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
__delattr__
(name, /)Implement delattr(self, name).
__dir__
()Default dir() implementation.
__eq__
(other)Return self==value.
__format__
(format_spec, /)Default object formatter.
__ge__
(value, /)Return self>=value.
__getattribute__
(name, /)Return getattr(self, name).
__getitem__
(i)Return the VariableSet at the specified index
__gt__
(value, /)Return self>value.
__init__
()Initialise an empty VariableSets object
__init_subclass__
This method is called when a class is subclassed.
__le__
(value, /)Return self<=value.
__len__
()__lt__
(value, /)Return self<value.
__ne__
(value, /)Return self!=value.
__new__
(**kwargs)Create and return a new object.
__reduce__
()Helper for pickle.
__reduce_ex__
(protocol, /)Helper for pickle.
__repr__
()Return repr(self).
__setattr__
(name, value, /)Implement setattr(self, name, value).
__sizeof__
()Size of object in memory, in bytes.
__str__
()Return str(self).
__subclasshook__
Abstract classes can override this to customize issubclass().
_read_horizontal
(lines, line_numbers)Read the data from the horizontal lines
_read_vertical
(lines)Read the data from the vertical lines
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
This function resets the names of all of the output directories for each run so that they are numbered sequentially from one
This function resets the names of all of the output directories for each run so that they all have a globally unique UID
Attributes
__dict__
__doc__
__hash__
__module__
__weakref__
list of weak references to the object (if defined)
-
__init__
()[source]¶ Initialise an empty VariableSets object
- Parameters
None –
- Returns
- Return type
None
-
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: Optional[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
-
repeat
(nrepeats: Union[List[int], int])[source]¶ Return a copy of this VariableSet in which all of the unique VaribleSet objects have been repeated ‘nrepeats’ times
- Parameters
nrepeats (int or list[int]) – The number of repeats of the VariableSet objects to perform. If this is a list, then nrepeats[i] will be the number of times to repeat variables[i]
- Returns
repeats – A new VariableSets object containing ‘nrepeats’ copies of the VariableSet objects from this set
- Return type
-