State#

class braincore.State(value)#

The pointer to specify the dynamical data.

To implement a new subclass of State, you only need to inherent this class:

Example:

class MyState(State):
  pass

The typical examples of State subclass are:

  • ShortTermState: The short-term state, which is used to store the short-term data in the program.

  • LongTermState: The long-term state, which is used to store the long-term data in the program.

  • ParamState: The parameter state, which is used to store the parameters in the program.

  • RandomState: The random generator state, which is used to store the random key in the program.

Parameters:

value (Any) – PyTree. It can be anything as a pyTree.

property source_info: SourceInfo#

The source information of the state, can be useful to identify the source code where the definition of the state.

Returns:

The source information.

tree_flatten()[source]#

Flattens this variable.

Returns:

A pair where the first element is a list of leaf values and the second element is a treedef representing the structure of the flattened tree.

classmethod tree_unflatten(aux_data, flat_contents)[source]#

Reconstructs a variable from the aux_data and the leaves.

Parameters:
  • aux_data

  • flat_contents

Returns:

The variable.

property value: Any#

The data and its value.