pyPENELOPE

multipleloop – Loop around many parameters

Note

Copy from scitools.multipleloop due to a problem with other scitools modules with py2exe http://code.google.com/p/scitools/

This module provides a tool for handling computer experiments with of a set of input parameters, where each input parameter is varied in a prescribed fashion.

In short, the parameters are held in a dictionary where the keys are the names of the parameters and the values are the numerical, string or other values of the parameters. The value can take on multiple values: e.g., an integer parameter ‘a’ can have values -1, 1 and 10. Similarly, a string parameter ‘method’ can have values ‘Newton’ and ‘Bisection’. The module will generate all combination of all parameters and values, which in the mentioned example will be (-1, ‘Newton’), (1, ‘Newton’), (10, ‘Newton’), (-1, ‘Bisection’), (1, ‘Bisection’), and (10, ‘Bisection’). Particular combination of values can easily be removed.

The usage and implementation of the module are documented in the book “Python Scripting for Computational Science” (H. P. Langtangen, Springer, 2009), Chapter 12.1.

penelopetools.api.util.multipleloop.combine(prm_values)

Compute the combination of all parameter values in the prm_values (nested) list. Main function in this module.

Parameters:prm_values (list or dict) – nested list of (parameter_name, list_of_parameter_values) or dictionary prm_values[parameter_name] = list_of_parameter_values
Returns:(all,names,varied) where
  • all contains all combinations (experiments) all[i] is the list of individual parameter values in experiment no i
  • names contains a list of all parameter names
  • varied holds a list of parameter names that are varied (i.e. where there is more than one value of the parameter, the rest of the parameters have fixed values)

Code example:

>>> dx = array([1.0/2**k for k in range(2,5)])
>>> dt = 3*dx;  dt = dt[:-1]
>>> p = {'dx': dx, 'dt': dt}
>>> p
{'dt': [ 0.75 , 0.375,], 'dx': [ 0.25  , 0.125 , 0.0625,]}
>>> all, names, varied = combine(p)
>>> all
[[0.75, 0.25], [0.375, 0.25], [0.75, 0.125], [0.375, 0.125],
 [0.75, 0.0625], [0.375, 0.0625]]