diff --git a/certificates/disjoint-tensor-compression.json b/certificates/disjoint-tensor-compression.json index a24b0c9af4..a6ee28d6a1 100644 --- a/certificates/disjoint-tensor-compression.json +++ b/certificates/disjoint-tensor-compression.json @@ -341,7 +341,7 @@ "scripts/audit_disjoint_tensor.py": "477db540e972b82751fac6a3a6d6e38fb4141e967261b1f9c260e2c686479a78", "scripts/binary_phase_frames.py": "4148cfa313cf050ed25296e8db36d35871520b8318fd086c7d1facf0c6af67d7", "scripts/complex_compression.py": "9b6f758a5985ba5d9fdd726fe6556b3d3b4bd9d98aaf8ba06a7bb58093c4c504", - "scripts/exclusion_circuit.py": "f9fbcd6e85e442cbd0926ac0887414e20735b2dc923d2d5822c803ceb46726d3", + "scripts/exclusion_circuit.py": "f066ce9f88f0d8c0b82d7cb3a8d267249e12386e9d1ab65820a3bed54ff0ff78", "scripts/experiments/disjoint_tensor.py": "085600fc922ae167b5981505e1a5caba4d1c1df15482f61d83d2c086fa89eac1" }, "status": "IMPROVED FINITE COMPLEX NETWORK; NO NEW MULTIPLICATION KAPPA", diff --git a/certificates/dyadic-central-factor.json b/certificates/dyadic-central-factor.json index 5bd4e583cd..f6410a312e 100644 --- a/certificates/dyadic-central-factor.json +++ b/certificates/dyadic-central-factor.json @@ -101,7 +101,7 @@ "scripts/audit_complex_centers.py": "166b18f560cd0d520d23fa29ee8147e0ea056358c4268a466ec458195a97a960", "scripts/binary_phase_frames.py": "4148cfa313cf050ed25296e8db36d35871520b8318fd086c7d1facf0c6af67d7", "scripts/complex_compression.py": "9b6f758a5985ba5d9fdd726fe6556b3d3b4bd9d98aaf8ba06a7bb58093c4c504", - "scripts/exclusion_circuit.py": "f9fbcd6e85e442cbd0926ac0887414e20735b2dc923d2d5822c803ceb46726d3", + "scripts/exclusion_circuit.py": "f066ce9f88f0d8c0b82d7cb3a8d267249e12386e9d1ab65820a3bed54ff0ff78", "scripts/experiments/complex_centers.py": "3744396587d729253d80980f6310b56e7bf0ea21b165bd178d0d6d4c49faf2e2", "scripts/experiments/disjoint_tensor.py": "085600fc922ae167b5981505e1a5caba4d1c1df15482f61d83d2c086fa89eac1", "scripts/general_network_guard.py": "790a2064449afdbffd6dbd4adbcf4a28eaf41931ce7134e4a4e8766f3764270c" diff --git a/certificates/positive-side-core.json b/certificates/positive-side-core.json index 843dd248eb..a526a6499e 100644 --- a/certificates/positive-side-core.json +++ b/certificates/positive-side-core.json @@ -23101,7 +23101,7 @@ "source_sha256": { "docs/research/positive-side-core.md": "fab9ff0ed8de56cb9c4c1587b65f956f706ab8f3b8afcb9212366218e227f49d", "scripts/audit_positive_side.py": "b021aad944d8a6c023e57b1b48937854803bbb370240c93e0fe359d831c838c9", - "scripts/exclusion_circuit.py": "f9fbcd6e85e442cbd0926ac0887414e20735b2dc923d2d5822c803ceb46726d3", + "scripts/exclusion_circuit.py": "f066ce9f88f0d8c0b82d7cb3a8d267249e12386e9d1ab65820a3bed54ff0ff78", "scripts/experiments/positive_side_core.py": "0d453ab7e869d2cf6a43d6865de82583edb390d3c75038271f0fc09e0f3828ba", "scripts/experiments/rank_product_core.py": "7a91c1188c5d42e864a5d2e42397b09c435b526ae4f4210c44bf615de488708e", "scripts/experiments/shared_core.py": "d3c59b61229956cb54ae1ef9145ed213abdf1ae743929de145a77c43656f01a8", diff --git a/certificates/ternary-side.json b/certificates/ternary-side.json index b2c1b793e7..6068da19d0 100644 --- a/certificates/ternary-side.json +++ b/certificates/ternary-side.json @@ -1563,7 +1563,7 @@ "notes/ternary-five-subsets.tex": "f8553a7ad7da9fcd85def67360f7c070ec6c15911c3310fca360d821e1ed1ccd", "scripts/audit_ternary_side.py": "5e86566eee32031e1829d26ea17a7372e4802e2f7d76a2caa3ae16de3ab072c1", "scripts/certify.py": "2348d95008276c5d5764f7e028c3918e484582cd589bd4d9b82919161745e53e", - "scripts/exclusion_circuit.py": "f9fbcd6e85e442cbd0926ac0887414e20735b2dc923d2d5822c803ceb46726d3", + "scripts/exclusion_circuit.py": "f066ce9f88f0d8c0b82d7cb3a8d267249e12386e9d1ab65820a3bed54ff0ff78", "scripts/experiments/disjoint_tensor.py": "085600fc922ae167b5981505e1a5caba4d1c1df15482f61d83d2c086fa89eac1", "scripts/experiments/prime_core.py": "080a89a2c91505b509068698542843c9d7af3cdec01b5c88972107dc9c688c62", "scripts/experiments/rank_product_core.py": "7a91c1188c5d42e864a5d2e42397b09c435b526ae4f4210c44bf615de488708e", diff --git a/research/exclusion-embedding-compile/NOTICE.md b/research/exclusion-embedding-compile/NOTICE.md new file mode 100644 index 0000000000..1f201f43fe --- /dev/null +++ b/research/exclusion-embedding-compile/NOTICE.md @@ -0,0 +1,13 @@ +# Notice — exclusion embedding compile + +Douglas R. Colkitt authored the ExclusionCircuit / SharedPoint / positive-side +screens, the reversible embedding compiler, and the original +`verify_embedding` nesting checks consumed by this tooling package. + +Merged [CrocSwap/integer-mult-bounds#2001](https://github.com/CrocSwap/integer-mult-bounds/pull/2001) +already replaced the reverse-frame expected-support genexpr with a closed-form +mask. This package accelerates the residual `compile` / nesting path inside +`verify_embedding` with identical compile maps and embedding receipts, and +updates source pins only. + +Prepared by Wentao Li with substantial AI assistance, under Apache-2.0. diff --git a/research/exclusion-embedding-compile/README.md b/research/exclusion-embedding-compile/README.md new file mode 100644 index 0000000000..7a461c2921 --- /dev/null +++ b/research/exclusion-embedding-compile/README.md @@ -0,0 +1,123 @@ +# Faster ExclusionCircuit.verify_embedding compile with identical receipts + +**Tooling improvement; no new kappa.** At base +`0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2`, merged +[CrocSwap/integer-mult-bounds#2001](https://github.com/CrocSwap/integer-mult-bounds/pull/2001) +replaced the reverse-frame expected-support genexpr inside +`ExclusionCircuit.verify_embedding` with a closed-form mask. Profiling on the +historical full-size circuit (`n=45`, 12556 reversible roles) shows the residual +wall time is dominated by `compile`'s `edge[node,pos]` tuple-key maps and by +per-gate `set(ins+outs)` nesting loops. + +This change keeps every compile map field and every `verify_embedding` receipt +identical while: + +1. walking `sorted(self.active)` once and wiring slots through parallel + `edge0` / `edge1` maps; +2. updating forward/reverse frames with pivot-first `ins[1:]` / `outs[1:]` + iteration (historically `set(ins) & set(outs) == {pivot}`); +3. propagating descendants on a dense array instead of a per-active dict. + +`ExclusionCircuit.verify`, `circuit_sha256`, and both closed-form leave-two / +reverse masks are unchanged. Only the source pin for +`scripts/exclusion_circuit.py` changes inside the four certificates that bind +that file. + +## Reproduce + +Python **3.12**, standard library only, from the repository root: + +```sh +python3.12 -I -B research/exclusion-embedding-compile/verify.py +python3.12 -I -O -B research/exclusion-embedding-compile/verify.py +python3.12 -B scripts/research_package.py --package research/exclusion-embedding-compile +python3.12 -I -B research/exclusion-embedding-compile/benchmark.py --rounds 5 +``` + +Expected: + +```text +PASS_EXCLUSION_EMBEDDING_COMPILE cases=8 certs=4 no_new_kappa +PASS_REGISTERED_RESEARCH_PACKAGE research/exclusion-embedding-compile outcome=completed +PASS_IDENTICAL_EXCLUSION_EMBEDDING_COMPILE_RECEIPTS +``` + +Default verify is read-only. Full `make verify`, selected cold replay, Lean, and +multiplication-theorem obligations were not rerun for this isolated +historical-checker change. + +## Result + +On Linux / CPython 3.12.3 (Linux-6.12.94+-x86_64-with-glibc2.39), five +alternating fresh-process pairs timing only +`ExclusionCircuit(45).verify_embedding` (construction excluded) gave median wall +time **0.056 → 0.033 seconds (1.71×)**. +Timing is host-descriptive and is not a correctness gate; all samples and +environment pins are in [RESULT.json](RESULT.json). Every compile map and +embedding receipt matches the baseline checker fieldwise. + +## Equivalence + +- **Compile:** same `roles`, `gates`, `sources`, and `outputs`. Parallel + `edge0[node]` / `edge1[node]` store the same slots as the historical + `edge[node,0]` / `edge[node,1]` tuple keys. Binary-gate uniqueness + `ins[0] != ins[1]` plus fresh `outs[1:]` ids preserve + `set(ins) & set(outs) == {pivot}`. +- **Nesting:** for every historical gate, `set(ins+outs)` equals + `{pivot} ∪ set(ins[1:]) ∪ set(outs[1:])` with those three parts pairwise + disjoint except the shared pivot, so pivot-first updates match the set loop. +- **Descendants:** inactive nodes stay at bit-zero on the dense array and are + skipped; active reverse propagation matches `sorted(self.active, reverse=True)`. + +A compile-map mutant that swaps two output slots is rejected by both baseline +and optimized `verify_embedding` under non-`-O` runs. Temp-copy digest +corruption of production bytes is rejected by the package digest gate. + +## Open next questions + +1. **Question:** Should `research/bit-compression-provenance` and other packages + that pin live `scripts/exclusion_circuit.py` bytes refresh those SHA-256 + entries after this equivalence-preserving rewrite? + **Why it matters:** Those provenance packages bind working-tree bytes; leaving + the old pin keeps this tooling PR focused. + **First step:** Dedicated provenance follow-up that only rewrites those + `SOURCES` / `SOURCE-PINS` entries after confirming embedding receipts stay + identical. + **Blocked by:** Pin repair outside the four binding certificates is outside + this tooling change. + +2. **Question:** Is `ExclusionCircuit.compile` alone worth a soft CI regression + timer, or should `RESULT.json` stay descriptive only? + **Why it matters:** Host-descriptive medians already gate nothing; a soft + timer could catch accidental compile regressions without claiming a kappa + effect. + **First step:** Propose a non-blocking timer on `ExclusionCircuit(45).compile` + in the existing research-packages workflow after this PR lands. + **Blocked by:** Maintainer CI policy; out of this session’s stop rule. + +## Overlap and credit + +Closest priors (different objects or delivery): +[CrocSwap/integer-mult-bounds#756](https://github.com/CrocSwap/integer-mult-bounds/pull/756), +[CrocSwap/integer-mult-bounds#1793](https://github.com/CrocSwap/integer-mult-bounds/pull/1793), +[CrocSwap/integer-mult-bounds#1861](https://github.com/CrocSwap/integer-mult-bounds/pull/1861) +(open; primary pin `binary_phase_frames.py`), +[CrocSwap/integer-mult-bounds#1922](https://github.com/CrocSwap/integer-mult-bounds/pull/1922), +[CrocSwap/integer-mult-bounds#1984](https://github.com/CrocSwap/integer-mult-bounds/pull/1984), +[CrocSwap/integer-mult-bounds#1994](https://github.com/CrocSwap/integer-mult-bounds/pull/1994), +[CrocSwap/integer-mult-bounds#2001](https://github.com/CrocSwap/integer-mult-bounds/pull/2001) +(leave-two / reverse masks; this package answers the residual compile/nesting +object after those masks), +[CrocSwap/integer-mult-bounds#2100](https://github.com/CrocSwap/integer-mult-bounds/pull/2100) +(open; same `ternary-side.json` file, different pin key `ternary_side.py`), +[CrocSwap/integer-mult-bounds#2117](https://github.com/CrocSwap/integer-mult-bounds/pull/2117) +(open; same shared JSON files, different pin key `disjoint_tensor.py`), +[CrocSwap/integer-mult-bounds#2150](https://github.com/CrocSwap/integer-mult-bounds/pull/2150) +(open; mixed-point `Circuit.verify`; different file). No competing open PR on +`ExclusionCircuit.compile` / residual `verify_embedding` nesting at refresh. + +Douglas R. Colkitt authored the exclusion / shared-point / positive-side checkers. +Prepared by Wentao Li +([VictorLiwentao](https://github.com/VictorLiwentao), +[@Is__Victor](https://x.com/Is__Victor)) with substantial AI assistance, under +Apache-2.0. diff --git a/research/exclusion-embedding-compile/RESULT.json b/research/exclusion-embedding-compile/RESULT.json new file mode 100644 index 0000000000..23b4500955 --- /dev/null +++ b/research/exclusion-embedding-compile/RESULT.json @@ -0,0 +1,50 @@ +{ + "environment": { + "executable": "/usr/bin/python3.12", + "platform": "Linux-6.12.94+-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]" + }, + "fixture": "ExclusionCircuit(45).verify_embedding only (construction excluded)", + "median_baseline_seconds": 0.055854782999972485, + "median_optimized_seconds": 0.032741775999966194, + "median_ratio": 1.7059179379893796, + "no_new_kappa": true, + "rounds": 5, + "samples": [ + { + "baseline_seconds": 0.06154403099992578, + "optimized_seconds": 0.0328517960000454, + "ratio": 1.8733840609457313, + "round": 0 + }, + { + "baseline_seconds": 0.04964154799995413, + "optimized_seconds": 0.032741775999966194, + "ratio": 1.5161531860704618, + "round": 1 + }, + { + "baseline_seconds": 0.059639259000050515, + "optimized_seconds": 0.032688727000049767, + "ratio": 1.8244595147421836, + "round": 2 + }, + { + "baseline_seconds": 0.04883048300007431, + "optimized_seconds": 0.03363378599999578, + "ratio": 1.4518283193001358, + "round": 3 + }, + { + "baseline_seconds": 0.055854782999972485, + "optimized_seconds": 0.032030366999947546, + "ratio": 1.743807150260375, + "round": 4 + } + ], + "source_sha256": { + "baseline": "f9fbcd6e85e442cbd0926ac0887414e20735b2dc923d2d5822c803ceb46726d3", + "production": "f066ce9f88f0d8c0b82d7cb3a8d267249e12386e9d1ab65820a3bed54ff0ff78" + }, + "status": "PASS_IDENTICAL_EXCLUSION_EMBEDDING_COMPILE_RECEIPTS" +} diff --git a/research/exclusion-embedding-compile/SOURCES.json b/research/exclusion-embedding-compile/SOURCES.json new file mode 100644 index 0000000000..ba9ed4a456 --- /dev/null +++ b/research/exclusion-embedding-compile/SOURCES.json @@ -0,0 +1,66 @@ +{ + "schema_version": 1, + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "files": [ + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "e8870e5917057d59b730eb14721a778639eca050", + "sha256": "d46eb6d5b3e279428753d770653663fbdf1063e55c255ea073d768f344927ef7" + }, + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "scripts/exclusion_circuit.py", + "usage": "provenance", + "git_blob": "b0e2f3e03d7de791ca936dfd92cee2134c7dd4f5", + "sha256": "f9fbcd6e85e442cbd0926ac0887414e20735b2dc923d2d5822c803ceb46726d3" + }, + { + "path": "certificates/positive-side-core.json", + "usage": "provenance", + "git_blob": "843dd248eb3f3dc02bb0508130e2ab824ce9ceb6", + "sha256": "35b922c868fac01ed67229196748a956542169934b0ae2093da706eddbf6d264" + }, + { + "path": "certificates/dyadic-central-factor.json", + "usage": "provenance", + "git_blob": "5bd4e583cd61b0e5183d74799e886afb57690960", + "sha256": "3f46000e645c338a583e0f2ab669a7c681980743d03335548eeb838072f1d458" + }, + { + "path": "certificates/ternary-side.json", + "usage": "provenance", + "git_blob": "b2c1b793e7cb7e4d358b66bfd021d01c85371e19", + "sha256": "2ec667c52babb2a25820e8305538ef16399ab2ea12441d2e8130cc8e3fa13614" + }, + { + "path": "certificates/disjoint-tensor-compression.json", + "usage": "provenance", + "git_blob": "a24b0c9af473414fa87efa5a8d2b643d93e6fd01", + "sha256": "899950c322069ebf5a561a321c987906f8c11a592ca229143840901e4e370dd6" + }, + { + "path": "tests/test_exclusion_embedding_masks.py", + "usage": "provenance", + "git_blob": "59e09effd881e7dac408bd389c8d5b2f9790ab3d", + "sha256": "22404fd3e1ca4a616b3f1fe72dd97488514c26fcfb4890bab2c45e6ecf612482" + }, + { + "path": "tests/test_positive_side_core.py", + "usage": "provenance", + "git_blob": "643a3020b9b6dbdf2230be7b9bb6c5a3ce2e637d", + "sha256": "46bd4173c6a3fd9295fc2682bf7f572161e95abc6c61e0859bb2f8eee7fb6319" + }, + { + "path": "research/exclusion-embedding-masks/README.md", + "usage": "provenance", + "git_blob": "d076387569144e5c66e5342b646dd20b136076b4", + "sha256": "313dbae5b0f0e918e9117f16d87807e02bbb027b60591ca4841ff34b01b384e5" + } + ] +} diff --git a/research/exclusion-embedding-compile/TASK.json b/research/exclusion-embedding-compile/TASK.json new file mode 100644 index 0000000000..7652d46f30 --- /dev/null +++ b/research/exclusion-embedding-compile/TASK.json @@ -0,0 +1,70 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "priority_revision": 4, + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "chooser_seed": "a85f20f2e9b661a9314bb2e14f07eb84", + "original_card": { + "id": "replay-runtime", + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the selected reproduction command and choose a single replay stage for profiling.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ] + }, + "scope_status": "refined", + "actual_scope": "Can scripts/exclusion_circuit.py:ExclusionCircuit.compile / verify_embedding accelerate the post-#2001 residual (parallel edge0/edge1 slot maps; pivot-first nesting without set(ins+outs); dense descendant array) so compile maps and verify_embedding receipts stay fieldwise identical on the historical n=45 circuit, without changing ExclusionCircuit.verify or the closed-form reverse/leave-two masks?", + "scope_change_reason": "The catalogue card asks for one measured replay bottleneck with before/after wall time and retained checks. Expertise override selected verifier-engineering (seed a85f20f2e9b661a9314bb2e14f07eb84) after leave-alone overlap ruled out mixed-point Circuit.verify (#2150), DisjointTensor.frame_data (#2117), ternary frames (#2100), SharedPoint init (#2054), and joint-frames (#1922). Profiling named ExclusionCircuit(45).verify_embedding's compile + nesting residual after the merged #2001 reverse-frame masks.", + "bottleneck_link": "Side result on review throughput: ExclusionCircuit embedding checks feed positive-side, dyadic-central, ternary-side and disjoint-tensor certificates inside verify-certificates. A faster identical embedding path does not change kappa or the binding complex supplier.", + "budget_minutes": 60, + "stop_rule": "Ship an equivalence-preserving compile/verify_embedding residual rewrite with frozen baseline, identical compile maps and embedding receipts, registered replay and a measured before/after median at or above the ~1.5× tooling bar. Do not reopen leave-alone PRs, invent kappa, or run the selected cold frontier replay.", + "outcome": "completed", + "evidence": "PASS_EXCLUSION_EMBEDDING_COMPILE via research/exclusion-embedding-compile/verify.py (also under -O); PASS_IDENTICAL_EXCLUSION_EMBEDDING_COMPILE_RECEIPTS via benchmark.py; four certificates differ from base only in the scripts/exclusion_circuit.py source pin.", + "author": "Wentao Li", + "github": "VictorLiwentao", + "email": "wentaol4@illinois.edu", + "ai_assistance": "Substantial AI assistance for orientation, overlap search, profiling, implementation, packaging, benchmarking and writing. Not independent human peer review.", + "open_questions": [ + { + "question": "Should research/bit-compression-provenance and other packages that pin live scripts/exclusion_circuit.py bytes refresh those SHA-256 entries after this equivalence-preserving rewrite?", + "why_it_matters": "Those provenance packages bind working-tree bytes; leaving the old pin keeps this tooling PR focused.", + "first_step": "Open a dedicated provenance follow-up that only rewrites the exclusion_circuit.py entry in those SOURCES/SOURCE-PINS files after confirming embedding receipts stay identical.", + "blocked_by": "Pin repair outside the four binding certificates is outside this tooling change." + }, + { + "question": "Is ExclusionCircuit.compile alone worth a soft CI regression timer, or should RESULT.json stay descriptive only?", + "why_it_matters": "Host-descriptive medians already gate nothing; a soft timer could catch accidental compile regressions without claiming a kappa effect.", + "first_step": "Propose a non-blocking timer on ExclusionCircuit(45).compile in the existing research-packages workflow after this PR lands.", + "blocked_by": "Maintainer CI policy; out of this session's stop rule." + } + ] +} diff --git a/research/exclusion-embedding-compile/VERIFY.json b/research/exclusion-embedding-compile/VERIFY.json new file mode 100644 index 0000000000..5d4ae0fbe1 --- /dev/null +++ b/research/exclusion-embedding-compile/VERIFY.json @@ -0,0 +1,54 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "scripts/exclusion_circuit.py", + "certificates/positive-side-core.json", + "certificates/dyadic-central-factor.json", + "certificates/ternary-side.json", + "certificates/disjoint-tensor-compression.json", + "tests/test_exclusion_embedding_compile.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 480, + "checks": "Exact baseline copy of the base-commit exclusion_circuit.py; identical ExclusionCircuit.compile maps and verify_embedding receipts on n in {4,6,8,12,16,24,32,45}; compile-map mutant rejected; reverse-frame bit rejection preserved; circuit_sha256 unchanged; closed-form reverse/leave-two masks retained; the four binding certificates differ from base only in the exclusion_circuit.py source pin." + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 480, + "checks": "Same equivalence and certificate pin discipline under -O (historical assert gates strip; receipt identity remains)." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "-m", + "unittest", + "discover", + "-s", + "tests", + "-p", + "test_exclusion_embedding_compile*.py", + "-v" + ], + "timeout_seconds": 180, + "checks": "Focused exclusion-embedding-compile package controls." + } + ] +} diff --git a/research/exclusion-embedding-compile/baseline.py b/research/exclusion-embedding-compile/baseline.py new file mode 100644 index 0000000000..b0e2f3e03d --- /dev/null +++ b/research/exclusion-embedding-compile/baseline.py @@ -0,0 +1,198 @@ +#!/usr/bin/env python3 +"""Cancellation-free circuit for all pair sums avoiding two specified points. + +Every addition has disjoint input supports. Node interning shares equal sums; +support tracking verifies the full linear map, not sampled input values. +""" +from itertools import combinations +from hashlib import sha256 +import json + + +class ExclusionCircuit: + def __init__(self,n): + assert n>=4 + self.n=n + self.inputs=list(combinations(range(n),2)) + self.support=[0]+[1< dict: + env = dict(os.environ) + env.pop("PYTHONOPTIMIZE", None) + env["PYTHONDONTWRITEBYTECODE"] = "1" + proc = subprocess.run( + [sys.executable, "-I", "-B", "-c", WORKER, str(ROOT), mode], + cwd=ROOT, + env=env, + capture_output=True, + text=True, + check=False, + ) + require(proc.returncode == 0, f"worker {mode} failed: {proc.stderr[-2000:]}") + line = proc.stdout.strip().splitlines()[-1] + return json.loads(line) + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--rounds", type=int, default=5) + parser.add_argument("--out", type=Path, default=PACKAGE / "RESULT.json") + args = parser.parse_args() + require(args.rounds >= 1, "rounds") + + samples = [] + for i in range(args.rounds): + order = ("optimized", "baseline") if i % 2 == 0 else ("baseline", "optimized") + pair = {} + for mode in order: + pair[mode] = run_worker(mode) + require( + pair["baseline"]["record"] == pair["optimized"]["record"], + f"receipt mismatch on round {i}", + ) + samples.append( + dict( + round=i, + baseline_seconds=pair["baseline"]["seconds"], + optimized_seconds=pair["optimized"]["seconds"], + ratio=pair["baseline"]["seconds"] / pair["optimized"]["seconds"], + ) + ) + print( + f"round {i}: baseline={pair['baseline']['seconds']:.3f}s " + f"optimized={pair['optimized']['seconds']:.3f}s " + f"ratio={samples[-1]['ratio']:.3f}", + flush=True, + ) + + base_med = statistics.median(s["baseline_seconds"] for s in samples) + opt_med = statistics.median(s["optimized_seconds"] for s in samples) + result = dict( + status="PASS_IDENTICAL_EXCLUSION_EMBEDDING_COMPILE_RECEIPTS", + fixture="ExclusionCircuit(45).verify_embedding only (construction excluded)", + rounds=args.rounds, + median_baseline_seconds=base_med, + median_optimized_seconds=opt_med, + median_ratio=base_med / opt_med, + samples=samples, + environment=dict( + python=sys.version, + platform=platform.platform(), + executable=sys.executable, + ), + source_sha256=dict( + baseline=sha256((PACKAGE / "baseline.py").read_bytes()).hexdigest(), + production=sha256((ROOT / "scripts/exclusion_circuit.py").read_bytes()).hexdigest(), + ), + no_new_kappa=True, + ) + args.out.write_text(json.dumps(result, indent=2, sort_keys=True) + "\n") + print( + "PASS_IDENTICAL_EXCLUSION_EMBEDDING_COMPILE_RECEIPTS", + f"median {base_med:.3f} -> {opt_med:.3f} s ({base_med / opt_med:.2f}x)", + flush=True, + ) + + +if __name__ == "__main__": + main() diff --git a/research/exclusion-embedding-compile/verify.py b/research/exclusion-embedding-compile/verify.py new file mode 100644 index 0000000000..0f4c2ed6f6 --- /dev/null +++ b/research/exclusion-embedding-compile/verify.py @@ -0,0 +1,255 @@ +#!/usr/bin/env python3 +"""Equivalence, pin and mutation controls for exclusion embedding compile. + +Read-only by default. Regenerates no certificate. Timing is not a pass gate; +see benchmark.py / RESULT.json. +""" +from __future__ import annotations + +import argparse +from copy import deepcopy +from hashlib import sha256 +import importlib.util +import json +from pathlib import Path +import subprocess +import sys + +ROOT = Path(__file__).resolve().parents[2] +PACKAGE = Path(__file__).resolve().parent +SCRIPTS = ROOT / "scripts" +sys.path.insert(0, str(SCRIPTS)) + +from certify import require # noqa: E402 +import exclusion_circuit as production # noqa: E402 + +BASE_COMMIT = "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2" +ORIGINAL_BLOB = "b0e2f3e03d7de791ca936dfd92cee2134c7dd4f5" +ORIGINAL_SHA256 = "f9fbcd6e85e442cbd0926ac0887414e20735b2dc923d2d5822c803ceb46726d3" +OPTIMIZED_SHA256 = "f066ce9f88f0d8c0b82d7cb3a8d267249e12386e9d1ab65820a3bed54ff0ff78" +N45_VERIFY_SHA = "3b1a4d7731db2950040552672fbc56ebd172e36e3412129030ff2aec472d5f6c" + +PINNED_CERTIFICATES = ( + "certificates/positive-side-core.json", + "certificates/dyadic-central-factor.json", + "certificates/ternary-side.json", + "certificates/disjoint-tensor-compression.json", +) + + +def load_module(path: Path, name: str): + spec = importlib.util.spec_from_file_location(name, path) + require(spec is not None and spec.loader is not None, f"missing module {path}") + module = importlib.util.module_from_spec(spec) + sys.modules[name] = module + spec.loader.exec_module(module) + return module + + +def digest_file(path: Path) -> str: + return sha256(path.read_bytes()).hexdigest() + + +def git_show(path: str) -> bytes: + return subprocess.check_output(["git", "show", f"{BASE_COMMIT}:{path}"], cwd=ROOT) + + +def check_duplicate_json_keys(text: str, rel: str) -> None: + """Reject duplicate keys inside each JSON object (object-pairs hook).""" + + def pairs_hook(pairs): + keys = [k for k, _ in pairs] + require(len(keys) == len(set(keys)), f"{rel}: duplicate JSON key(s) {keys}") + return dict(pairs) + + json.loads(text, object_pairs_hook=pairs_hook) + + +def check_baseline_bytes() -> None: + baseline = PACKAGE / "baseline.py" + original = git_show("scripts/exclusion_circuit.py") + require(sha256(original).hexdigest() == ORIGINAL_SHA256, "base exclusion_circuit.py sha256 drift") + blob = ( + subprocess.check_output( + ["git", "rev-parse", f"{BASE_COMMIT}:scripts/exclusion_circuit.py"], cwd=ROOT + ) + .decode() + .strip() + ) + require(blob == ORIGINAL_BLOB, "base exclusion_circuit.py blob drift") + require(baseline.read_bytes() == original, "baseline.py must be an exact copy of the base commit source") + require( + digest_file(SCRIPTS / "exclusion_circuit.py") == OPTIMIZED_SHA256, + "production exclusion_circuit.py does not match the claimed optimized digest", + ) + + +def check_compile_and_embedding(baseline, optimized) -> dict: + records = [] + for n in (4, 6, 8, 12, 16, 24, 32, 45): + circuit = optimized.ExclusionCircuit(n) + old_code = baseline.ExclusionCircuit.compile(circuit) + new_code = circuit.compile() + require(old_code == new_code, f"compile map mismatch on n={n}") + old = baseline.ExclusionCircuit.verify_embedding(circuit) + new = circuit.verify_embedding() + require(old == new, f"verify_embedding mismatch on n={n}") + records.append( + dict( + n=n, + roles=new_code["roles"], + gates=len(new_code["gates"]), + reversible_roles=new["reversible_roles"], + forward_coefficient_map_exact=new["forward_coefficient_map_exact"], + forward_support_frames_nested=new["forward_support_frames_nested"], + reverse_support_frames_nested=new["reverse_support_frames_nested"], + no_forbidden_source_target_path=new["no_forbidden_source_target_path"], + ) + ) + require(records[-1]["reversible_roles"] == 12556, "unexpected n=45 reversible_roles") + return {"cases": len(records), "records": records} + + +def check_verify_untouched(baseline, optimized) -> dict: + """Leave-two-out verify receipts and closed-form masks stay in production.""" + circuit = optimized.ExclusionCircuit(45) + old = baseline.ExclusionCircuit.verify(circuit) + new = circuit.verify() + require(old == new, "verify receipt drifted") + require(new["circuit_sha256"] == N45_VERIFY_SHA, "unexpected n=45 circuit_sha256") + text = (SCRIPTS / "exclusion_circuit.py").read_text(encoding="utf-8") + require( + "assert self.support[node]==full^(vertex[a]|vertex[b])" in text, + "verify leave-two-out must retain the #2001 closed-form pair mask", + ) + require( + "assert reverse_frames[slot]==full^(vertex[a]|vertex[b])" in text, + "verify_embedding must retain the closed-form reverse mask", + ) + require("edge0" in text and "edge1" in text, "compile must use parallel edge0/edge1 maps") + require( + "for slot in set(ins+outs)" not in text, + "historical set(ins+outs) nesting loops must be removed from production", + ) + return {"verify_companion": True, "n45_circuit_sha256": N45_VERIFY_SHA} + + +def check_compile_mutant(baseline, optimized) -> dict: + """Corrupt one compiled gate mapping; both checkers must reject nesting.""" + circuit = optimized.ExclusionCircuit(8) + real_compile = optimized.ExclusionCircuit.compile + + def compile_flip(self): + code = real_compile(self) + pairs = list(code["outputs"].items()) + require(len(pairs) >= 2, "need two outputs to flip") + (p0, s0), (p1, s1) = pairs[0], pairs[1] + code = dict(code) + outs = dict(code["outputs"]) + outs[p0], outs[p1] = s1, s0 + code["outputs"] = outs + return code + + optimized.ExclusionCircuit.compile = compile_flip + try: + with _expect_assertion(): + optimized.ExclusionCircuit.verify_embedding(circuit) + with _expect_assertion(): + baseline.ExclusionCircuit.verify_embedding(circuit) + finally: + optimized.ExclusionCircuit.compile = real_compile + return {"compile_mutant": "rejected"} + + +class _expect_assertion: + def __enter__(self): + return self + + def __exit__(self, exc_type, exc, tb): + require(exc_type is AssertionError, "expected AssertionError from corrupted compile map") + return True + + +def check_certificate_pin_discipline() -> dict: + """Certificates may update exclusion_circuit.py and companion disjoint_tensor.py pins.""" + companion_key = "scripts/experiments/disjoint_tensor.py" + companion_orig = "102dd59bf96033f96ba0dab4c2aba77b3a7a73b67b0f96929ff8b20a98b91cd8" + companion_opt = "085600fc922ae167b5981505e1a5caba4d1c1df15482f61d83d2c086fa89eac1" + # Open #2117 may advance the disjoint_tensor pin further; accept either live hash. + companion_open_2117 = "23763a4b6086fb3d19f9282fff5c118f53fa52e7a7f17da1bde990bd4cf8b6ac" + reports = {} + for rel in PINNED_CERTIFICATES: + raw = (ROOT / rel).read_text(encoding="utf-8") + check_duplicate_json_keys(raw, rel) + base = json.loads(git_show(rel).decode()) + live = json.loads(raw) + base_pin = base["source_sha256"]["scripts/exclusion_circuit.py"] + live_pin = live["source_sha256"]["scripts/exclusion_circuit.py"] + require(base_pin == ORIGINAL_SHA256, f"{rel}: unexpected base pin") + require(live_pin == OPTIMIZED_SHA256, f"{rel}: optimized pin missing") + restored = deepcopy(live) + restored["source_sha256"]["scripts/exclusion_circuit.py"] = ORIGINAL_SHA256 + if companion_key in live["source_sha256"]: + require( + live["source_sha256"][companion_key] + in {companion_orig, companion_opt, companion_open_2117}, + f"{rel}: unexpected companion disjoint_tensor pin", + ) + restored["source_sha256"][companion_key] = companion_orig + # Base tip may already carry the post-#2001 companion opt pin. + base_companion = base["source_sha256"].get(companion_key) + if base_companion in {companion_opt, companion_open_2117}: + restored["source_sha256"][companion_key] = base_companion + require(restored == base, f"{rel}: changed fields beyond allowed source pins") + reports[rel] = { + "base_pin": base_pin, + "live_pin": live_pin, + "only_pin_changed": True, + } + return reports + + +def check_temp_corruption_rejection() -> dict: + """On-disk corruption of a temp production copy must fail the digest gate.""" + import tempfile + + src = (SCRIPTS / "exclusion_circuit.py").read_bytes() + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "exclusion_circuit.py" + path.write_bytes(src + b"\n# corrupted\n") + require(digest_file(path) != OPTIMIZED_SHA256, "corruption must change digest") + return {"temp_corruption": "rejected"} + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--write-certificate", action="store_true", help="unused; kept for API parity") + args = parser.parse_args() + require(not args.write_certificate, "this package does not rewrite certificate payloads") + + check_baseline_bytes() + baseline = load_module(PACKAGE / "baseline.py", "exclusion_embedding_compile_baseline") + cases = check_compile_and_embedding(baseline, production) + verify_guard = check_verify_untouched(baseline, production) + if __debug__: + mutant = check_compile_mutant(baseline, production) + else: + mutant = {"compile_mutant": "skipped_under_-O"} + pins = check_certificate_pin_discipline() + corruption = check_temp_corruption_rejection() + print( + "PASS_EXCLUSION_EMBEDDING_COMPILE", + f"cases={cases['cases']}", + f"certs={len(pins)}", + "no_new_kappa", + ) + print( + "controls", + mutant["compile_mutant"], + f"verify_companion={verify_guard['verify_companion']}", + corruption["temp_corruption"], + ) + + +if __name__ == "__main__": + main() diff --git a/research/exclusion-embedding-masks/verify.py b/research/exclusion-embedding-masks/verify.py index d280945bc5..f02f5aa1d0 100644 --- a/research/exclusion-embedding-masks/verify.py +++ b/research/exclusion-embedding-masks/verify.py @@ -26,7 +26,7 @@ BASE_COMMIT = "0b1cccf86e2f5132ed286a26ef0a681a495740ea" ORIGINAL_BLOB = "aaa99986c4b81c5d4fbe016fd216a4818940bb95" ORIGINAL_SHA256 = "b253f9d7318becda1c1f3b24e2287ed44a9c27fcea00cf9d531afb950d0457a0" -OPTIMIZED_SHA256 = "f9fbcd6e85e442cbd0926ac0887414e20735b2dc923d2d5822c803ceb46726d3" +OPTIMIZED_SHA256 = "f066ce9f88f0d8c0b82d7cb3a8d267249e12386e9d1ab65820a3bed54ff0ff78" N45_VERIFY_SHA = "3b1a4d7731db2950040552672fbc56ebd172e36e3412129030ff2aec472d5f6c" PINNED_CERTIFICATES = ( diff --git a/research/exclusion-support-masks/verify.py b/research/exclusion-support-masks/verify.py index 43b8396e11..67123cd72b 100644 --- a/research/exclusion-support-masks/verify.py +++ b/research/exclusion-support-masks/verify.py @@ -26,7 +26,7 @@ BASE_COMMIT = "0b1cccf86e2f5132ed286a26ef0a681a495740ea" ORIGINAL_BLOB = "aaa99986c4b81c5d4fbe016fd216a4818940bb95" ORIGINAL_SHA256 = "b253f9d7318becda1c1f3b24e2287ed44a9c27fcea00cf9d531afb950d0457a0" -OPTIMIZED_SHA256 = "f9fbcd6e85e442cbd0926ac0887414e20735b2dc923d2d5822c803ceb46726d3" +OPTIMIZED_SHA256 = "f066ce9f88f0d8c0b82d7cb3a8d267249e12386e9d1ab65820a3bed54ff0ff78" PINNED_CERTIFICATES = ( "certificates/positive-side-core.json", diff --git a/scripts/exclusion_circuit.py b/scripts/exclusion_circuit.py index b0e2f3e03d..33060a507e 100644 --- a/scripts/exclusion_circuit.py +++ b/scripts/exclusion_circuit.py @@ -121,27 +121,47 @@ def compile(self): Gates are (input slots, output slots), sharing their first pivot slot. All extra output slots are allocated fresh; nonpivot inputs retire. + + Slot wiring uses parallel edge0/edge1 maps instead of ``edge[node,pos]`` + tuple keys, and walks ``sorted(self.active)`` once. Gate lists, role + counts, source/output slot maps remain identical to the historical + allocator. See ``research/exclusion-embedding-compile/``. """ + active=sorted(self.active) + args=self.args users={x:[] for x in self.active} - for node in sorted(self.active): - if self.args[node]: - for pos,x in enumerate(self.args[node]):users[x].append(('gate',node,pos)) - for target,node in sorted(self.outputs.items()):users[node].append(('output',target)) - edge={};source_slots={};output_slots={};gates=[];size=0 - for node in sorted(self.active): - if self.args[node]: - ins=(edge[node,0],edge[node,1]);pivot=ins[0] + for node in active: + ab=args[node] + if ab: + a,b=ab + users[a].append(('gate',node,0)) + users[b].append(('gate',node,1)) + for target,node in sorted(self.outputs.items()): + users[node].append(('output',target)) + edge0={};edge1={} + source_slots={};output_slots={};gates=[];size=0 + inputs=self.inputs + for node in active: + ab=args[node] + if ab: + ins=(edge0[node],edge1[node]);pivot=ins[0] + # Historical: len(set(ins))==len(ins) and set(ins)&set(outs)=={pivot}. + # Binary gates have two distinct inputs; outs[1:] are fresh ids. + assert ins[0]!=ins[1] else: pivot=size;size+=1;ins=(pivot,) - source_slots[self.inputs[node-1]]=pivot - assert users[node] - outs=(pivot,)+tuple(range(size,size+len(users[node])-1)) - size+=len(users[node])-1 - assert len(set(ins))==len(ins) and set(ins)&set(outs)=={pivot} + source_slots[inputs[node-1]]=pivot + ulist=users[node] + assert ulist + n_extra=len(ulist)-1 + outs=(pivot,)+tuple(range(size,size+n_extra)) + size+=n_extra gates.append((node,ins,outs)) - for user,slot in zip(users[node],outs): - if user[0]=='gate':edge[user[1],user[2]]=slot - else:output_slots[user[1]]=slot + for user,slot in zip(ulist,outs): + if user[0]=='gate': + (edge0 if user[2]==0 else edge1)[user[1]]=slot + else: + output_slots[user[1]]=slot assert size==self.additions+len(self.outputs) return dict(roles=size,gates=gates,sources=source_slots,outputs=output_slots) @@ -149,30 +169,53 @@ def verify_embedding(self): """Check scalar coefficients and both directions' frame support nesting.""" code=self.compile();gates=code['gates'];size=code['roles'] values=[0]*size;frames=[0]*size + support=self.support;variables=self.variables;outputs=self.outputs for pair,slot in code['sources'].items(): - values[slot]=frames[slot]=self.support[self.variables[pair]] + values[slot]=frames[slot]=support[variables[pair]] for node,ins,outs in gates: - frame=self.support[node] - for slot in set(ins+outs): + frame=support[node] + # Unique slots are pivot + ins[1:] + outs[1:] because + # set(ins) & set(outs) == {pivot} on every historical gate. + pivot=ins[0] + assert frames[pivot]&~frame==0 + frames[pivot]=frame + for slot in ins[1:]: assert frames[slot]&~frame==0 frames[slot]=frame - for slot in ins[1:]:values[ins[0]]^=values[slot] - for slot in outs[1:]:values[slot]^=values[ins[0]] + for slot in outs[1:]: + assert frames[slot]&~frame==0 + frames[slot]=frame + acc=values[pivot] + for slot in ins[1:]: + acc^=values[slot] + values[pivot]=acc + for slot in outs[1:]: + values[slot]^=acc for pair,slot in code['outputs'].items(): - assert values[slot]==frames[slot]==self.support[self.outputs[pair]] - descendants={node:0 for node in self.active} + assert values[slot]==frames[slot]==support[outputs[pair]] + # Dense descendant array: inactive nodes stay 0 and are skipped. + descendants=[0]*len(support) target_index={pair:i for i,pair in enumerate(sorted(self.outputs))} reverse_frames=[0]*size for pair,node in self.outputs.items(): bit=1<