MultiSim#

class MultiSim(sims=None, base_sim=None, label=None, n_runs=4, initialize=False, inplace=True, debug=False, **kwargs)[source]#

Bases: object

Class for running multiple copies of a simulation.

Parameters:
  • sims (Sim/list) – a single sim or a list of sims

  • base_sim (Sim) – the sim used for shared properties; if not supplied, the first of the sims provided

  • label (str) – the name of the multisim

  • n_runs (int) – if a single sim is provided, the number of replicates (default 4)

  • initialize (bool) – whether or not to initialize the sims (otherwise, initialize them during run)

  • inplace (bool) – whether to modify the sims in-place (default True); else return new sims

  • debug (bool) – if True, run in serial

  • kwargs (dict) – stored in run_args and passed to run()

Methods

brief()[source]#

A single-line display of the MultiSim; same as print(multisim)

show(output=False)[source]#

Print a moderate length summary of the MultiSim. See also multisim.disp() (detailed output) and multisim.brief() (short output).

Parameters:

output (bool) – if true, return a string instead of printing output

Example:

msim = ss.MultiSim(ss.demo(run=False), label='Example multisim')
msim.run()
msim.show() # Prints moderate length output
disp()[source]#

Display the full object

init_sims(**kwargs)[source]#

Initialize the sims

run(**kwargs)[source]#

Run the sims; see ss.multi_run() for additional arguments

Parameters:
  • n_runs (int) – how many replicates of each sim to run (if a list of sims is not provided)

  • inplace (bool) – whether to modify the sims in place (otherwise return copies)

  • kwargs (dict) – passed to multi_run(); use run_args to pass arguments to sim.run()

Returns:

None (modifies MultiSim object in place)

shrink(**kwargs)[source]#

Not to be confused with reduce(), this shrinks each sim in the msim; see sim.shrink() for more information.

Parameters:

kwargs (dict) – passed to sim.shrink() for each sim

reset()[source]#

Undo reduce() by resetting the base sim, which, and results

reduce(quantiles=None, use_mean=False, bounds=None, output=False)[source]#

Combine multiple sims into a single sim statistically: by default, use the median value and the 10th and 90th percentiles for the lower and upper bounds. If use_mean=True, then use the mean and ±2 standard deviations for lower and upper bounds.

Parameters:
  • quantiles (dict) – the quantiles to use, e.g. [0.1, 0.9] or {‘low : ‘0.1, ‘high’ : 0.9}

  • use_mean (bool) – whether to use the mean instead of the median

  • bounds (float) – if use_mean=True, the multiplier on the standard deviation for upper and lower bounds (default 2)

  • output (bool) – whether to return the “reduced” sim (in any case, modify the multisim in-place)

Example:

msim = ss.MultiSim(ss.Sim())
msim.run()
msim.reduce()
msim.summarize()
mean(bounds=None, **kwargs)[source]#

Alias for reduce(use_mean=True). See reduce() for full description.

Parameters:
  • bounds (float) – multiplier on the standard deviation for the upper and lower bounds (default, 2)

  • kwargs (dict) – passed to reduce()

median(quantiles=None, **kwargs)[source]#

Alias for reduce(use_mean=False). See reduce() for full description.

Parameters:
  • quantiles (list or dict) – upper and lower quantiles (default, 0.1 and 0.9)

  • kwargs (dict) – passed to reduce()

summarize(method='mean', quantiles=None, how='default')[source]#

Summarize the simulations statistically.

Parameters:
  • method (str) – one of ‘mean’ (default: [mean, 2*std]), ‘median’ ([median, min, max]), or ‘all’ (all results)

  • quantiles (dict) – if method=’median’, use these quantiles

  • how (str) – passed to sim.summarize()

plot(key=None, fig=None, fig_kw=None, plot_kw=None, fill_kw=None)[source]#

Plot all results in the MultiSim object.

If the MultiSim object has been reduced (i.e. mean or median), then plot the best value and uncertainty bound. Otherwise, plot individual sims.

Parameters:
  • key (str) – the results key to plot (by default, all)

  • fig (Figure) – if provided, plot results into an existing figure

  • fig_kw (dict) – passed to plt.subplots()

  • plot_kw (dict) – passed to plt.plot()

  • fill_kw (dict) – passed to plt.fill_between()