feat(adr-0249): P2 affine relation compiler #67

Merged
core-labs merged 1 commit from feat/adr-0249-p2-relation-compiler into main 2026-07-18 19:31:37 +00:00
Owner

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.pycompile_affine_relation(input, scale, offset, curvature=1.0) compiles output = scale·input + offset (Tier-1: scale > 0, offset any real) into a quadratic-well ProblemHamiltonian, reusing the ratified compile_quadratic_well + HamiltonianCompileError contracts rather than forking machinery. A companion affine_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 + offset in 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:

  • The returned well is a bare projector: its metadata is {curvature, target_digest} only, carrying no answer and no relation coefficients. It literally cannot report the answer.
  • Ablation test: the relaxation start decodes to the input (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.
  • End-to-end recovery verified across multiply / add / subtract (offset<0) / divide (scale=1/divisor) / negative input — all decode exactly via projective readback.

Fail-closed + reproducibility

Typed HamiltonianCompileError refusals 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.py21/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.

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)` compiles `output = scale·input + offset` (Tier-1: scale > 0, offset any real) into a quadratic-well `ProblemHamiltonian`, reusing the ratified `compile_quadratic_well` + `HamiltonianCompileError` contracts rather than forking machinery. A companion `affine_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 + offset` in 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: - The returned well is a **bare projector**: its metadata is `{curvature, target_digest}` only, carrying no answer and no relation coefficients. It literally cannot report the answer. - **Ablation test**: the relaxation start decodes to the input (`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. - End-to-end recovery verified across multiply / add / subtract (`offset<0`) / divide (`scale=1/divisor`) / negative input — all decode exactly via projective readback. ## Fail-closed + reproducibility Typed `HamiltonianCompileError` refusals 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.
core-labs added 1 commit 2026-07-18 19:28:48 +00:00
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
core-labs merged commit 2575d0d937 into main 2026-07-18 19:31:37 +00:00
core-labs deleted branch feat/adr-0249-p2-relation-compiler 2026-07-18 19:31:40 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: core-labs/core#67
No description provided.