reno.components.Stock#

class reno.components.Stock(label=None, init=None, doc=None, min=None, max=None, dim=1, group='', cgroup='', dtype=None)#

Bases: TrackedReference

A 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) - out_flows(t)

Methods

__init__([label, init, doc, min, max, dim, ...])

Create a stock component.

add_inflow(obj)

Add the flow or equation (creating an implicit flow) or a list of either as inflow(s) to this stock.

add_outflow(obj)

Add the specified flow to the set of outflows on this stock.

astype(dtype)

Returns a symbolic operation to convert the output of this equation to the specified type.

clip(min, max)

Returns a symbolic operation for enforcing the output is between the passed min and max.

combine_eqs(eqs)

Helper function to convert a list of equations into a single combined equation.

compute_diff_eq()

Create a combined equation that accounts for both inflows and outflows.

debug_equation(t[, sample])

Get a latex string output with the debug version of this equation.

display()

Display a markdown with latex for inflow equations and outflow equations.

equal(obj)

Returns a symbolic operation for checking equality with passed object.

equations(**kwargs)

Get a list of string latex representations for all in and out flows.

eval([t, save, force])

Compute the equation for the given timestep.

find_parts_of_type(search_type[, ...])

Recursively search for all EquationParts in the tree of the specified type.

from_dict(data, refs)

Deserialize reference and parse data from dictionary previously saved from to_dict().

get_shape()

Get the size of the additional "data" dimension.

get_type()

Get the type of the target output of this equation expression.

history(index_eq)

Get a reference to a previous value of this reference.

initial_vals()

Assign the starting values for t=0, the first step of the simulation.

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.

mean([axis])

Returns a symbolic operation to find the series-wise mean of the array.

min_refs()

Get any references found in the min constraint equation.

not_equal(obj)

Returns a symbolic operation for checking inequality with passed object.

plot([ax])

Plot (or add to passed axes) this reference's values.

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([include_ref_types])

Recursively find a list of all References immediately underneath this part.

series_max()

Returns a symbolic operation to find the series-wise maximum of the array.

series_min()

Returns a symbolic operation to find the series-wise minimum of the array.

sum([axis])

Returns a symbolic operation to find the series-wise sum of the array.

to_dict()

Serialize class into a dictionary for saving to file.

Attributes

dtype

The type of each underlying value.

outflows

Returns operation representing the sum of the flows leaving this stock.

shape

The size of the data dimension, 1 by default.

space

Returns an operation that computes how much space is remaining in this stock after taking into account any outflows for this timestep.

timeseries

Returns symbolic operation for getting a timeseries view of the data.

model

Keep a reference to container model, makes it easier to compare refs across multiple models.

init

Initial value/equation for initial value for stock/flow/var at t=0

dim

Size of an optional extra dimension, allowing a given reference to describe a vector of values at every timestep.

implicit

Implicit 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_mask

Follows same shape as value (up through first two dimensions), set of booleans indicating which values have already been evaluated and saved.

label

Label is what's used in any visual representation (e.g. allows spaces where name does not.).

doc

A docstring to explain/describe the reference.

Parameters:
__annotations__ = {}#
__iadd__(obj)#

Return stock with specified flow(s) or equation(s) (implicit flow) as an inflow.

Parameters:

obj (Flow | EquationPart | list[EquationPart | Flow])

Return type:

Stock

__isub__(obj)#

Return stock with specified flow applied as an outflow.

Parameters:

obj (Flow | list[Flow])

Return type:

Stock

__lshift__(flow)#

Return flow(s), having applied as an inflow to this stock.

(stock << inflow)

Parameters:

flow (Flow | EquationPart | list[EquationPart | Flow])

Return type:

Flow | EquationPart | list[EquationPart | Flow]

__module__ = 'reno.components'#
__rrshift__(flow)#

Return stock with flow(s) or equation(s) (implicit flow) as an inflow.

(inflow >> stock)

Parameters:

flow (Flow | EquationPart | list[EquationPart | Flow])

Return type:

Stock

__rshift__(flow)#

Return flow, having applied as an outflow to this stock.

(stock >> outflow)

Parameters:

flow (Flow | list[Flow])

Return type:

Flow | list[Flow]

__setattr__(name, value)#

Implement setattr(self, name, value).

Parameters:
  • name (str)

  • value (Any)

Return type:

None

add_inflow(obj)#

Add the flow or equation (creating an implicit flow) or a list of either as inflow(s) to this stock.

Parameters:

obj (Flow | EquationPart | list[EquationPart | Flow])

Return type:

None

add_outflow(obj)#

Add the specified flow to the set of outflows on this stock.

Parameters:

obj (Flow | list[Flow])

Return type:

None

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:

EquationPart

compute_diff_eq()#

Create a combined equation that accounts for both inflows and outflows.

Return type:

EquationPart

debug_equation(t, sample=0, **kwargs)#

Get a latex string output with the debug version of this equation.

Parameters:
  • t (int)

  • sample (int)

  • kwargs (dict)

Return type:

str

display()#

Display a markdown with latex for inflow equations and outflow equations.

Return type:

None

equations(**kwargs)#

Get a list of string latex representations for all in and out flows.

Parameters:

kwargs (dict)

Return type:

list[str]

from_dict(data, refs)#

Deserialize reference and parse data from dictionary previously saved from to_dict().

Parameters:
Return type:

None

initial_vals()#

Assign the starting values for t=0, the first step of the simulation.

Return type:

None

property outflows: Operation#

Returns operation representing the sum of the flows leaving this stock.

property space: Operation#

Returns an operation that computes how much space is remaining in this stock after taking into account any outflows for this timestep.

Note that this requires a max value to be set on this stock.

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