brainstate.util.unfreeze

Contents

brainstate.util.unfreeze#

brainstate.util.unfreeze(x)[source]#

Convert a FrozenDict to a regular dict.

Recursively converts FrozenDict instances to mutable dicts.

Parameters:

x (FrozenDict[TypeVar(K), TypeVar(V)] | dict[TypeVar(K), TypeVar(V)]) – A FrozenDict or dict to unfreeze.

Returns:

A mutable dictionary.

Return type:

dict[TypeVar(K), TypeVar(V)]

See also

freeze

Convert a mapping to a FrozenDict.

FrozenDict

The immutable dictionary class.

Examples

>>> from brainstate.util import FrozenDict, unfreeze

>>> fd = FrozenDict({'a': 1, 'b': {'c': 2}})
>>> d = unfreeze(fd)
>>> isinstance(d, dict)
True
>>> isinstance(d['b'], dict)  # Nested FrozenDicts are unfrozen
True
>>> d['a'] = 10  # Can modify the result