feat(adr-0249): P2 affine relation compiler #67
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/adr-0249-p2-relation-compiler"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Second phase of the reader→Hamiltonian compiler arc (P1 quantity kernel merged in #66). Compiles a single affine relation into a corridor constraint Hamiltonian — the first place the substrate performs real arithmetic and relaxation reads the answer back.
What it does
core/physics/relation_compiler.py—compile_affine_relation(input, scale, offset, curvature=1.0)compilesoutput = scale·input + offset(Tier-1: scale > 0, offset any real) into a quadratic-wellProblemHamiltonian, reusing the ratifiedcompile_quadratic_well+HamiltonianCompileErrorcontracts rather than forking machinery. A companionaffine_relaxation_start(input)gives the natural relaxation start (the known input's null point).Anti-hollow (spike §4.1) — the load-bearing property
The compiler never evaluates
scale·input + offsetin Python. It embeds the input as a null point (P1) and applies the relation's structure as versor operators — a dilator for the scale (α = −ln scale), a translator for the offset — so the substrate's geometric product performs the arithmetic. Three things enforce this:{curvature, target_digest}only, carrying no answer and no relation coefficients. It literally cannot report the answer.4), and only the relaxed steady state decodes to the answer (17), with byte-identical Hamiltonian either way — relaxation does the work, not the compile step.offset<0) / divide (scale=1/divisor) / negative input — all decode exactly via projective readback.Fail-closed + reproducibility
Typed
HamiltonianCompileErrorrefusals on non-positive scale (outside the positive-dilation Tier-1 envelope — negative multipliers are recorded, not silently handled) and non-finite coefficients. Golden-bytes canary pins the compiled matrix (spike §4.6 Tier 2). Serve-quarantined (A-04). This is the single-relation primitive; multi-step state-chaining is the P4 turn-program compiler.Tests
tests/test_adr_0249_relation_compiler.py— 21/21 green. Forward recovery (6 relation shapes), bare-projector metadata pin, ablation, start-decodes-to-input, non-positive-scale + non-finite refusals, golden bytes.Governance
Stacks on P1 (now on main). No self-Accept — ADR-0249 lands with acceptance evidence as the arc completes. P3–P5 follow.
[Verification]:
uv run python -m pytest tests/test_adr_0249_relation_compiler.py -q→ 21 passed;uv run core test --suite smoke -q→ 176 passed.Compiles output = scale*input + offset (Tier-1: scale > 0) into a quadratic-well constraint Hamiltonian, reusing the ratified compile_quadratic_well + HamiltonianCompileError contracts. Anti-hollow (spike §4.1): the compiler never evaluates scale*input+offset in Python — it embeds the input (P1) and applies the relation's structure as versor operators (dilator for scale, translator for offset), so the substrate's geometric product performs the arithmetic. The returned well is a bare projector carrying no answer and no coefficients (metadata = {curvature, target_digest} only); relaxation + projective readback recover the output. Verified end-to-end: multiply/add/subtract/divide/negative-input all decode exactly; ablation confirms the start decodes to the input and only the relaxed state to the answer. Fail-closed on non-positive scale (outside positive-dilation Tier-1) and non-finite coefficients. Golden-bytes canary pins the compiled matrix. Serve-quarantined (A-04). Single-relation primitive; state-chaining is P4. 21/21 pins green. [Verification]: uv run python -m pytest tests/test_adr_0249_relation_compiler.py -q