data_class_helpers — dataclass field factories + log serialisation
Purpose
Two tiny, stateless utilities for the sim records: field default factories (
default_flat_zero,
default_z,default_eye) that give each dataclass instance its own fresh numpy default, and the
internal log-serialisation walk (_as_log_dict→_field_names→_log_value) behindPackage.log().
Role in the system
- Consumed by data_classes: every numpy field on
State/Desired/Packageis declared with one of
thedefault_*factories so two instances never share a mutable default array. - The
_as_log_dictwalk is the serialiser invoked byPackage.log()(utils/infra.py:265) and by the
per-recordlog()methods (e.g.data_classes.py:128), turning a dataclass into a flat, log-safe dict
for the run → log pipeline that the orchestrator / data_analyzer read back.
Inputs / Outputs
- In:
default_*take a size (or nothing) and return adataclasses.field(default_factory=…); the
log walk takes any dataclass instance plus arbitrary nested values. - Out: field descriptors for class bodies; a
{field_name: log_safe_value}dict where enums become
.value, numpy scalars become Python scalars, arrays are copied, and dict/list/tuple recurse.
Key functions
default_flat_zero— field defaulting to a fresh flat zero vector of lengthsize—utils/data_class_helpers.py:7default_z— field defaulting to a fresh unit +z axis[0,0,1]—utils/data_class_helpers.py:12default_eye— field defaulting to a freshsize×sizeidentity —utils/data_class_helpers.py:17_log_value— coerce one value to a log-safe form (enum/np-scalar/array-copy + container recursion) —utils/data_class_helpers.py:34