firecrown.updatable
Parameters that can be updated, and collections of them.
Abstract class Updatable is the base class from which any class in Firecrown
that supports updating from a ParamsMap should inherit. Such classes are
expected to change state only in through their implementation of _update()
(including any other private methods used to implement _update()). Other
functions should not change the data of Updatable objects.
UpdatableCollection is a subclass of the built-in list. It implements the
Updatable interface by calling update() on each element it contains.
The append() method is overridden to make sure that only objects which are of
a type that implements Updatable can be appended to the list.
Attributes
Exceptions
Error for when a required parameter is missing. |
Classes
Abstract class Updatable is the base class for Updatable objects in Firecrown. |
|
Class that represents a collection of updatable objects. |
Functions
|
Get a ParamsMap with the default values of all parameters in the updatables. |
|
Get a ParamsMap with the default values of all parameters in the updatables. |
Module Contents
- type firecrown.updatable.GeneralUpdatable = 'Updatable' | 'UpdatableCollection'
- exception firecrown.updatable.MissingSamplerParameterError(parameter)[source]
Bases:
RuntimeError
Error for when a required parameter is missing.
Raised when an Updatable fails to be updated because the ParamsMap supplied for the update is missing a parameter that should have been provided by the sampler.
- Parameters:
parameter (str)
- parameter
- class firecrown.updatable.Updatable(parameter_prefix=None)[source]
Bases:
abc.ABC
Abstract class Updatable is the base class for Updatable objects in Firecrown.
Any class in Firecrown that supports updating from a ParamsMap should inherit from
Updatable. Such classes are expected to change state only in through their implementation of _update (including any other private methods used to implement _update). Other functions should not change the data of Updatable objects.- Parameters:
parameter_prefix (None | str)
- parameter_prefix: None | str = None
- __setattr__(key, value)[source]
Set the attribute named
keyto the supplied value.There is special handling for two types:
SamplerParameterandInternalParameter.We also keep track of all
Updatableinstance variables added, appending a reference to each toself._updatablesas well as storing the attribute directly.- Parameters:
key (str) – name of the attribute
value (Any) – value for the attribute
- Return type:
None
- set_parameter(key, value)[source]
Sets the parameter to the given value.
Assure this InternalParameter or SamplerParameter has not already been set, and then set it.
- Parameters:
key (str) – name of the attribute
value (firecrown.parameters.InternalParameter | firecrown.parameters.SamplerParameter) – value for the attribute
- Return type:
None
- set_internal_parameter(key, value)[source]
Assure this InternalParameter has not already been set, and then set it.
- Parameters:
key (str) – name of the attribute
value (firecrown.parameters.InternalParameter) – value for the attribute
- Return type:
None
- set_sampler_parameter(value)[source]
Assure this SamplerParameter has not already been set, and then set it.
- Parameters:
value (firecrown.parameters.SamplerParameter) – value for the attribute
- Return type:
None
- update(params)[source]
Update self by calling to prepare for the next MCMC sample.
We first update the values of sampler parameters from the values in params. An error will be raised if any of self’s sampler parameters can not be found in params or if any internal parameters are provided in params.
We then use the params to update each contained
UpdatableorUpdatableCollectionobject. The method_update()is called to give subclasses an opportunity to do any other preparation for the next MCMC sample.- Parameters:
params (firecrown.parameters.ParamsMap) – new parameter values
- Return type:
None
- is_updated()[source]
Determine if the object has been updated.
A default-constructed Updatable has not been updated. After update, but before reset, has been called the object is updated. After reset has been called, the object is not currently updated.
- Returns:
True if the object is currently updated, and False if not.
- Return type:
bool
- reset()[source]
Reset the updatable.
Clean up self by clearing the _updated status and reseting all internals. We call the abstract method _reset to allow derived classes to clean up any additional internals.
Each MCMC framework connector should call this after handling an MCMC sample.
- Return type:
None
- required_parameters()[source]
Returns all information about parameters required by this object.
This object returned contains the information for all parameters defined in the implementing class, and any additional parameters.
- Returns:
a RequiredParameters object containing all relevant parameters
- Return type:
- get_params_names()[source]
Return the names of the parameters required by this object.
The order of the returned names is arbitrary.
- Returns:
a list of parameter names
- Return type:
list[str]
- firecrown.updatable.T
- class firecrown.updatable.UpdatableCollection(iterable=None)[source]
Bases:
collections.UserList[T],Generic[T]
Class that represents a collection of updatable objects.
UpdatableCollection is a list of Updatable objects and is itself supports
update()andreset()(although it does not inherit fromUpdatable).Every item in an UpdatableCollection must itself be
Updatable. Callingupdate()on the collection results in every item in the collection being updated.- Parameters:
iterable (None | collections.abc.Iterable[T])
- update(params)[source]
Update self by calling update() on each contained item.
- Parameters:
params (firecrown.parameters.ParamsMap) – new parameter values for each contained item
- Return type:
None
- is_updated()[source]
Returns whether this updatable has been updated.
Return True if the object is currently updated, and False if not. A default-constructed Updatable has not been updated. After update, but before reset, has been called the object is updated. After reset has been called, the object is not currently updated.
- Return type:
bool
- required_parameters()[source]
Return a RequiredParameters object.
The RequiredParameters object is formed by concatenating the RequiredParameters of each contained item.
- Return type:
- firecrown.updatable.get_default_params(*args)[source]
Get a ParamsMap with the default values of all parameters in the updatables.
- Parameters:
args (Updatable) – updatables to get the default parameters from
- Returns:
a ParamsMap with the default values of all parameters
- Return type:
dict[str, float]