BatchRun
¶
BatchRun(
parameter_space: dict[str, Any],
result_directory_name: str,
store_trajectories: bool = True,
max_workers: Optional[int] = None,
)
Bases: ABC
flowchart TD
nrgise.BatchRun[BatchRun]
click nrgise.BatchRun href "" "nrgise.BatchRun"
A BatchRun can be used in order to simulate multiple configurations of
an EnergySystem in a grid search manner.
The BatchRun handles paralellisation and storage of results for you.
To perform a batch run, implement this abstract base class and implement
the perform_single_simulation() method.
Results will be stored in the result_directory_name and contain:
- The simulation results (information of each time step) of each
simulation will be stored in
/trajectories. - Additionally, a summary of all simulations will be stored in the
batch_run_summary.csv.
Examples of how to use the BatchRun can be found in examples/batch_run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter_space
|
dict[str, Any]
|
Parameters which will be used to perform the simulations. |
required |
result_directory_name
|
str
|
Name of directory where the results will be dumped. |
required |
max_workers
|
Optional[int]
|
Number of parallel tasks to be executed. This should be
max the number of cores of your system. If the default value
|
None
|
Example
class CustomBatchRun(BatchRun):
def __init__(
self,
result_directory_name,
parameter_space,
):
super().__init__(parameter_space=parameter_space, result_directory_name=result_directory_name, max_workers=4)
def _create_energy_system(self, parameters: dict) -> EnergySystem:
...
return energy_system
def perform_single_simulation(self, parameters: dict) -> Tuple[pd.DataFrame, dict]: # SimulationResults, Summary
energy_system = self._create_energy_system(parameters)
controller = SelfConsumption()
simulation = Simulation(controller=controller, energy_system=energy_system)
single_run_trajectory = simulation.run()
economic_summary = nrgise.economics.get_economic_summary(...)
# include whatever is of interest in the summary, e.g. parameters and economic summary
summary = {
'parameters': parameters,
'economics': asdict(economic_summary) }
return single_run_trajectory, summary
if __name__ == '__main__':
parameter_space = {
'storage_capacity': [0, 10, 20, 40, 60],
'storage_efficiency': [0.8, 0.9],
}
batch_run = MyBatchRun(
result_directory_name='tmp',
parameter_space=parameter_space
)
batch_run.run()
# investigate results
results = pd.read_csv('tmp/batch_run_summary.csv', index_col=[0])
...
nrgise.BatchRun.perform_single_simulation
abstractmethod
¶
perform_single_simulation(
parameters: dict,
) -> Tuple[pd.DataFrame, dict[str, Any]]
Contains implementation of a single simulation run. This typically includes the construction and simulation
of an EnergySystem dependent on the parameters. Returns results of the simulation in two parts:
Returns:
| Type | Description |
|---|---|
DataFrame
|
Full simulation results of the single run as a pd.DataFrame. |
dict[str, Any]
|
Summary of the single run as dicts. The summary will be used to
create the |
nrgise.BatchRun.run
¶
run() -> None
Starts the batch run. This will execute perform_single_run() for all parameter combinations in the parameter_space.