metawards.VariableSets

class metawards.VariableSets[source]

This class holds the collection of all VariableSet objects that contain the set of adjustable variables that are used to control a single run of the model

Examples

>>> v = VariableSets()
>>> v.append({"beta[2]": 0.95, "beta[3]": 0.9})
>>> v.append({"beta[1]": 0.86, "beta[2]": 0.89})
>>> print(v)
{(beta[2]=0.95, beta[3]=0.9)[repeat 1], (beta[1]=0.86,
beta[2]=0.89)[repeat 1]}
>>> v = v.repeat(2)
>>> print(v)
{(beta[2]=0.95, beta[3]=0.9)[repeat 1], (beta[1]=0.86,
beta[2]=0.89)[repeat 1], (beta[2]=0.95, beta[3]=0.9)[repeat 2],
(beta[1]=0.86, beta[2]=0.89)[repeat 2]}
__init__()[source]

Initialise an empty VariableSets object

Parameters:None
Returns:
Return type:None

Methods

__init__() Initialise an empty VariableSets object
append(variables) Append the passed set of variables to the set that will be used to run a model.
read(filename, line_numbers) Read and return collection of VariableSet objects from the specified line number(s) of the specified file
repeat(nrepeats) Return a copy of this VariableSet in which all of the unique VaribleSet objects have been repeated ‘nrepeats’ times
append(variables: metawards._variableset.VariableSet)[source]

Append the passed set of variables to the set that will be used to run a model. If there are any existing VariableSet objects in this list, then the new VariableSet must adjust the same variables

Parameters:variables (VariableSet) – The VariableSet to append to this list. If you pass a dict of {str: float} values, then this will automatically be converted into a VariableSet. Note that all VariableSet objects in a VariableSets must adjust the same variables
Returns:
Return type:None
static read(filename: str, line_numbers: List[int] = None)[source]

Read and return collection of VariableSet objects from the specified line number(s) of the specified file

Parameters:
  • filename (str) – The name of the file from which to read the VariableSets
  • line_numbers (List[int]) – The line numbers from the file to read. This is 0-indexed, meaning that the first line is line 0. If this is None, then all lines are read and used
Returns:

variables – The collection of VariableSet objects that have been read, in the order they were read from the file

Return type:

VariableSets

repeat(nrepeats: int)[source]

Return a copy of this VariableSet in which all of the unique VaribleSet objects have been repeated ‘nrepeats’ times

Parameters:nrepeats (int) – The number of repeats of the VariableSet objects to perform
Returns:repeats – A new VariableSets object containing ‘nrepeats’ copies of the VariableSet objects from this set
Return type:VariableSets