Class used to perform multiple simulation runs with randomly sampled parameters.
More...
|
| Time | get_dt () const |
| | Return the initial step sized used by simulations. More...
|
| |
| size_t | get_num_runs () const |
| | Return the number of total runs that the study will make. More...
|
| |
| RandomNumberGenerator & | get_rng () |
| | Access the study's random number generator. More...
|
| |
| Time | get_t0 () const |
| | Return the initial time point for simulations. More...
|
| |
| Time | get_tmax () const |
| | Return the final time point for simulations. More...
|
| |
| | ParameterStudy (const Parameters ¶meters, Time t0, Time tmax, Step dt, size_t num_runs) |
| | Create a parameter study with some parameters. More...
|
| |
| template<class CreateSimulationFunction , class ProcessSimulationResultFunction > |
| EnsembleResultT< CreateSimulationFunction, ProcessSimulationResultFunction > | run (CreateSimulationFunction &&create_simulation, ProcessSimulationResultFunction &&process_simulation_result) |
| | Run all simulations distributed over multiple MPI ranks. More...
|
| |
|
| template<class CreateSimulationFunction , class ProcessSimulationResultFunction > |
| EnsembleResultT< CreateSimulationFunction, ProcessSimulationResultFunction > | run_serial (CreateSimulationFunction &&create_simulation, ProcessSimulationResultFunction &&process_simulation_result) |
| | Run all simulations in serial. More...
|
| |
| template<class CreateSimulationFunction > |
| std::vector< SimulationT< CreateSimulationFunction > > | run_serial (CreateSimulationFunction &&create_simulation) |
| | Run all simulations in serial. More...
|
| |
|
| const Parameters & | get_parameters () const |
| | Get the input parameters that each simulation in the study is created from. More...
|
| |
| Parameters & | get_parameters () |
| | Get the input parameters that each simulation in the study is created from. More...
|
| |
|
| template<class CreateSimulationFunction , class ProcessSimulationResultFunction > |
| using | EnsembleResultT = std::conditional_t< std::is_void_v< ProcessedResultT< CreateSimulationFunction, ProcessSimulationResultFunction > >, void, std::vector< ProcessedResultT< CreateSimulationFunction, ProcessSimulationResultFunction > >> |
| | Type returned by run functions. Is void if ProcessedResultT is, otherwise a vector of ProcessedResultT. More...
|
| |
| template<class CreateSimulationFunction , class ProcessSimulationResultFunction > |
| using | ProcessedResultT = std::decay_t< std::invoke_result_t< ProcessSimulationResultFunction, SimulationT< CreateSimulationFunction >, size_t > > |
| | The return type of process_simulation_result. Ensures that the function is invocable. More...
|
| |
| template<class CreateSimulationFunction > |
| using | SimulationT = std::decay_t< std::invoke_result_t< CreateSimulationFunction, Parameters, Time, Step, size_t > > |
| | The return type of create_simulation. Ensures that the function is invocable. More...
|
| |
template<class ParameterType, typename TimeType, typename StepType = TimeType>
class mio::ParameterStudy< ParameterType, TimeType, StepType >
Class used to perform multiple simulation runs with randomly sampled parameters.
Note that the type of simulation is not determined until calling one of the run functions.
- Template Parameters
-
| ParameterType | The parameters used to create simulations. |
| TimeType | The time type used by the simulation, e.g. double or TimePoint. |
| StepType | The time step type used by the simulation, e.g. double or TimeStep. May be the same as TimeType. |
template<class ParameterType , typename TimeType , typename StepType = TimeType>
template<class CreateSimulationFunction , class ProcessSimulationResultFunction >
Type returned by run functions. Is void if ProcessedResultT is, otherwise a vector of ProcessedResultT.
template<class ParameterType , typename TimeType , typename StepType = TimeType>
| static std::vector<size_t> mio::ParameterStudy< ParameterType, TimeType, StepType >::distribute_runs |
( |
size_t |
num_runs, |
|
|
int |
num_procs |
|
) |
| |
|
inlinestaticprivate |
Distribute a number of runs over a number of processes.
Processes with low ranks get additional runs, if the number is not evenly divisible.
- Parameters
-
| num_runs | The total number of runs. |
| num_procs | The total number of processes, i.e. the size of MPI_Comm. |
- Returns
- A vector of size num_procs with the number of runs each process should make.
template<class ParameterType , typename TimeType , typename StepType = TimeType>
template<class CreateSimulationFunction , class ProcessSimulationResultFunction >
| EnsembleResultT<CreateSimulationFunction, ProcessSimulationResultFunction> mio::ParameterStudy< ParameterType, TimeType, StepType >::run |
( |
CreateSimulationFunction && |
create_simulation, |
|
|
ProcessSimulationResultFunction && |
process_simulation_result |
|
) |
| |
|
inline |
Run all simulations distributed over multiple MPI ranks.
- Parameters
-
| [in] | create_simulation | A callable sampling the study's parameters and returning a simulation. |
| [in] | process_simulation_result | A callable that takes the simulation and processes its result. |
- Returns
- A vector that contains processed simulation results for each run, or void if processing returns nothing.
Important: Do not forget to use mio::mpi::init and finalize when using this function!
Important side effect: Calling this function overwrites seed and counter of thread_local_rng(). Use this RNG when sampling parameters in create_simulation.
The function signature for create_simulation is SimulationT(const Parameters& study_parameters, Time t0, Step dt, size_t run_idx), where SimulationT is some kind of simulation. The function signature for process_simulation_result is ProcessedResultT(SimulationT&&, size_t run_index), where ProcessedResultT is a (de)serializable result, or void. A void function can be useful if the results should be fully handled during the study, for example, when memory is limited and the results have to be written to a disk.
If MPI is enabled and the results are non-void, all results are gathered on the root rank 0. Other ranks will return an empty vector.
template<class ParameterType , typename TimeType , typename StepType = TimeType>
template<class CreateSimulationFunction , class ProcessSimulationResultFunction >
| EnsembleResultT<CreateSimulationFunction, ProcessSimulationResultFunction> mio::ParameterStudy< ParameterType, TimeType, StepType >::run_impl |
( |
size_t |
start_run_idx, |
|
|
size_t |
end_run_idx, |
|
|
CreateSimulationFunction && |
create_simulation, |
|
|
ProcessSimulationResultFunction && |
process_simulation_result |
|
) |
| |
|
inlineprivate |
Main loop creating and running simulations.
- Parameters
-
| [in] | start_run_idx,end_run_idx | Range of indices. Performs one run for each index. |
| [in] | create_simulation | A callable sampling the study's parameters and return a simulation. |
| [in] | process_simulation_result | A callable that takes the simulation and processes its result. |
- Returns
- A vector that contains processed simulation results for each run.
Important side effect: Calling this function overwrites seed and counter of thread_local_rng(). Use this RNG when sampling parameters in create_simulation.
template<class ParameterType , typename TimeType , typename StepType = TimeType>
template<class CreateSimulationFunction >
| std::vector<SimulationT<CreateSimulationFunction> > mio::ParameterStudy< ParameterType, TimeType, StepType >::run_serial |
( |
CreateSimulationFunction && |
create_simulation | ) |
|
|
inline |
Run all simulations in serial.
- Parameters
-
| [in] | create_simulation | A callable sampling the study's parameters and returning a simulation. |
| [in] | process_simulation_result | (Optional) A callable that takes the simulation and processes its result. |
- Returns
- A vector containing (processed) simulation results for each run, or void if processing returns nothing.
Important side effect: Calling this function overwrites seed and counter of thread_local_rng(). Use this RNG when sampling parameters in create_simulation.
The function signature for create_simulation is SimulationT(const Parameters& study_parameters, Time t0, Step dt, size_t run_idx), where SimulationT is some kind of simulation. The function signature for process_simulation_result is ProcessedResultT(SimulationT&&, size_t run_index), where ProcessedResultT is a (de)serializable result, or void. A void function can be useful if the results should be fully handled during the study, for example, when memory is limited and the results have to be written to a disk.
template<class ParameterType , typename TimeType , typename StepType = TimeType>
template<class CreateSimulationFunction , class ProcessSimulationResultFunction >
| EnsembleResultT<CreateSimulationFunction, ProcessSimulationResultFunction> mio::ParameterStudy< ParameterType, TimeType, StepType >::run_serial |
( |
CreateSimulationFunction && |
create_simulation, |
|
|
ProcessSimulationResultFunction && |
process_simulation_result |
|
) |
| |
|
inline |
Run all simulations in serial.
- Parameters
-
| [in] | create_simulation | A callable sampling the study's parameters and returning a simulation. |
| [in] | process_simulation_result | (Optional) A callable that takes the simulation and processes its result. |
- Returns
- A vector containing (processed) simulation results for each run, or void if processing returns nothing.
Important side effect: Calling this function overwrites seed and counter of thread_local_rng(). Use this RNG when sampling parameters in create_simulation.
The function signature for create_simulation is SimulationT(const Parameters& study_parameters, Time t0, Step dt, size_t run_idx), where SimulationT is some kind of simulation. The function signature for process_simulation_result is ProcessedResultT(SimulationT&&, size_t run_index), where ProcessedResultT is a (de)serializable result, or void. A void function can be useful if the results should be fully handled during the study, for example, when memory is limited and the results have to be written to a disk.