GraphDef#
- class brainstate.graph.GraphDef(root, node_specs)#
The static structure of an object graph.
A
GraphDefis a rootEdgeplus a flat tuple of graph-node specs ordered ascending by index. It is hashable (the hash is computed once and cached) and registered as a JAX static pytree, so it can serve as a transform cache key (e.g. forjit).- Parameters:
root (Edge) – The edge for the root object (a
NodeEdge,PytreeEdge, etc.).node_specs (tuple) – Graph-node specs, ascending by index.
Examples
>>> import brainstate >>> model = brainstate.nn.Linear(2, 3) >>> graphdef, _ = brainstate.graph.flatten(model) >>> graphdef.type is brainstate.nn.Linear True