printing — console formatting helpers

Purpose

Pretty-print nested dicts, Package records, and numpy arrays as aligned, precision-controlled
console text. formatted_dict is the entry point; the _format_* helpers dispatch by value type.

Role in the system

  • Consumed lazily by save_dict in infra (from utils.printing import formatted_dict) when
    writing a timestamped summary .txt.
  • Used by target_finder (ee_guidance tower) to print EE-pose score dicts.
  • Stateless support library — no config or sim dependencies; pure string formatting.

Single source since 2026-06-22 — was duplicated in infra

infra used to carry its own inline copy of formatted_dict + the _format_* family (kept in sync by
hand). That copy was removed on 2026-06-22; infra now does from utils.printing import formatted_dict,
so this is the one definition (Package.__repr__ / SuperPackage route through here too). The
consolidation was driven by the AST clone-detector (validation/ast_duplication.py, which scored the two
_format_* families J=1.00) and was byte-identical on 9/10 inputs. The one intended behaviour change:
a non-square 2-D array (e.g. a 6×7 Jacobian) now prints its rows — infra’s old copy raised
RuntimeError('Tenser, said the tensor.'). (logs/logs_Jun22_26/CLAIMS.md C2–C3)

Inputs / Outputs

  • In: a dict (values may be scalars, numpy arrays, nested Mappings, or any object with a
    .log() method), plus title, precision, indent.
  • Out: a single aligned multi-line str (keys left-padded to a common width; floats rounded).

Key functions

  • formatted_dict — aligned, recursive dict pretty-printer (the public entry point) — utils/printing.py:8
  • snake_to_Titlesnake_case key → Title Case label (module-level lambda) — utils/printing.py:5
  • _format_array — formats a 0/1/2-D array by rank; column vectors flatten to a row, 2-D prints
    tab-indented rows — utils/printing.py:40
  • _format_package_value — value dispatch: array, nested Mapping, .log()-able package, or
    passthrough (this is what makes the printer recurse) — utils/printing.py:57

Pseudocode

formatted_dict(d, title, precision, indent):
    width = max key length + 1
    for k, v in d:
        s = _format_package_value(v, ...)   # array | nested dict | package.log() | passthrough
        if s is multiline: append "<k>:" then the block
        elif s is float:   append "<k>: <rounded>"
        else:              append "<k>: <s>"
    return joined string

infra · target_finder · data_classes · terminology