Attention
This project is still in an early phase of development.
The python API is not yet stable, and some aspects of the schema for the blueprint and workplan will likely evolve. Therefore whilst you are welcome to try out using the package, we cannot yet guarantee backwards compatibility. We expect to reach a more stable version in 2026.
Simulation#
- class cstar.simulation.Simulation(name: str, directory: str | Path, discretization: Discretization, runtime_code: AdditionalCode | None = None, compile_time_code: AdditionalCode | None = None, codebase: ExternalCodeBase | None = None, start_date: str | datetime | None = None, end_date: str | datetime | None = None, valid_start_date: str | datetime | None = None, valid_end_date: str | datetime | None = None)#
Bases:
ABC,LoggingMixinAn abstract base class representing a C-Star simulation.
- name#
The name of this simulation.
- Type:
str
- directory#
The local directory in which this simulation will be prepared and executed.
- Type:
Path
- start_date#
The starting date of the simulation.
- Type:
str or datetime
- end_date#
The ending date of the simulation.
- Type:
str or datetime
- valid_start_date#
The earliest allowed start date, based on, e.g. the availability of input data.
- Type:
str or datetime
- valid_end_date#
The latest allowed end date, based on, e.g., the availability of input data.
- Type:
str or datetime
- codebase#
The repository containing the base source code for this simulation.
- Type:
- runtime_code#
Runtime configuration files.
- Type:
- compile_time_code#
Additional source code modifications and compile-time configuration files.
- Type:
- discretization#
Numerical discretization parameters for this simulation.
- Type:
- from_dict(simulation_dict, directory)#
Construct a Simulation instance from a dictionary.
- to_dict()#
Convert this Simulation instance into a dictionary.
- from_blueprint(blueprint, directory)#
Initialize a Simulation from a YAML blueprint.
- to_blueprint(filename)#
Save this simulation’s configuration as a YAML blueprint.
- setup()#
Prepare all necessary files and configurations for the simulation locally.
- build(rebuild=False)#
Compile any necessary additional code associated with this simulation.
- pre_run()#
Execute any pre-processing actions required before running the simulation.
- run()#
Execute the simulation.
- post_run()#
Execute any post-processing actions required after running the simulation.
- persist()#
Save the state of this Simulation instance to disk.
- restore(directory)#
Restore a previously saved Simulation instance from disk.
- restart(new_end_date)#
Create a new Simulation instance starting from the end of this one.
Methods
Simulation.build([rebuild])Abstract method to compile any necessary code for this simulation.
Simulation.from_blueprint(blueprint)Abstract method to create a Simulation instance from a blueprint file.
Simulation.from_dict(simulation_dict, directory)Abstract method to create a Simulation instance from a dictionary.
Save the current state of the simulation to a file.
Abstract method to perform post-processing actions after the simulation run.
Abstract method to perform any necessary pre-processing steps before running the simulation.
Simulation.restart(new_end_date)Create a new Simulation instance starting from the end date of the current simulation.
Simulation.restore(directory)Restore a previously saved simulation state.
Abstract method to begin execution of the simulation.
Abstract method to set up the Simulation.
Simulation.state_file_from(directory)The path where a state file containing a pickled Simulation will be created upon successful completion of a simulation, when that simulation uses the supplied directory as it's working directory.
Convert the Simulation instance into a dictionary representation.
Attributes
Simulation.default_codebaseAbstract property that must be implemented by subclasses to provide a default codebase.
Simulation.logReturn the logger instance for this class.
Simulation.state_fileThe path where a state file containing the pickled Simulation will be created upon successful completion of the simulation.