DotDict#

class brainstate.util.DotDict(*args, **kwargs)#

Dictionary with dot notation access to nested keys.

DotDict allows accessing dictionary items using attribute syntax, making code more readable when dealing with nested configurations.

Examples

>>> config = DotDict({'model': {'layers': 3, 'units': 64}})
>>> config.model.layers
3
>>> config.model.units = 128
>>> config['model']['units']
128
All dictionary keys become accessible as attributes unless they conflict
with built-in methods.
copy()[source]#

Create a shallow copy.

Return type:

DotDict

deepcopy()[source]#

Create a deep copy.

Return type:

DotDict

classmethod from_dict(d)[source]#

Create DotDict from standard dict.

Parameters:

d (Dict[str, Any]) – Standard Python dictionary.

Returns:

A new DotDict instance.

Return type:

DotDict

get(key, default=None)[source]#

Get item with default value.

Return type:

Any

setdefault(key, default=None)[source]#

Set default value if key doesn’t exist.

Return type:

Any

to_dict()[source]#

Convert to standard dict recursively.

Returns:

A standard Python dict with nested DotDicts also converted.

Return type:

Dict[str, Any]

tree_flatten()[source]#

Flatten for JAX pytree.

Return type:

Tuple[Tuple[Any, ...], Tuple[str, ...]]

classmethod tree_unflatten(keys, values)[source]#

Unflatten from JAX pytree.

Return type:

DotDict

update(*args, **kwargs)[source]#

Update with recursive merge for nested dicts.

Parameters:
  • *args – Dict-like objects to merge.

  • **kwargs – Key-value pairs to merge.

Return type:

None