hwcomponents package
Subpackages
Submodules
hwcomponents.find_models module
- hwcomponents.find_models.get_models(*paths_or_packages_or_models, include_installed=True, name_must_include='', _return_wrappers=False)[source]
Instantiate a list of model objects for later queries. Searches for models in the given paths and packages.
- Parameters:
paths_or_packages_or_models (list) – A list of paths or packages to search for models.
include_installed (bool) – Whether to include models from installed packages.
name_must_include (str) – If provided, a model will only be returned if its name includes this string. Non-case-sensitive.
_return_wrappers (bool) – Whether to return EnergyAreaModelWrapper objects or EnergyAreaModel objects.
- Return type:
Union[List[EnergyAreaModelWrapper],List[EnergyAreaModel]]- Returns:
A list of EnergyAreaModelWrapper objects or EnergyAreaModel objects.
- hwcomponents.find_models.get_models_in_module(module, model_ids, _return_wrappers=False)[source]
Finds all EnergyAreaModel subclasses in a module and returns them as EnergyAreaModelWrapper objects. Ignores underscore-prefixed classes.
- Parameters:
model_ids (set) – A set of model IDs to avoid duplicates.
_return_wrappers (bool) – Whether to return EnergyAreaModelWrapper objects or EnergyAreaModel objects.
- Return type:
Union[List[EnergyAreaModelWrapper],List[EnergyAreaModel]]- Returns:
A list of EnergyAreaModelWrapper objects.
- hwcomponents.find_models.installed_models(_return_wrappers=False)[source]
Lists all Python packages installed that are prefixed with “hwcomponents_”. Finds EnergyAreaModel subclasses in these packages and returns them as EnergyAreaModel or EnergyAreaModelWrapper objects.
- Parameters:
_return_wrappers (bool) – Whether to return EnergyAreaModelWrapper objects or EnergyAreaModel objects.
- Return type:
Union[List[EnergyAreaModelWrapper],List[EnergyAreaModel]]- Returns:
A list of EnergyAreaModel or EnergyAreaModelWrapper objects.
hwcomponents.hwcomponents module
hwcomponents.model module
- class hwcomponents.model.EnergyAreaModel[source]
Bases:
ListLoggable,ABCEnergyAreaModel base class. EnergyAreaModel class must have “name” attribute, “priority” attribute, and “get_area” method. EnergyAreaModels may have any number of methods that are decorated with @actionDynamicEnergy.
- Parameters:
component_name (str | list[str] | None) – The name of the component. Must be a string or list/tuple of strings. Can be omitted if the component name is the same as the class name.
priority (float) – The priority of the model. Higher priority models are used first. Must be a number between 0 and 1.
leak_power (float | None) – The leakage power of the component in Watts. Must be set if subcomponents is not set.
area (float | None) – The area of the component in m^2. Must be set if subcomponents is not set.
energy_scale (float) – A scale factor for the energy. All calls to @actionDynamicEnergy will be scaled by this factor.
area_scale (float) – A scale factor for the area. All calls to area will be scaled by this factor.
leak_scale (float) – A scale factor for the leakage power. All calls to leak_power will be scaled by this factor.
subcomponents (list[EnergyAreaModel] | None) – A list of subcomponents. If set, the area and leak power of the subcomponents will be added to the area and leak power of the component. All calls to @actionDynamicEnergy functions will be added to the energy of the component if they occur during one of the component’s actions. The area, energy, and leak power of subcomponents WILL NOT BE scaled by the component’s energy_scale, area_scale, or leak_scale; if you want to scale the subcomponents, multiply their energy_scale, area_scale, or leak_scale by the desired scale factor.
- Variables:
component_name (The name of the component. Must be a string or list/tuple of) – strings. Can be omitted if the component name is the same as the class name.
priority (The priority of the model. Higher priority models are used first.) – Must be a number between 0 and 1.
energy_scale (A scale factor for the energy. All calls to actionDynamicEnergy) – will be scaled by this factor.
area_scale (A scale factor for the area. All calls to area) – will be scaled by this factor.
leak_scale (A scale factor for the leakage power. All calls to leak_power) – will be scaled by this factor.
subcomponents (A list of subcomponents. If set, the area and leak power of the) – subcomponents will be added to the area and leak power of the component. All calls to @actionDynamicEnergy functions will be added to the energy of the component if they occur during one of the component’s actions, and will be scaled by the component’s energy_scale.
- property area: Number
Returns the area in m^2 of the component.
- Return type:
The area in m^2 of the component.
-
component_name:
Union[str,List[str],None] = None Name of the component. Must be a string or list/tuple of strings. Can be omitted if the component name is the same as the class name.
- get_action_names()[source]
Returns the names of the actions supported by the model.
- Returns:
The names of the actions supported by the model.
- Return type:
List[str]
- leak(time_period)[source]
Returns the leakage energy for a given time period.
- Parameters:
time_period (float) – The time period in seconds.
- Return type:
float- Returns:
The leakage energy in Joules.
- property leak_power: Number
Returns the leakage power of the component in Watts.
- Return type:
The leakage power in Watts.
-
priority:
Number= None Priority determines which model is used when multiple models are available for a given component. Higher priority models are used first. Must be a number between 0 and 1.
- required_arguments(action_name=None)[source]
Returns the required arguments for the given action. If no action is given, returns the required arguments for the __init__ method.
- Parameters:
action_name (str | None) – The name of the action to get the required arguments for. If None, returns the required arguments for the __init__ method.
- Return type:
List[str]- Returns:
- list[str]
The required arguments for the given action.
- scale(key, target, default, energy_scale_function, area_scale_function, leak_scale_function)[source]
- Return type:
float
- try_call_arbitrary_action(action_name, **kwargs)[source]
Tries to call the given action with the given arguments.
- Parameters:
action_name (str) – The name of the action to call.
**kwargs (dict) – The arguments with which to call the action.
- Return type:
TypeVar(T, bound= EnergyAreaModel)
- classmethod try_init_arbitrary_args(**kwargs)[source]
Tries to initialize the model with the given arguments.
- Parameters:
**kwargs (dict) – The arguments with which to initialize the model.
- Return type:
TypeVar(T, bound= EnergyAreaModel)- Returns:
The initialized model. If the model cannot be initialized with the given arguments, an exception is raised.
- hwcomponents.model.actionDynamicEnergy(func=None, bits_per_action=None)[source]
Decorator that adds an action to an energy/area model. If the component has no subcomponents, then the action is expected to return an energy value in Joules. If the component has subcomponents, then None return values are assumed to be 0, and subcomponent actions that occur during the component’s action will be added to the component’s energy. The energy of the subcomponents will NOT be scaled by the component’s energy_scale.
- Parameters:
func (Callable[[], float] | None) – The function to decorate.
bits_per_action (str) – The attribute of the model that contains the number of bits per action. If this is set and a bits_per_action is passed to the function, the energy will be scaled by the number of bits. For example, if bits_per_action is set to “width”, the function is called with bits_per_action=10, and the model has a width attribute of 5, then the energy will be scaled by 2.
- Return type:
Callable[[],float]- Returns:
The decorated function.
hwcomponents.select_models module
- hwcomponents.select_models.get_area(component_name, component_attributes, models=None, return_estimation_object=False, _relaxed_component_name_selection=False)[source]
Finds the area using the best-matching model. “Best” is defined as the highest-priority model that has all required attributes specified in component_attributes.
- Parameters:
component_name (The name of the component.)
component_attributes (The attributes of the component.)
models (The models to use.)
return_estimation_object (Whether to return the estimation object instead of) – the area value.
_relaxed_component_name_selection (Whether to relax the component name) – selection. Relaxed selection ignores underscores in the component name.
- Return type:
float|Estimation- Returns:
The area in m^2.
- hwcomponents.select_models.get_energy(component_name, component_attributes, action_name, action_arguments, models=None, return_estimation_object=False, _relaxed_component_name_selection=False)[source]
Finds the energy using the best-matching model. “Best” is defined as the highest-priority model that has all required attributes specified in component_attributes and a matching action with all required arguments specified in action_arguments.
- Parameters:
component_name (The name of the component.)
component_attributes (The attributes of the component.)
action_name (The name of the action.)
action_arguments (The arguments of the action.)
models (The models to use.)
return_estimation_object (Whether to return the estimation object instead of) – the energy value.
_relaxed_component_name_selection (Whether to relax the component name) – selection. Relaxed selection ignores underscores in the component name.
- Return type:
float|Estimation- Returns:
The energy in Joules.
- hwcomponents.select_models.get_leak_power(component_name, component_attributes, models=None, return_estimation_object=False, _relaxed_component_name_selection=False)[source]
Finds the leak power using the best-matching model. “Best” is defined as the highest-priority model that has all required attributes specified in component_attributes.
- Parameters:
component_name (The name of the component.)
component_attributes (The attributes of the component.)
models (The models to use.)
_relaxed_component_name_selection (Whether to relax the component name) – selection. Relaxed selection ignores underscores in the component name.
- Return type:
float|Estimation- Returns:
The leak power in Watts.
- hwcomponents.select_models.get_model(component_name, component_attributes, required_actions=(), models=None, return_estimation_object=False, _relaxed_component_name_selection=False)[source]
Finds the best model for the given component. “Best” is defined as the highest-priority model that has all required attributes specified in component_attributes, and has actions for all of required_actions.
- Parameters:
component_name (The name of the component.)
component_attributes (The attributes of the component.)
required_actions (The actions that are required for the component.)
models (The models to use.)
return_estimation_object (Whether to return the estimation object instead of) – the model wrapper.
_relaxed_component_name_selection (Whether to relax the component name) – selection. Relaxed selection ignores underscores in the component name.
- Return type:
EnergyAreaModelWrapper- Returns:
The best model wrapper.