eta_ctrl.simulators.pyomo_model module
- class eta_ctrl.simulators.pyomo_model.PyomoModel(*, sampling_time: float, model_parameters: dict[str, Any] | None = None, prediction_horizon: TimeStep | str | None = None, **kwargs: Any)[source]
Bases:
object- sampling_time
Sampling time (interval between optimization time steps) in seconds.
- model_parameters
Configuration for the MILP model parameters.
- model: ConcreteModel
Concrete pyomo model as initialized by _model.
- pyo_update_params(updated_params: Mapping[str, int | float | bool | Mapping | np.ndarray | Sequence | Any]) None[source]
Update model parameters and indexed parameters of a pyomo instance with values given in a dictionary.
- Parameters:
updated_params – Dictionary with the updated values.
- Returns:
Updated model instance.
- pyo_init_params() PyoParams[source]
Public proxy for initial parameter mapping used by utility workflows.
- classmethod load_from_import(model_import: str, **kwargs: Any) PyomoModel[source]
Load a
PyomoModelsubclass from a dotted Python import string.This is the single place where model classes are resolved from their import path, so both
MpcAgentandcreate_state()can reuse it without duplicating the logic.- Parameters:
model_import – Dotted import path to the subclass (e.g.
"eta_ctrl.examples.kea_tank.kea_pyomo_model.DrKeaModel").kwargs – Keyword arguments forwarded to the subclass constructor (e.g.
sampling_time,prediction_horizon,model_parameters).
- Returns:
Instantiated
PyomoModelsubclass.
- classmethod create_state(model_import: str, model_name: str, output_dir: pathlib.Path | str | None = None, **kwargs: Any) None[source]
Generate state config and model parameters TOML files for a PyomoModel.
Creates a concrete model from the subclass
_modeldefinition (without running subclass__init__), then writes:{model_name}_state_config.toml— indexedpyo.Varcomponents as actions and indexedpyo.Paramcomponents as observations.{model_name}_model_parameters.toml— scalarpyo.Paramcomponents that belong in[agent_specific.model_parameters]of the run config.
- Parameters:
model_import – Dotted import path to the
PyomoModelsubclass (e.g."eta_ctrl.examples.kea_tank.kea_pyomo_model.DrKeaModel").model_name – Name used as prefix for the output files.
output_dir – Target directory for the output files. Defaults to the current working directory.
kwargs – Optional export-time kwargs:
sampling_time(default1.0),prediction_horizon(defaultsampling_time), andmodel_parameters.
- pyo_get_solution(names: set[str] | None = None) tuple[dict[str, list[float]], dict[str, float]][source]
Convert the pyomo solution into a more usable format for plotting.
- Parameters:
names – Names of the model parameters that are returned.
- Returns:
Dictionary of {parameter name: value} pairs. Value may be a scalar value or a list.
- property start_value_mapping: dict[str, str]
Mapping of initial-condition Param names to their corresponding Expression names.
Subclasses that should be compatible with
PyomoSimEnvmust define a_start_value_mappingclass attribute (e.g._start_value_mapping = {"temp0": "temp_expression"}).- Raises:
AttributeError – If the subclass does not define
_start_value_mapping.
- check_pyomo_sim_compatibility(ext_outputs: list[str]) None[source]
Validate that this model is compatible with
PyomoSimEnv.Checks that every external output (defined in the state config) has a corresponding entry in
start_value_mapping, that the mapped Param is a scalarpyo.Param, and the mapped Expression is an indexedpyo.Expression.- Parameters:
ext_outputs – External output names from the environment’s StateConfig.
- Raises:
AttributeError – If
_start_value_mappingis not defined.KeyError – If an external output is missing from the expression mapping.
ValueError – If a mapped component does not exist in the concrete model.
TypeError – If a component has the wrong Pyomo type (e.g. Var instead of Param).