parasweep.sweepers module¶
-
class
parasweep.sweepers.
Sweep
(*args, **kwargs)[source]¶ Bases:
abc.ABC
Abstract class for parameter sweep types.
Sweeps must define an initialization using
__init__
, the sweep length using__len__
, an iteration usingelements
, and a type of mapping usingmapping
.-
elements
()[source]¶ Return the elements of the sweep.
May be lazily evaluated, depending on the type of sweep.
-
mapping
(sim_ids, sweep_id, save=True)[source]¶ Return a mapping between the simulation IDs and the parameter sets.
The mapping may be from simulation IDs to parameter sets or vice-versa, depending on what is convenient for the type of sweep.
Parameters: - sim_ids (list) – The simulation IDs that were assigned to each parameter set, in the
same order as returned by
elements
. - sweep_id (str) – The sweep ID
- save (bool) – Whether to save the mapping to disk. The filename should be of the
form
sim_ids_{sweep_id}
, with an extension depending on the mapping type. True by default.
- sim_ids (list) – The simulation IDs that were assigned to each parameter set, in the
same order as returned by
-
-
class
parasweep.sweepers.
CartesianSweep
(sweep_params)[source]¶ Bases:
parasweep.sweepers.Sweep
A Cartesian product parameter sweep.
Parameters: sweep_params (dict) – A dictionary containing the parameter names as keys and lists of values to sweep over as values. -
elements
()[source]¶ Return the elements of the sweep.
May be lazily evaluated, depending on the type of sweep.
-
mapping
(sim_ids, sweep_id, save=True)[source]¶ Return a labelled array which maps parameters to simulation IDs.
See
parasweep.sweepers.Sweep.mapping()
for argument information. Returns a multidimensional labelled array (using xarray) which maps the parameters to the simulation IDs. The array coordinates correspond to each sweep parameter, while the values contain the simulation IDs. Ifsave=True
, this array will be saved as a netCDF file with the namesim_ids_{sweep_id}.nc
.
-
-
class
parasweep.sweepers.
FilteredCartesianSweep
(sweep_params, filter_func)[source]¶ Bases:
parasweep.sweepers.Sweep
A parameter sweep which uses specified parameter sets.
Parameters: - sweep_params (dict) – A dictionary containing the parameter names as keys and lists of values to sweep over as values.
- filter_func (function) – A boolean function of parameter values; only parameter sets that
return true will be included in the sweep. The arguments of the
function should be named after the corresponding parameters. If not all
the parameters in the sweep are used in the filtering, the
**kwargs
argument should be defined, or else an error will be raised.
-
elements
()[source]¶ Return the elements of the sweep.
May be lazily evaluated, depending on the type of sweep.
-
mapping
(sim_ids, sweep_id, save=True)[source]¶ Return a dictionary which maps simulation IDs to parameter sets.
See
parasweep.sweepers.Sweep.mapping()
for argument information. Ifsave=True
, this dictionary will be saved as a JSON file with the namesim_ids_{sweep_id}.json
.
-
class
parasweep.sweepers.
SetSweep
(param_sets)[source]¶ Bases:
parasweep.sweepers.Sweep
A Cartesian product parameter sweep with filtering.
Parameters: param_sets (list) – A list containing the parameter sets to use in the sweep as dictionaries. -
elements
()[source]¶ Return the elements of the sweep.
May be lazily evaluated, depending on the type of sweep.
-
mapping
(sim_ids, sweep_id, save=True)[source]¶ Return a dictionary which maps simulation IDs to parameter sets.
See
parasweep.sweepers.Sweep.mapping()
for argument information. Ifsave=True
, this dictionary will be saved as a JSON file with the namesim_ids_{sweep_id}.json
.
-
-
class
parasweep.sweepers.
RandomSweep
(sweep_params, length, random_state=None)[source]¶ Bases:
parasweep.sweepers.Sweep
A random parameter sweep.
Each parameter is treated as an independent random variable with a given distribution.
Parameters: - sweep_params (dict) – A dictionary containing the parameter names as keys and SciPy random
variables (i.e., instances of subclasses of
_RandomVariable
, or ofscipy.stats._distn_infrastructure.rv_generic
) as values. - length (int) – The number of sets of random parameters to draw
- random_state (numpy.random.RandomState instance, optional) – If provided, will use the given random state in generating random numbers. By default, it uses the global random state.
-
elements
()[source]¶ Return the elements of the sweep.
May be lazily evaluated, depending on the type of sweep.
-
mapping
(sim_ids, sweep_id, save=True)[source]¶ Return a dictionary which maps simulation IDs to parameter sets.
See
parasweep.sweepers.Sweep.mapping()
for argument information. Ifsave=True
, this dictionary will be saved as a JSON file with the namesim_ids_{sweep_id}.json
.
- sweep_params (dict) – A dictionary containing the parameter names as keys and SciPy random
variables (i.e., instances of subclasses of