Model Module
- class corrai.base.model.Model(is_dynamic)[source]
Bases:
ABCAbstract base class for models in Corrai.
A Model defines the interface for simulation-based, analytical, or FMU-driven systems. It provides utilities to map high-level Parameter objects to model-specific properties and to run simulations given parameter-value pairs.
Subclasses must implement the
simulate()method.- Parameters:
is_dynamic (
bool) – Indicates if the model returns time dependant results as DataFrame with DatetimeIndex, or is static and returns a Series of values
- get_property_from_param(parameter_value_pairs)[source]
Convert (Parameter, value) pairs into a dictionary of model property assignments, handling relative and absolute values.
- simulate(property_dict, simulation_options, simulation_kwargs)[source]
Abstract method. Run the simulation and return a pandas DataFrame.
- simulate_parameter(parameter_value_pairs, simulation_options, simulation_kwargs)[source]
Helper that combines
get_property_from_param()andsimulate().
- get_property_values(property_list)[source]
Retrieve current values of given model properties. Must be implemented in subclasses if relative parameters are used.
- get_property_from_param(parameter_value_pairs)[source]
Map (Parameter, value) pairs to a dictionary of model properties.
Handles both absolute and relative parameter definitions. For relative parameters, the initial property value is used as a baseline.
- Parameters:
parameter_value_pairs (
list[tuple[Parameter,str|int|float]]) – List of tuples linking aParameterobject with the value assigned for this simulation.- Returns:
property_dict – Mapping from property names (str) to updated values.
- Return type:
dict[str,int|float|str]
- abstractmethod simulate(property_dict=None, simulation_options=None, **simulation_kwargs)[source]
Run a simulation for given properties and options.
Must be implemented in subclasses.
- Parameters:
property_dict (
dict[str,str|int|float]) – Mapping from model property names to values to override.simulation_options (
dict) – Options controlling the simulation (e.g., start/end times, timestep, solver parameters).simulation_kwargs (dict, optional) – Extra keyword arguments for the simulation routine.
- Returns:
Simulation results as a DataFrame with a DateTimeIndex and one or more output columns.
- Return type:
DataFrame|Series
- simulate_parameter(parameter_value_pairs, simulation_options=None, simulation_kwargs=None)[source]
Simulate the model given a set of parameter-value pairs.
This combines
get_property_from_param()andsimulate().- Parameters:
parameter_value_pairs (
list[tuple[Parameter,str|int|float]]) – The parameters and their assigned values for this run.simulation_options (
dict) – Options passed to the simulation routine.simulation_kwargs (
dict) – Additional arguments for the simulation routine.
- Returns:
Simulation results as a DataFrame with a DateTimeIndex and one or more output columns.
- Return type:
Union[DataFrame,Series]
- get_property_values(property_list)[source]
Retrieve current values of given properties from the model.
Must be implemented in subclasses if relative parameters are used.
- Parameters:
property_list (
list[str]) – Names of model properties.- Returns:
Current values of the requested properties.
- Return type:
list[str|int|float]- Raises:
NotImplementedError – If not overridden in a subclass.