ValueHashedFields#
- class t3toolbox.backend.common.ValueHashedFields#
Mixin giving a frozen dataclass VALUE-based
__hash__/__eq__over all its fields, with numpy arrays compared by CONTENT rather than by identity.The generalization of
ValueHashedMasks(which value-hashes one designated.datatuple of masks) to a dataclass whose parameters are its fields. Both exist for the same reason: the object rides as jaxaux_data, so its__hash__/__eq__are part of the jit compilation cache key, and identity semantics make a rebuilt-but-identical object a NEW key -> jit RECOMPILES. A geometry rebuilt at each rank-continuation level, or a sampling kind rebuilt at each outer step, must be the SAME cache key when its parameters are the same.Use it instead of the dataclass
eq=Truedefault whenever a field may hold a numpy array (eq=Truewould raise “truth value of an array is ambiguous”), and instead ofeq=Falsewhenever the object is a jit aux (identity semantics recompile). Subclasses must be@dataclass(frozen=True, eq=False).The alternative this replaces is a hand-maintained parallel
identitytuple restating the fields – correct while someone keeps it in sync, silently identity-based for a user-built object that omits it. Here the fields ARE the key, so there is nothing to keep in sync.