reno.components.Function#

class reno.components.Function(f, *args, inject_mathlib=True, pt_mathlib=None, np_mathlib=None, **kwargs)#

Bases: Reference

Represents a call to a python function _outside_ of a model/system of equations.

This is to allow for computations that might be a little complex, too fancy, or too annoying to specify entirely within the EquationPart system. By wrapping the call with this class, we defer actual computation/computation of input parameters until eval time, it’s a thunk!

Note

Any passed arguments that _are_ equations will be evaluated and passed in to the actual function call when .eval() is run. In a simulation run with stocks/flows etc., these arguments are likely to resolve to numpy arrays, which is the vector of all samples for that argument at the current eval’ed timestep. (So the function should expect to do vector operations, numpy will probably automagically handle this.)

Parameters:
  • f (Callable) – The python function to run when .eval() is called.

  • args (list[any]) – Arguments to pass to f when .eval() is called. Any EquationPart arguments will have their .eval() called prior to f’s execution.

  • inject_mathlib (bool) – Whether to pass a mathlib arg to allow running in both normal reno math mode as well as pymc. Requires underlying function to take mathlib.

  • pt_mathlib – The library to use for pytensor operations.

  • np_mathlib – The library to use for numpy operations.

  • kwargs (list[any]) – Keyword args to pass to f when .eval() is called. Any EquationPart arguments will have their .eval() called prior to f’s execution.

NOTE: theoretically works in pymc conversion (as long as mathlib is used) but relatively untested as of writing.

NOTE: pt_str isn’t implemented in this class due to difficulty in referring to an unknown external function via a string.

Methods

__init__(f, *args[, inject_mathlib, ...])

clip(min, max)

equal(obj)

eval([t, save, force])

Eval any function arguments as needed, and then call the function itself.

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.

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.

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)

Get a latex-suitable string representation of the function, use texttt to make it look like code and distinguishable from flows/vars/stocks/etc.

not_equal(obj)

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.

seek_refs()

Immediate refs only, depth=1.

series_max()

series_min()

sum([axis])

Attributes

dtype

The type of each underlying value.

shape

The size of the data dimension, 1 by default.

timeseries

Get a timeseries view of the data (includes all historical data across all timesteps.)

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.

__annotations__ = {}#
__module__ = 'reno.components'#
__repr__()#

Return repr(self).

eval(t=0, save=False, force=False, **kwargs)#

Eval any function arguments as needed, and then call the function itself.

Parameters:
  • t (int) – Timestep along simulation at which to evaluate.

  • save (bool) – Ignored in this subclass, but passed along in sub- .eval() calls.

  • force (bool)

Return type:

int | float | ndarray

latex(**kwargs)#

Get a latex-suitable string representation of the function, use texttt to make it look like code and distinguishable from flows/vars/stocks/etc.

Return type:

str

pt(**refs)#

Get a pytensor graph representing this piece of an equation.

Parameters:

refs (dict[str, TensorVariable])

Return type:

TensorVariable