rtm_wrapper.execution#
Simulation sweep execution.
Executor objects are responsible for repeatedly running simulations with a specific RTM engine according to a sweep specification.
Module Contents#
Classes#
Base class for simulation executors. |
|
Base class for executors that store the entire simulation results in a local, |
|
Executor that runs simulations in series. |
|
Executor the launches simulations in concurrent worker threads. |
|
Executor that runs multiple |
- class SweepExecutor[source]#
Bases:
abc.ABCBase class for simulation executors.
- abstract run(sweep: rtm_wrapper.simulation.SweepSimulation, engine: rtm_wrapper.engines.base.RTMEngine, **kwargs: Any) None[source]#
Execute a sweep simulation using the given engine.
- Parameters:
sweep (rtm_wrapper.simulation.SweepSimulation) –
engine (rtm_wrapper.engines.base.RTMEngine) –
kwargs (Any) –
- Return type:
None
- class LocalMemoryExecutor[source]#
Bases:
SweepExecutor,abc.ABCBase class for executors that store the entire simulation results in a local, in-memory
xarray.Dataset.- steps_for(sweep: rtm_wrapper.simulation.SweepSimulation) int[source]#
Return a forecast for the number of times
step_callbackwill be called if the given simulation is pass torun.- Parameters:
sweep (rtm_wrapper.simulation.SweepSimulation) –
- Return type:
int
- run(sweep: rtm_wrapper.simulation.SweepSimulation, engine: rtm_wrapper.engines.base.RTMEngine, *, step_callback: Callable[Ellipsis, None] | None = None, **kwargs: Any) None[source]#
Execute a sweep simulation using the given engine.
- Parameters:
sweep (rtm_wrapper.simulation.SweepSimulation) –
engine (rtm_wrapper.engines.base.RTMEngine) –
step_callback (Callable[Ellipsis, None] | None) –
kwargs (Any) –
- Return type:
None
- class SerialExecutor[source]#
Bases:
LocalMemoryExecutorExecutor that runs simulations in series.
- class ConcurrentExecutor(max_workers: int | None = None)[source]#
Bases:
LocalMemoryExecutorExecutor the launches simulations in concurrent worker threads.
This executor is designed to take advantage of engines that release the GIL while running.
Warning
This executor assumes that the provided engine’s
run_simulationmethod is thread-safe. All worker threads operate on the same engine instance. Make sure that the provided engine does not mutate itself or any global state without appropriate locking.- Parameters:
max_workers (int | None) –
- class ParallelConcurrentExecutor(split_dim: str | None = None, split_sections: int | collections.abc.Sequence[int] | None = None, max_managers: int | None = None, max_workers: int | None = None)[source]#
Bases:
LocalMemoryExecutorExecutor that runs multiple
ConcurrentExecutors in spawned subprocesses.This can improve performance over
ConcurrentExecutorwhen simulation sweeps are Python bounded, which can happen when individual simulator runs are fast or when many simulation works are used.- Parameters:
split_dim (str | None) –
split_sections (int | collections.abc.Sequence[int] | None) –
max_managers (int | None) –
max_workers (int | None) –
- steps_for(sweep: rtm_wrapper.simulation.SweepSimulation) int[source]#
Return a forecast for the number of times
step_callbackwill be called if the given simulation is pass torun.- Parameters:
sweep (rtm_wrapper.simulation.SweepSimulation) –
- Return type:
int