infra — project namespaces, paths & NPZ I/O
Purpose
The bottom layer of the support library: flexible attribute namespaces (
Package/
RecursiveNamespace/SuperPackage), the canonical path constants (PROJECT_ROOT,YAML_DICT,
today’sLOGS_DIR), and the lean save/load helpers for NPZ + summary dicts. Almost everything
imports from here.
Role in the system
- Namespaces.
Packageis the project’s mutable record type — imported by breve_controller,
com_controller, guidance_classes,analysis/runner.pyandanalysis/logger.py.Package.pack(...)
is the sanctioned “pack these locals” idiom (.claude/rules/PYTHON.md). - Config namespaces.
RecursiveNamespace.from_mappingturns parsed YAML into dotted-access config;
parameter_loader buildsparameters.yamland the asset YAMLs on top of it. - Paths.
PROJECT_ROOT/MODELS_DIR/YAML_DICT/ datedLOGS_DIRare the single source of
filesystem truth consumed acrossutils/,analysis/andvalidation/. - NPZ I/O.
save_npz/load_npz/last_npzare the lean numbered-file store used by ad-hoc
studies; the run pipeline’s structured logs go throughanalysis/logger.py, not here. - Pretty-printing:
infrare-exports printing’sformatted_dict(from utils.printing import formatted_dict) — the inline copy +_format_*family was removed 2026-06-22, so printing is now
the single source (Package.__repr__/SuperPackageroute through it).
Inputs / Outputs
- In: YAML paths, summary dicts, keyword arrays, file stems + an optional
cfg/model_key. - Out:
RecursiveNamespace/Packageconfig objects, numbered.npz/.txtpaths underLOGS_DIR,
and aligned text snapshots.
Key functions / classes
Package— mutable attribute namespace with deepcopy, recursivemerge/update_from, dictlog—utils/infra.py:262RecursiveNamespace.from_mapping— nested-dict → dotted-access config namespace —utils/infra.py:393SuperPackage—Packagethat auto-converts nested mappings on construction —utils/infra.py:430load_spec— YAML file (optionally merged onto a base dict) →RecursiveNamespace—utils/infra.py:17save_npz/load_npz/last_npz— numbered<stem>_<model_key>_N.npzsave/load/latest —utils/infra.py:185/:202/:169next_filename/find_last_idx— next free / last-used numeric suffix in a folder —utils/infra.py:78/:98formatted_dict— aligned, precision-controlled pretty-print of nested dicts/arrays — imported from printing (not defined here since 2026-06-22)PROJECT_ROOT,YAML_DICT,LOGS_DIR— repo root, domain-YAML map, today’s dated log dir —utils/infra.py:11/:14/:47
Pseudocode (numbered-file store)
save_npz(stem, **arrays) # stem += "_<model_key>"; fname = next_filename(stem, folder)
# np.savez(fname, **arrays) -> <stem>_N.npz under LOGS_DIR/npz
load_npz(stem, query=[...]) # fname = last_npz(stem) # highest N matching <stem>_*.npz
# unwrap object arrays; return the queried entries
Related
parameter_loader · printing · data_classes · data_class_helpers · breve_controller · terminology