reno.components.EquationPart#
- class reno.components.EquationPart(sub_equation_parts=None)#
Bases:
objectThe base object that represents some portion/subtree of a compute or equation tree.
The purpose of EquationParts is to allow constructing an equation as a “deferred computation” - essentially symbolically creating a compute tree of objects all with
.eval()functions that get recursively run later on when a simulation is running/equation is computing (spawned with root ``.eval()`.)Note
In order to get nice semantics when constructing equations, all math operations applied to an EquationPart get replaced with their corresponding operation EquationPart. This means a
5 + Scalar(4)gets converted into anOperation("+", Scalar(5), Scalar(4))Methods
__init__([sub_equation_parts])Create a root node of an equation tree with the provided parts as subtrees.
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.
equal(obj)Returns a symbolic operation for checking equality with passed object.
eval([t, save, force])Execute the compute graph for this equation, this needs to be implemented in every subclass.
find_parts_of_type(search_type[, ...])Recursively search for all EquationParts in the tree of the specified type.
Get the size of the additional "data" dimension.
get_type()Get the type of the target output of this equation expression.
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)Construct a string representation of this portion of the equation for use in a latex display.
mean([axis])Returns a symbolic operation to find the series-wise mean of the array.
not_equal(obj)Returns a symbolic operation for checking inequality with passed object.
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([include_ref_types])Recursively find a list of all References immediately underneath this part.
Returns a symbolic operation to find the series-wise maximum of the array.
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.
Attributes
The type of each underlying value.
The size of the data dimension, 1 by default.
Returns symbolic operation for getting a timeseries view of the data.
- Parameters:
sub_equation_parts (list[EquationPart])
- __add__(obj)#
Returns symbolic ‘+’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __and__(obj)#
Returns symbolic ‘&’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __annotations__ = {}#
- __dict__ = mappingproxy({'__module__': 'reno.components', '__doc__': 'The base object that represents some portion/subtree of a compute\n or equation tree.\n\n The purpose of EquationParts is to allow constructing an equation as a\n "deferred computation" - essentially symbolically creating a compute\n tree of objects all with ``.eval()`` functions that get recursively run\n later on when a simulation is running/equation is computing (spawned with\n root ``.eval()`.)\n\n Note:\n In order to get nice semantics when constructing equations, all math\n operations applied to an EquationPart get replaced with their\n corresponding operation EquationPart. This means a ``5 + Scalar(4)``\n gets converted into an ``Operation("+", Scalar(5), Scalar(4))``\n ', '__init__': <function EquationPart.__init__>, '__add__': <function EquationPart.__add__>, '__sub__': <function EquationPart.__sub__>, '__neg__': <function EquationPart.__neg__>, '__mul__': <function EquationPart.__mul__>, '__truediv__': <function EquationPart.__truediv__>, '__mod__': <function EquationPart.__mod__>, '__pow__': <function EquationPart.__pow__>, '__radd__': <function EquationPart.__radd__>, '__rsub__': <function EquationPart.__rsub__>, '__rmul__': <function EquationPart.__rmul__>, '__rtruediv__': <function EquationPart.__rtruediv__>, '__rmod__': <function EquationPart.__rmod__>, '__rpow__': <function EquationPart.__rpow__>, '__lt__': <function EquationPart.__lt__>, '__le__': <function EquationPart.__le__>, '__gt__': <function EquationPart.__gt__>, '__ge__': <function EquationPart.__ge__>, '__and__': <function EquationPart.__and__>, '__rand__': <function EquationPart.__rand__>, '__or__': <function EquationPart.__or__>, '__ror__': <function EquationPart.__ror__>, '__getitem__': <function EquationPart.__getitem__>, 'series_max': <function EquationPart.series_max>, 'series_min': <function EquationPart.series_min>, 'sum': <function EquationPart.sum>, 'mean': <function EquationPart.mean>, 'timeseries': <property object>, 'shape': <property object>, 'dtype': <property object>, 'equal': <function EquationPart.equal>, 'not_equal': <function EquationPart.not_equal>, 'clip': <function EquationPart.clip>, 'astype': <function EquationPart.astype>, 'eval': <function EquationPart.eval>, 'latex': <function EquationPart.latex>, 'seek_refs': <function EquationPart.seek_refs>, 'get_shape': <function EquationPart.get_shape>, 'get_type': <function EquationPart.get_type>, 'find_parts_of_type': <function EquationPart.find_parts_of_type>, 'pt': <function EquationPart.pt>, 'pt_str': <function EquationPart.pt_str>, 'is_static': <function EquationPart.is_static>, '__dict__': <attribute '__dict__' of 'EquationPart' objects>, '__weakref__': <attribute '__weakref__' of 'EquationPart' objects>, '__annotations__': {}})#
- __ge__(obj)#
Returns symbolic ‘>=’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __getitem__(obj)#
Returns symbolic operation to index or slice with the provided index expression.
- Parameters:
obj (EquationPart | int | float | ndarray | slice)
- Return type:
- __gt__(obj)#
Returns symbolic ‘>’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __le__(obj)#
Returns symbolic ‘<=’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __lt__(obj)#
Returns symbolic ‘<’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __mod__(obj)#
Returns symbolic ‘%’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __module__ = 'reno.components'#
- __mul__(obj)#
Returns symbolic ‘*’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __or__(obj)#
Returns symbolic ‘|’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __pow__(obj)#
Returns symbolic ‘**’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __radd__(obj)#
Returns symbolic ‘+’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __rand__(obj)#
Returns symbolic ‘&’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __rmod__(obj)#
Returns symbolic ‘%’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __rmul__(obj)#
Returns symbolic ‘*’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __ror__(obj)#
Returns symbolic ‘|’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __rpow__(obj)#
Returns symbolic ‘**’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __rsub__(obj)#
Returns symbolic ‘-’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __rtruediv__(obj)#
Returns symbolic ‘/’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __sub__(obj)#
Returns symbolic ‘-’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __truediv__(obj)#
Returns symbolic ‘/’ operation with the passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- __weakref__#
list of weak references to the object
- astype(dtype)#
Returns a symbolic operation to convert the output of this equation to the specified type.
- Parameters:
dtype (type)
- Return type:
- clip(min, max)#
Returns a symbolic operation for enforcing the output is between the passed min and max.
- Parameters:
min (EquationPart | int | float | ndarray)
max (EquationPart | int | float | ndarray)
- Return type:
- property dtype: type#
The type of each underlying value.
- equal(obj)#
Returns a symbolic operation for checking equality with passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- eval(t=0, save=False, force=False, **kwargs)#
Execute the compute graph for this equation, this needs to be implemented in every subclass.
Note that throughout a compute tree, this should effectively recurse through
.eval()calls to all subparts as well.- Parameters:
t (int) – Timestep along simulation at which to evaluate.
save (bool) – Whether to store/track/cache the output in a tracked matrix. This is really only applicable to ``TrackedReference``s, but given recursive nature of this function, needs to always be passed down through all subsequent calls.
force (bool) – Whether to ignore a previously cached value and compute regardless.
kwargs (dict) – Any additional arguments to pass through evaluation tree.
- Return type:
int | float | ndarray
- find_parts_of_type(search_type, already_checked=None)#
Recursively search for all EquationParts in the tree of the specified type.
- Parameters:
search_type (type) – The type of component/equation part to search for, e.g.
reno.components.ExtendedOperation.already_checked (list[EquationPart]) – Used to avoid recursing into already checked visited equation parts.
- Return type:
list[EquationPart]
- get_shape()#
Get the size of the additional “data” dimension.
Prefer using
shapeproperty over directly calling this function.Override this in any subclass to control how shape is calculated.
For now this is returning an integer because we only allow a single additional dimension. Note that this shape _does not_ incoporate time or batch dimensions, only the “data” dimension if applicable. This should be overridden by subclasses, e.g. operations which would change the shape.
- Return type:
int
- get_type()#
Get the type of the target output of this equation expression.
Prefer using
dtypeproperty over directly calling this function.Override this in any subclass to control how the type gets determined.
A
Nonereturn means that the type doesn’t matter or shouldn’t influence or override anything upstream.Similar to shape, this gets computed recursively, used to automatically determine if the value needs to be initialized with a certain numpy type.
- Return type:
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.- Return type:
bool
- latex(**kwargs)#
Construct a string representation of this portion of the equation for use in a latex display. Should probably be overriden in most subclasses, and often needs to be called recursively on sub_equation_parts.
- Parameters:
kwargs (dict)
- Return type:
str
- mean(axis=0)#
Returns a symbolic operation to find the series-wise mean of the array.
- Parameters:
axis (int)
- Return type:
- not_equal(obj)#
Returns a symbolic operation for checking inequality with passed object.
- Parameters:
obj (EquationPart | int | float | ndarray)
- Return type:
- pt(**refs)#
Get a pytensor graph representing this piece of an equation.
- Parameters:
refs (dict[str, TensorVariable])
- Return type:
TensorVariable
- pt_str(**refs)#
Construct a string containing relevant pytensor code for this piece of the equation. This is useful for “compiling” into pymc code.
- Parameters:
refs (dict[str, str])
- Return type:
str
- seek_refs(include_ref_types=False)#
Recursively find a list of all References immediately underneath this part.
Either provides a list of references that appear underneath these equations or a dictionary with the “roles” or types that those references play.
Note that this doesn’t infinitely recurse into TrackedReferences themselves, this is used to find the outermost references that need to resolve. (Avoiding circular refs)
- series_max()#
Returns a symbolic operation to find the series-wise maximum of the array.
- Return type:
- series_min()#
Returns a symbolic operation to find the series-wise minimum of the array.
- Return type:
- property shape: int#
The size of the data dimension, 1 by default.
- sum(axis=0)#
Returns a symbolic operation to find the series-wise sum of the array.
- Parameters:
axis (int)
- Return type: