scippuncertainty.mc.driver.run#

scippuncertainty.mc.driver.run(fn, *, n_samples, samplers, accumulators=None, n_threads=1, seed=None, progress=None, description='Monte-Carlo')[source]#

Propagate uncertainties using Monte-Carlo.

This function drives the propagation by drawing samples, calling the provided function on each, anc accumulating the results.

Parameters:
  • fn (Callable[..., dict[str, DataArray] | SkipSampleType]) – Function to perform the calculation that you want to propagate uncertainties through.

  • n_samples (int) – Number of samples to draw in total.

  • samplers (dict[str, Sampler]) – Dict of samplers to generate the input data. Samples are passed to fn by keyword arguments according to the keys in this dict.

  • accumulators (Optional[dict[str, Accumulator]], default: None) – Dict of accumulators for the results. Each item in the output of fn is passed to the accumulator with the same key.

  • n_threads (int, default: 1) – Number of threads. Setting n_threads to something higher than 1 only makes sense if fn spends a significant amount of time in code that releases the GIL (e.g. most functions in Scipp).

  • seed (Union[Generator, list[Generator], int, list[int], SeedSequence, None], default: None) – Used to seed one random number generator per thread. See scippuncertainty.random.make_rngs() for details.

  • progress (Optional[bool], default: None) – If True, show progress bars in the terminal. This requires the package rich. If False, no progress is shown. If None, the default, progress bars are shown if and only if rich is installed.

  • description (str, default: 'Monte-Carlo') – Message to display in progress bars.

Returns:

MCResult – Dict of results obtained from the accumulators. It contains one item per accumulator with the same key.