brainstate.graph moduel#
Most of these APIs are adapted from Flax (google/flax).
It enables the structure-preserving State retrieval and manipulatio in the brainstate.
Graph Node#
Base class for all graph nodes in the BrainState framework. |
Graph Operation#
Pop one or more State types from the graph node, removing them from the node. |
|
Return all graph nodes, optionally filtered and limited by hierarchy depth. |
|
Return all State objects from a graph node, optionally filtered. |
|
Return the treefy state mapping of a graph node, optionally filtered. |
|
Update the graph node in-place with the given state dict(s). |
|
Flatten a graph node into a (graph_def, state_mapping) pair. |
|
Unflatten a graph_def + state_mapping back into a node. |
|
Split a graph node into a GraphDef and one or more state NestedDicts. |
|
Reconstruct a node from its GraphDef and one or more state NestedDicts. |
|
Iterate over all leaf values in the graph node (non-node values). |
|
Iterate over all graph nodes within the given node. |
|
Create a deep copy of the given graph node. |
|
Return the GraphDef of the given graph node. |
Context Management#
Context managers for handling complex state updates during graph transformations. These utilities enable splitting and merging graph states in a thread-safe manner.
Context manager for splitting multiple graph nodes sharing a reference index. |
|
Context manager for merging multiple graph nodes sharing a reference index. |
Graph Conversion#
Utilities for converting between graph and tree representations, enabling flexible manipulation of nested module structures.
Convert a pytree that may contain graph nodes into a pure pytree of NodeStates. |
|
Convert a pytree of NodeStates back into graph nodes. |
|
A JAX pytree wrapper that carries both a GraphDef and one or more state mappings. |
Graph Definition Classes#
Core classes for representing graph structure, node definitions, and references. These classes provide the foundation for graph operations and state management.
Base class representing the static graph structure of a node. |
|
Graph structure of a node, containing all static information for reconstruction. |
|
A reference to an already-seen node in the graph (used for shared/circular refs). |
|
A mapping that uses object identity (id) as the hash key. |
|
Register a custom graph node type with the graph system. |