brainstate.util module#
Dict Operation#
Flatten a nested mapping into a flat mapping with tuple or string keys. |
|
Unflatten a mapping by converting tuple/string keys back to nested structure. |
|
A pytree-like nested mapping structure for organizing hierarchical data. |
|
A pytree-like structure that contains a |
Functions for flattening, merging, and freezing nested dictionaries.
Flatten a nested dictionary. |
|
Unflatten a dictionary with separated keys. |
|
Merge multiple dictionaries. |
|
Convert a mapping to a FrozenDict. |
|
Convert a FrozenDict to a regular dict. |
|
Check whether a class was created by the brainstate |
Filter Operation#
to_predicate converts a filter specification into a predicate; the remaining
classes are composable filter primitives for selecting states and tree leaves.
Convert a Filter to a predicate function. |
A filter class that combines multiple filters using a logical AND operation. |
|
Combine multiple filters using logical OR operation. |
|
A filter class that negates the result of another filter. |
|
Filter that matches no objects. |
|
Filter that matches all objects. |
|
Filter objects based on their type. |
|
Filter objects that have a specific tag attribute. |
|
Filter objects based on whether their path contains a specific key. |
Pretty Representation#
Configuration for pretty representation of objects. |
|
Configuration for pretty representation of attributes. |
|
Interface for pretty representation of objects. |
|
Pretty representation of a mapping. |
|
Mapping mixin for pretty representation. |
|
Base dictionary class with pretty representation and tree utilities. |
|
A list subclass with pretty representation and JAX pytree compatibility. |
|
Base class for generating pretty representations of tree-like structures. |
Create a pretty string representation. |
|
Generate a pretty representation of an object while avoiding duplicate representations. |
Struct Operation#
Create a dataclass that works with JAX transformations. |
|
Create a dataclass field with JAX pytree metadata. |
|
Base class for creating JAX-compatible pytree nodes. |
|
An immutable dictionary that works as a JAX pytree. |
Other Operations#
Clear on-device memory buffers and optionally compilation cache. |
|
Create a partial function to check if input is NOT an instance of given classes. |
|
Create a partial function to check if input IS an instance of given classes. |
|
Enhanced dictionary for managing collections in BrainState. |
|
Dictionary with dot notation access to nested keys. |
|
Snapshot of the active JAX trace used to detect cross-trace State leakage. |
|
A thread-safe LRU cache with bounded size. |
Get a unique name for the given object type. |
|
Calculate the number of epochs for simulation based on a total and a fraction. |