atomica.model.Variable¶
- class atomica.model.Variable(pop, id)[source]¶
Bases:
object
Integration object to manage compartments, characteristics, parameters, and links
This is a lightweight abstract class to store arrays of values at each simulation time step. It includes functionality that is common to all integration objects, and defines the interface to be implemented by derived classes.
Attributes
Variable code name
Unique identifier for the integration object
The units for the quantity, used for plotting and for validation.
Reference back to the Population containing this object
Methods
Produce a time series plot
Preallocate data storage
relink
Make the variable a dependency
unlink
Update the value at a given time index
- id¶
Unique identifier for the integration object
- property name: str¶
Variable code name
This is implemented as a property method because the
id
of theVariable
is a tuple containing the population name and the variable code name, so this property method returns just the variable code name portion. That way, storage does not need to be duplicated.- Returns:
A code name
- plot()[source]¶
Produce a time series plot
This is a quick function to make a basic line plot of this
Variable
. Mainly intended for debugging. Production-ready plots should be generated using the plotting library functions instead- Return type:
- pop¶
Reference back to the Population containing this object
- preallocate(tvec, dt)[source]¶
Preallocate data storage
This method gets called just before integration, once the final sizes of the arrays are known. Performance is improved by preallocating the arrays. The
tvec
attribute is assigned as-is, so it is typically a reference to the array stored in the parentModel
object. Thus, there is no duplication of storage there, andVariable.tvec
is mainly for convenience when interpolating or plotting.This method may be overloaded in derived classes to preallocate other variables specific to those classes.
- set_dynamic(**kwargs)[source]¶
Make the variable a dependency
For Compartments and Links, this does nothing. For Characteristics and Parameters, it will set the dynamic flag, but in addition, any validation constraints e.g. a Parameter that depends on Links cannot itself be dynamic, will be enforced.
This method generally must be overloaded in derived classes e.g.
Parameter.set_dynamic()
- Return type:
- units¶
The units for the quantity, used for plotting and for validation. Note that the default
'unknown'
units are distinct to dimensionless units, which have value''
- update(ti)[source]¶
Update the value at a given time index
This method performs any required computations to update the value of the variable at a given time index. For example, Parameters may require their update function to be called, while characteristics need their source compartments to be added up.
This method generally must be overloaded in derived classes e.g.
Parameter.update()