MultiSim#

class MultiSim(sims=None, base_sim=None, label=None, n=None, **kwargs)[source]#

Bases: prettyobj

The MultiSim class handles the running of multiple simulations

Methods

run(compute_stats=True, **kwargs)[source]#

Run all simulations in the MultiSim

compute_stats(return_raw=False, quantiles=None, use_mean=False, bounds=None)[source]#

Compute statistics across multiple sims

static merge(*args, base=False)[source]#

Convenience method for merging two MultiSim objects.

Parameters:
  • args (MultiSim) – the MultiSims to merge (either a list, or separate)

  • base (bool) – if True, make a new list of sims from the multisim’s two base sims; otherwise, merge the multisim’s lists of sims

Returns:

a new MultiSim object

Return type:

msim (MultiSim)

Examples:

mm1 = fp.MultiSim.merge(msim1, msim2, base=True) mm2 = fp.MultiSim.merge([m1, m2, m3, m4], base=False)

split(inds=None, chunks=None)[source]#

Convenience method for splitting one MultiSim into several. You can specify either individual indices of simulations to extract, via inds, or consecutive chunks of indices, via chunks. If this function is called on a merged MultiSim, the chunks can be retrieved automatically and no arguments are necessary.

Parameters:
  • inds (list) – a list of lists of indices, with each list turned into a MultiSim

  • chunks (int or list) – if an int, split the MultiSim into that many chunks; if a list return chunks of that many sims

Returns:

A list of MultiSim objects

Examples:

m1 = fp.MultiSim(fp.Sim(label='sim1'))
m2 = fp.MultiSim(fp.Sim(label='sim2'))
m3 = fp.MultiSim.merge(m1, m2)
m3.run()
m1b, m2b = m3.split()

msim = fp.MultiSim(fp.Sim(), n_runs=6)
msim.run()
m1, m2 = msim.split(inds=[[0,2,4], [1,3,5]])
mlist1 = msim.split(chunks=[2,4]) # Equivalent to inds=[[0,1], [2,3,4,5]]
mlist2 = msim.split(chunks=2) # Equivalent to inds=[[0,1,2], [3,4,5]]
remerge(base=True, recompute=True, **kwargs)[source]#

Split a sim, compute stats, and re-merge.

Parameters:
  • base (bool) – whether to use the base sim (otherwise, has no effect)

  • kwargs (dict) – passed to msim.split()

Note: returns a new MultiSim object (if that concerns you).

to_df(yearly=False, mean=False)[source]#

Export all individual sim results to a dataframe

plot(to_plot=None, plot_sims=True, do_show=None, do_save=None, filename='fp_multisim.png', fig_args=None, axis_args=None, plot_args=None, style=None, colors=None, **kwargs)[source]#

Plot the MultiSim

Parameters:

plot_sims (bool) – whether to plot individual sims (else, plot with uncertainty bands)

See sim.plot() for additional args.