h2integrate.core.model_baseclasses#
Classes
|
Baseclass with methods to cache results and load data from cached results. |
|
|
|
Baseclass to be used for all cost models. |
|
|
|
|
|
Baseclass to be used for all resizeable performance models. |
|
- class h2integrate.core.model_baseclasses.PerformanceModelBaseClass(**kwargs)#
- initialize()#
Perform any one-time initialization run at instantiation.
- setup()#
Declare inputs and outputs.
- Available attributes:
name pathname comm options
- compute(inputs, outputs, discrete_inputs, discrete_outputs)#
Computation for the OM component.
For a template class this is not implement and raises an error.
- class h2integrate.core.model_baseclasses.CostModelBaseConfig(*, cost_year)#
- Parameters:
cost_year (int)
- cost_year: int#
- class h2integrate.core.model_baseclasses.CostModelBaseClass(**kwargs)#
Baseclass to be used for all cost models. The built-in outputs are used by the finance model and must be outputted by all cost models.
Subclasses should use CostModelBaseConfig for their configuration class.
- Outputs:
CapEx (float): capital expenditure costs in $
OpEx (float): annual fixed operating expenditure costs in $/year
VarOpEx (float): annual variable operating expenditure costs in $/year
- Discrete Outputs:
- cost_year (int): dollar-year corresponding to CapEx and OpEx values.
This may be inherent to the cost model, or may depend on user provided input values.
- initialize()#
Perform any one-time initialization run at instantiation.
- setup()#
Declare inputs and outputs.
- Available attributes:
name pathname comm options
- compute(inputs, outputs, discrete_inputs, discrete_outputs)#
Computation for the OM component.
For a template class this is not implement and raises an error.
- class h2integrate.core.model_baseclasses.ResizeablePerformanceModelBaseConfig(*, size_mode='normal', flow_used_for_sizing=None, max_feedstock_ratio=1.0, max_commodity_ratio=1.0)#
- Parameters:
size_mode (str)
flow_used_for_sizing (str | None)
max_feedstock_ratio (float)
max_commodity_ratio (float)
- size_mode: str#
- flow_used_for_sizing: str | None#
- max_feedstock_ratio: float#
- max_commodity_ratio: float#
- class h2integrate.core.model_baseclasses.ResizeablePerformanceModelBaseClass(**kwargs)#
Baseclass to be used for all resizeable performance models. The built-in inputs are used by the performance models to resize themselves.
These parameters are all set as attributes within the config class, which inherits from ResizeablePerformanceModelBaseConfig
- Discrete Inputs:
- size_mode (str): The mode in which the component is sized. Options:
“normal”: The component size is taken from the tech_config.
- “resize_by_max_feedstock”: The component size is calculated relative to the
maximum available amount of a certain feedstock or feedstocks
- “resize_by_max_commodity”: The electrolyzer size is calculated relative to the
maximum amount of the commodity used by another tech
- flow_used_for_sizing (str): The feedstock/commodity flow used to determine the plant size
in “resize_by_max_feedstock” and “resize_by_max_commodity” modes
- Inputs:
- max_feedstock_ratio (float): The ratio of the max feedstock that can be consumed by
this component to the max feedstock available.
- max_commodity_ratio (float): The ratio of the max commodity that can be produced by
this component to the max commodity consumed by the downstream tech.
- setup()#
Declare inputs and outputs.
- Available attributes:
name pathname comm options
- compute(inputs, outputs, discrete_inputs, discrete_outputs)#
Computation for the OM component.
For a template class this is not implement and raises an error.
- class h2integrate.core.model_baseclasses.CacheBaseConfig(*, enable_caching, cache_dir)#
- Parameters:
enable_caching (bool)
cache_dir (str | Path)
- enable_caching: bool#
- cache_dir: str | Path#
- class h2integrate.core.model_baseclasses.CacheBaseClass(**kwargs)#
Baseclass with methods to cache results and load data from cached results.
Subclasses should have a corresponding config class that inherits CacheBaseConfig.
- set_outputs_from_cache_dict(cached_dict, outputs, discrete_outputs={})#
Set outputs and discrete_outputs using previously cached data available in cached_dict.
- Parameters:
cached_dict (dict) – dictionary with top-level keys of “outputs” and “discrete_outputs”. Top-level values are dictionaries with keys corresponding to output of discrete output names and values of the resulting output value.
outputs (om.vectors.default_vector.DefaultVector) – OM outputs of compute() method. The output values are set the outputs have been previously cached.
discrete_outputs (om.core.component._DictValues, optional) – OM discrete outputs of compute() method. Defaults to {}.
- create_cache_dict_from_outputs(outputs, discrete_outputs={})#
Create a dictionary of outputs and discrete outputs. The outputs and discrete_outputs should be set in the compute() prior to this function being called.
- Parameters:
outputs (om.vectors.default_vector.DefaultVector) – OM outputs of compute() method that have already been set with the resulting values.
discrete_outputs (om.core.component._DictValues, optional) – OM discrete outputs of compute() method that have been set with resulting values. Defaults to {}.
- Returns:
dict –
- dictionary with top-level keys of “outputs” and “discrete_outputs”.
Top-level values are dictionaries with keys corresponding to output of discrete output names and values of the resulting output value.
- load_outputs(inputs, outputs, discrete_inputs={}, discrete_outputs={}, config_dict={})#
Load previously cached computation results if they exist.
This method generates a unique cache filename based on the current inputs and configuration, then checks if cached results exist for this exact combination. If cached results are found, the output and discrete_output values are populated from the cache file and the method returns True to indicate the computation can be skipped. If no cache file exists or caching is disabled, the method returns False to indicate the computation must be performed.
- Parameters:
inputs (om.vectors.default_vector.DefaultVector) – OM inputs to compute() method.
outputs (om.vectors.default_vector.DefaultVector) – OM outputs of compute() method. The output values are set the results that have been previously cached.
discrete_inputs (om.core.component._DictValues, optional) – OM discrete inputs to compute() method. Defaults to {}.
discrete_outputs (om.core.component._DictValues, optional) – OM discrete outputs of compute() method. The discrete_output values are set to the discrete_outputs have been previously cached. Defaults to {}.
config_dict (dict, optional) – dictionary created/updated from config class. Defaults to {}. If config_dict is input as an empty dictionary, config_dict is created from self.config.as_dict()
- Returns:
bool –
- True if outputs were set to cached results. False if cache file
doesn’t exist and the model still needs to calculate and set the outputs.
- cache_outputs(inputs, outputs, discrete_inputs={}, discrete_outputs={}, config_dict={})#
Save computation results to cache for future reuse.
This method generates a unique cache filename based on the current inputs and configuration, then serializes the output and discrete_output values to a pickle file. This allows future computations with identical inputs and configuration to skip the calculation by loading from cache instead. The outputs and discrete_outputs must already be set with their computed values before before calling this method. If caching is disabled, this method returns immediately without saving anything.
- Parameters:
inputs (om.vectors.default_vector.DefaultVector) – OM inputs to compute() method
outputs (om.vectors.default_vector.DefaultVector) – OM outputs of compute() method that have already been set with the resulting values
discrete_inputs (om.core.component._DictValues, optional) – OM discrete inputs to compute() method. Defaults to {}.
discrete_outputs (om.core.component._DictValues, optional) – OM discrete_outputs of compute() method that have already been set with the resulting values. Defaults to {}.
config_dict (dict, optional) – dictionary created/updated from config class. Defaults to {}. If config_dict is input as an empty dictionary, config_dict is created from self.config.as_dict()
- make_cache_hash_filename(config, inputs, discrete_inputs={})#
Make valid filepath to a pickle file with a filename that is unique based on information available in the config, inputs, and discrete inputs.
- Parameters:
config (object | dict) – configuration object that inherits BaseConfig or dictionary.
inputs (om.vectors.default_vector.DefaultVector) – OM inputs to compute() method
discrete_inputs (om.core.component._DictValues, optional) – OM discrete inputs to compute() method. Defaults to {}.
- Returns:
Path – filepath to pickle file with filename as unique cache key.
- compute(inputs, outputs, discrete_inputs, discrete_outputs)#
Computation for the OM component. This template includes commented out code on how to use the functionality of this base class within a subclass.
Please ensure this method is implemented in a subclass.