# Path: qkeras/autoqkeras/forgiving_metrics/forgiving_factor.py
# class ForgivingFactor:
#   """Base class. Should never be invoked."""
# 
#   def __init__(self, delta_p, delta_n, rate):
#     self.delta_p = np.float32(delta_p) / 100.0
#     self.delta_n = np.float32(delta_n) / 100.0
#     self.rate = np.float32(rate)
# 
#   def get_reference(self, model):
#     """Computes reference size of model."""
# 
#     raise Exception("class not implemented.")
# 
#   def get_trial(self, model, schema):
#     """Computes size of quantization trial."""
# 
#     raise Exception("class not implemented.")
# 
#   def delta(self):
#     return np.where(
#         self.trial_size < self.reference_size,
#         self.delta_p * (np.log(self.reference_size/self.trial_size) /
#                         np.log(self.rate)),
#         self.delta_n * (np.log(self.reference_size/self.trial_size) /
#                         np.log(self.rate)))
# 
# Path: qkeras/qtools/run_qtools.py
# class QTools:
#   def __init__(self, model, process, source_quantizers=None,
#                is_inference=False, weights_path=None,
#                keras_quantizer=None, keras_accumulator=None,
#                for_reference=False,
#                model_weights_already_quantized=True,
#                hw_weight_dict=None):
#   def qtools_stats_to_json(self, json_name):
#   def qtools_stats_print(self):
#   def pe(self, weights_on_memory="dram",
#          activations_on_memory="dram",
#          min_sram_size=0,
#          rd_wr_on_io=True,
#          verbose=False):
#   def extract_energy_sum(self, cfg_setting, energy_dict):
#   def extract_energy_profile(self, cfg_setting, energy_dict):
# 
# Path: qkeras/qtools/settings.py
# class ConfigClass:
#   def __init__(self):
#   def update(self, process, cfg_setting):


import json
import numpy as np
from qkeras.autoqkeras.forgiving_metrics.forgiving_factor import ForgivingFactor   # pylint: disable=line-too-long
from qkeras.qtools import run_qtools
from qkeras.qtools import settings as qtools_settings
    assert self.activations_on_memory[0] in ["dram", "sram", "fixed"]
    assert self.activations_on_memory[1] in ["dram", "sram", "fixed"]
    assert self.reference_internal in ["fp16", "fp32", "int8"]
    assert self.reference_accumulator in ["int16", "int32", "fp16", "fp32"]

  def get_reference(self, model):
    # we only want to compute reference once
    if self.reference_size is not None:
      return self.reference_size * self.stress

    q = run_qtools.QTools(
        model, process=self.process,
        source_quantizers=self.reference_internal,
        is_inference=self.trained_model,
        weights_path=None,
        keras_quantizer=self.reference_internal,
        keras_accumulator=self.reference_accumulator,
        for_reference=True)

    energy_dict = q.pe(
        weights_on_memory=self.parameters_on_memory[0],
        activations_on_memory=self.activations_on_memory[0],
        min_sram_size=self.min_sram_size[0],
        rd_wr_on_io=self.rd_wr_on_io[0])

    self.ref_energy_dict = energy_dict
    self.reference_size = q.extract_energy_sum(
        qtools_settings.cfg.include_energy, energy_dict)

    self.reference_energy_profile = q.extract_energy_profile(

# Path: qkeras/autoqkeras/forgiving_metrics/forgiving_factor.py
# class ForgivingFactor:
#   """Base class. Should never be invoked."""
# 
#   def __init__(self, delta_p, delta_n, rate):
#     self.delta_p = np.float32(delta_p) / 100.0
#     self.delta_n = np.float32(delta_n) / 100.0
#     self.rate = np.float32(rate)
# 
#   def get_reference(self, model):
#     """Computes reference size of model."""
# 
#     raise Exception("class not implemented.")
# 
#   def get_trial(self, model, schema):
#     """Computes size of quantization trial."""
# 
#     raise Exception("class not implemented.")
# 
#   def delta(self):
#     return np.where(
#         self.trial_size < self.reference_size,
#         self.delta_p * (np.log(self.reference_size/self.trial_size) /
#                         np.log(self.rate)),
#         self.delta_n * (np.log(self.reference_size/self.trial_size) /
#                         np.log(self.rate)))
# 
# Path: qkeras/qtools/run_qtools.py
# class QTools:
#   def __init__(self, model, process, source_quantizers=None,
#                is_inference=False, weights_path=None,
#                keras_quantizer=None, keras_accumulator=None,
#                for_reference=False,
#                model_weights_already_quantized=True,
#                hw_weight_dict=None):
#   def qtools_stats_to_json(self, json_name):
#   def qtools_stats_print(self):
#   def pe(self, weights_on_memory="dram",
#          activations_on_memory="dram",
#          min_sram_size=0,
#          rd_wr_on_io=True,
#          verbose=False):
#   def extract_energy_sum(self, cfg_setting, energy_dict):
#   def extract_energy_profile(self, cfg_setting, energy_dict):
# 
# Path: qkeras/qtools/settings.py
# class ConfigClass:
#   def __init__(self):
#   def update(self, process, cfg_setting):


# Path: qkeras/autoqkeras/forgiving_metrics/forgiving_energy.py
import json
import numpy as np
from qkeras.autoqkeras.forgiving_metrics.forgiving_factor import ForgivingFactor   # pylint: disable=line-too-long
from qkeras.qtools import run_qtools
from qkeras.qtools import settings as qtools_settings

    assert self.activations_on_memory[0] in ["dram", "sram", "fixed"]
    assert self.activations_on_memory[1] in ["dram", "sram", "fixed"]
    assert self.reference_internal in ["fp16", "fp32", "int8"]
    assert self.reference_accumulator in ["int16", "int32", "fp16", "fp32"]

  def get_reference(self, model):
    # we only want to compute reference once
    if self.reference_size is not None:
      return self.reference_size * self.stress

    q = run_qtools.QTools(
        model, process=self.process,
        source_quantizers=self.reference_internal,
        is_inference=self.trained_model,
        weights_path=None,
        keras_quantizer=self.reference_internal,
        keras_accumulator=self.reference_accumulator,
        for_reference=True)

    energy_dict = q.pe(
        weights_on_memory=self.parameters_on_memory[0],
        activations_on_memory=self.activations_on_memory[0],
        min_sram_size=self.min_sram_size[0],
        rd_wr_on_io=self.rd_wr_on_io[0])

    self.ref_energy_dict = energy_dict
    self.reference_size = q.extract_energy_sum(
        qtools_settings.cfg.include_energy, energy_dict)

    self.reference_energy_profile = q.extract_energy_profile(

        qtools_settings.cfg.include_energy, energy_dict)