reno.components.Stock#
- class reno.components.Stock(label=None, init=None, doc=None, min=None, max=None, dim=1, group='', dtype=None)#
Bases:
TrackedReferenceA stock represents some bucket or quantity of material/thing that can accumulate (in_flows) or deplete (out_flows) over time.
https://en.wikipedia.org/wiki/Stock_and_flow https://insightmaker.com/docs/stocks
Note that stock update equations are based on the previous timestep’s values for all references (as opposed to flows/vars), e.g.:
` stock(t) = stock(t-1) + in_flows(t-1) - out_flows(t-1) `Methods
__init__([label, init, doc, min, max, dim, ...])clip(min, max)combine_eqs(eqs)Helper function to convert a list of equations into a single combined equation.
Create a combined equation that accounts for both inflows and outflows.
debug_equation(t[, sample])display()Display a markdown with latex for inflow equations and outflow equations.
equal(obj)equations(**kwargs)Get a list of string latex representations for all in and out flows.
eval([t, save, compute_mask, force])Compute the equation for the given timestep.
find_refs_of_type(search_type[, already_checked])Actually recursive as opposed to seek_refs, returns a list of all equation parts matching passed type.
from_dict(data, refs)Deserialize reference and parse data from dictionary previously saved from
to_dict().get_shape()For now this is returning an integer because we only allow a single additional dimension.
get_type()Similar to shape, this gets computed recursively, used to automatically determine if the value needs to be initialized with a certain numpy type.
history(index_eq)Get a reference to a previous value of this reference.
Subclasses that have a special way of defining the initial set of values (e.g. stocks with their _0 values) can override this function, automatically called at the end of
populate().is_static()Convenience shortcut for
reno.utils.is_static()- True if this equation doesn't rely on any dynamic values (thus constant), False if it does.latex(**kwargs)String representation suitable for a latex display.
max_refs()Get any references found in the max constraint equation.
min_refs()Get any references found in the min constraint equation.
not_equal(obj)plot([ax, plot_kwargs])Generate a matplotlib plot for this stock's simulation.
populate(n, steps)Initialize the matrix of values with size
n x steps.pt(**refs)Get a pytensor graph representing this piece of an equation.
pt_str(**refs)Construct a string containing relevant pytensor code for this piece of the equation.
qual_name([dot])Get a string with both the model and the reference name if this model is a submodel of something else.
resolve_init_array(obj_or_eq)Convert a number or scalar/distribution into correct starting array.
seek_refs()Immediate refs only, depth=1.
series_max()series_min()sum([axis])to_dict()Serialize class into a dictionary for saving to file.
Attributes
dtypeThe type of each underlying value.
shapeThe size of the data dimension, 1 by default.
timeseriesGet a timeseries view of the data (includes all historical data across all timesteps.)
modelKeep a reference to container model, makes it easier to compare refs across multiple models.
initInitial value/equation for initial value for stock/flow/var at t=0
dimSize of an optional extra dimension, allowing a given reference to describe a vector of values at every timestep.
implicitImplicit components (normally created as subcomponents of more advanced operations) don't show up in diagrams, latex, or output JSON, since they are created by operations.
computed_maskFollows same shape as value (up through first two dimensions), set of booleans indicating which values have already been evaluated and saved.
labelLabel is what's used in any visual representation (e.g. allows spaces where name does not.).
docA docstring to explain/describe the reference.
- Parameters:
label (str)
init (int | float | Distribution | Scalar | EquationPart)
doc (str)
min (EquationPart)
max (EquationPart)
dim (int)
group (str)
dtype (type)
- __annotations__ = {}#
- __iadd__(obj)#
- __isub__(obj)#
- __module__ = 'reno.components'#
- __setattr__(name, value)#
Implement setattr(self, name, value).
- combine_eqs(eqs)#
Helper function to convert a list of equations into a single combined equation. (Essentially a big summation operator.)
- Parameters:
eqs (list[EquationPart])
- Return type:
- compute_diff_eq()#
Create a combined equation that accounts for both inflows and outflows.
- Return type:
- debug_equation(t, sample=0, **kwargs)#
- display()#
Display a markdown with latex for inflow equations and outflow equations.
- equations(**kwargs)#
Get a list of string latex representations for all in and out flows.
- Return type:
list[str]
- from_dict(data, refs)#
Deserialize reference and parse data from dictionary previously saved from
to_dict().- Parameters:
data (dict)
refs (dict[str, TrackedReference])
- initial_vals()#
Subclasses that have a special way of defining the initial set of values (e.g. stocks with their _0 values) can override this function, automatically called at the end of
populate().
- plot(ax=None, plot_kwargs=None)#
Generate a matplotlib plot for this stock’s simulation.
- to_dict()#
Serialize class into a dictionary for saving to file. Stock has to modify the parent TrackedReference class serialization to account for equations being handled a little differently.
- Return type:
dict