reno.components.Metric#

class reno.components.Metric(eq=None, label=None)#

Bases: Reference

Metrics run in a separate after-simulation analysis. Generally intended to be a series aggregate type equation (e.g. using series_min/series_max/sum on slices of values across time from references computed during the simulation etc.

Methods

__init__([eq, label])

clip(min, max)

debug_equation(t[, sample])

equal(obj)

equation(**kwargs)

Get the representation of the full equation for the metric as a latex string.

eval([t, save, force])

Execute the compute graph for this equation, this needs to be implemented in every subclass.

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.

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.

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.

qual_name([dot])

Get a string with both the model and the reference name if this model is a submodel of something else.

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

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.)

model

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

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__ = {}#
__module__ = 'reno.components'#
__repr__()#

Return repr(self).

__setattr__(name, value)#

Implement setattr(self, name, value).

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

Get the representation of the full equation for the metric as a latex string.

Return type:

str

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.

from_dict(data, refs)#

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

Parameters:
model#

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

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

qual_name(dot=False)#

Get a string with both the model and the reference name if this model is a submodel of something else.

This is primarily used for helping distinguish things in a multimodel setup.

Parameters:

dot (bool)

to_dict()#

Serialize class into a dictionary for saving to file.

Return type:

dict