HashableDict#
- class brainstate.mixin.HashableDict(the_dict)[source]#
A dictionary that can be hashed by converting non-hashable values to strings.
This is used internally to make parameter dictionaries hashable so they can be used as part of cache keys or other contexts requiring hashability.
- Parameters:
the_dict (
dict) – The dictionary to make hashable.
Notes
Non-hashable values in the dictionary are automatically converted to their string representation.
Examples
>>> import brainstate >>> import jax.numpy as jnp >>> >>> # Regular dict with non-hashable values cannot be hashed >>> regular_dict = {"array": jnp.array([1, 2, 3]), "value": 42} >>> # hash(regular_dict) # This would raise TypeError >>> >>> # HashableDict can be hashed >>> hashable = brainstate.mixin.HashableDict(regular_dict) >>> key = hash(hashable) # This works! >>> >>> # Can be used in sets or as dict keys >>> cache = {hashable: "result"}