eta_ctrl.common.export_pyomo module
Pyomo model export utilities.
This module provides functions for exporting Pyomo model components to TOML files.
- eta_ctrl.common.export_pyomo.extract_indexed_variable_info(component: pyo.Var) dict[str, Any][source]
Extract comprehensive information from indexed Pyomo variables.
This function analyzes indexed Pyomo variables to extract domain information, bounds, and index set details. It handles edge cases where variables may not have complete information by providing reasonable defaults.
- Parameters:
component – Indexed Pyomo variable component to analyze.
- Returns:
Dictionary containing variable type, bounds, and index information.
- eta_ctrl.common.export_pyomo.extract_scalar_variable_info(component: pyo.Var) dict[str, Any][source]
Extract comprehensive information from scalar Pyomo variables.
This function analyzes scalar Pyomo variables to extract domain information and bounds. It provides fallback defaults for variables without explicit domain or bounds specifications.
- Parameters:
component – Scalar Pyomo variable component to analyze.
- Returns:
Dictionary containing variable type and bounds information.
- eta_ctrl.common.export_pyomo.export_pyomo_state_config(model: ConcreteModel, model_name: str, output_path: Path) None[source]
Export Pyomo model variables (observations) to a TOML file.
This method extracts the variables from the Pyomo model and exports them to a TOML file for later use in state configuration.
ATTENTION: All variables are treated as observations, you need to separate these.
- Parameters:
model – Pyomo ConcreteModel instance.
model_name – Name of the model for identification.
output_path – Full path where the TOML file should be saved (including filename).
- eta_ctrl.common.export_pyomo.export_pyomo_parameters(model: ConcreteModel, model_name: str, output_path: Path) None[source]
Export Pyomo model parameters to a TOML file.
This method extracts parameter names and values from the Pyomo model and exports them to a TOML file. For indexed parameters, all values are collected as arrays to preserve the complete parameter information.
- Parameters:
model – Pyomo ConcreteModel instance.
model_name – Name of the model for identification.
output_path – Full path where the TOML file should be saved (including filename).
- eta_ctrl.common.export_pyomo.export_pyomo_state(model: ConcreteModel, model_name: str, output_dir: Path | str | None = None) None[source]
Export Pyomo model state config and parameters files.
This is the main public interface for exporting Pyomo model data, creating both state configuration and parameters files.
- Parameters:
model – Pyomo ConcreteModel instance.
model_name – Name of the model for identification.
output_dir – Directory where files should be created. If None, uses current working directory.
- eta_ctrl.common.export_pyomo.export_pyomo_model_state_config(model: ConcreteModel, model_name: str, output_path: Path) None[source]
Export a PyomoModel’s components to a state config TOML file.
Classification rules:
Indexed
pyo.Varcomponents →[[actions]]Indexed
pyo.Paramcomponents →[[observations]]
Scalar parameters are intentionally omitted here; use
export_pyomo_model_parameters()for those.- Parameters:
model – Pyomo ConcreteModel instance.
model_name – Name of the model for identification.
output_path – Full path (including filename) for the TOML file.
- eta_ctrl.common.export_pyomo.export_pyomo_model_parameters(model: ConcreteModel, model_name: str, output_path: Path) None[source]
Export scalar (non-indexed) Pyomo parameters to a model parameters TOML file.
The output corresponds to the
[agent_specific.model_parameters]section of a run config.- Parameters:
model – Pyomo ConcreteModel instance.
model_name – Name of the model for identification.
output_path – Full path (including filename) for the TOML file.
- eta_ctrl.common.export_pyomo.export_pyomo_model_state(model: ConcreteModel, model_name: str, output_dir: Path | str | None = None) None[source]
Export a PyomoModel’s state config and model parameters to TOML files.
This is the main public interface for
PyomoModelstate generation. It writes two files:{model_name}_state_config.toml— indexed Vars as actions, indexed Params as observations.{model_name}_model_parameters.toml— scalar Params that belong in[agent_specific.model_parameters]of the run config.
- Parameters:
model – Pyomo ConcreteModel instance.
model_name – Name of the model used for file naming.
output_dir – Target directory. Defaults to the current working directory.