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.

n_prediction_steps: int

Number of steps in the prediction (prediction_horizon/sampling_time).

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.

build_abstract_model() AbstractModel[source]

Public proxy for creating the model definition.

classmethod load_from_import(model_import: str, **kwargs: Any) PyomoModel[source]

Load a PyomoModel subclass from a dotted Python import string.

This is the single place where model classes are resolved from their import path, so both MpcAgent and create_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 PyomoModel subclass.

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 _model definition (without running subclass __init__), then writes:

  • {model_name}_state_config.toml — indexed pyo.Var components as actions and indexed pyo.Param components as observations.

  • {model_name}_model_parameters.toml — scalar pyo.Param components that belong in [agent_specific.model_parameters] of the run config.

Parameters:
  • model_import – Dotted import path to the PyomoModel subclass (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 (default 1.0), prediction_horizon (default sampling_time), and model_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 PyomoSimEnv must define a _start_value_mapping class 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 scalar pyo.Param, and the mapped Expression is an indexed pyo.Expression.

Parameters:

ext_outputs – External output names from the environment’s StateConfig.

Raises:
  • AttributeError – If _start_value_mapping is 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).