From 761d3573252b1b0c3bba9e9c7af836a3ae2574c7 Mon Sep 17 00:00:00 2001 From: Wentao Li Date: Thu, 15 Oct 2026 00:57:26 +0000 Subject: [PATCH 1/2] Tooling: ship spectator-orbit screen into production sparse-fusion Wire ToikY's exact orbit-weighted central_gate_screen into the shipped scripts/audit_sparse_fusion.py path used by make verify. Screen receipts at h=22,25,28 and certificates/sparse-fusion-audit.json stay byte-identical. Package research/sparse-fusion-orbits-production/ with baseline, verify and benchmark harness. Prepared by Wentao Li with substantial AI assistance. --- .../sparse-fusion-orbits-production/NOTICE.md | 17 ++ .../sparse-fusion-orbits-production/README.md | 97 +++++++ .../SOURCES.json | 60 ++++ .../sparse-fusion-orbits-production/TASK.json | 70 +++++ .../VERIFY.json | 23 ++ .../baseline.py | 268 ++++++++++++++++++ .../benchmark.py | 177 ++++++++++++ .../sparse-fusion-orbits-production/verify.py | 207 ++++++++++++++ scripts/audit_sparse_fusion.py | 31 +- 9 files changed, 945 insertions(+), 5 deletions(-) create mode 100644 research/sparse-fusion-orbits-production/NOTICE.md create mode 100644 research/sparse-fusion-orbits-production/README.md create mode 100644 research/sparse-fusion-orbits-production/SOURCES.json create mode 100644 research/sparse-fusion-orbits-production/TASK.json create mode 100644 research/sparse-fusion-orbits-production/VERIFY.json create mode 100644 research/sparse-fusion-orbits-production/baseline.py create mode 100644 research/sparse-fusion-orbits-production/benchmark.py create mode 100644 research/sparse-fusion-orbits-production/verify.py diff --git a/research/sparse-fusion-orbits-production/NOTICE.md b/research/sparse-fusion-orbits-production/NOTICE.md new file mode 100644 index 0000000000..6cfd87990a --- /dev/null +++ b/research/sparse-fusion-orbits-production/NOTICE.md @@ -0,0 +1,17 @@ +# Attribution and license + +Prepared by Wentao Li ([VictorLiwentao](https://github.com/VictorLiwentao), +[@Is__Victor](https://x.com/Is__Victor), wentaol4@illinois.edu) with substantial +AI assistance for orientation, overlap search, profiling, production wiring, +packaging, benchmarking and writing. Not independent human peer review. +Apache-2.0; see the repository root `LICENSE`. + +The exact spectator-orbit reduction and its permutation-conjugation argument +were introduced by **ToikY** in the opt-in adapter +`research/sparse-fusion-orbits/` (see that package's NOTICE.md and PROOF.md). +This package wires an equivalent check into the production +`scripts/audit_sparse_fusion.py:central_gate_screen` path used by `make verify`. + +The original sparse/fusion finite screen, phase-group identities and scientific +receipt are by **Douglas R. Colkitt**. Upstream material retains its own source +notices and license. diff --git a/research/sparse-fusion-orbits-production/README.md b/research/sparse-fusion-orbits-production/README.md new file mode 100644 index 0000000000..b39e9ccd52 --- /dev/null +++ b/research/sparse-fusion-orbits-production/README.md @@ -0,0 +1,97 @@ +# Production spectator orbits for the sparse-fusion screen + +**Tooling improvement; no new kappa.** At base +`0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2`, +`scripts/audit_sparse_fusion.py:central_gate_screen` still summed exact binary +ranks over every weight-three indicator. ToikY's opt-in adapter +`research/sparse-fusion-orbits/` already proved an exact spectator-orbit +reduction with identical receipts. This package wires that equivalent check +into the **production** source used by `make verify`. + +`certificates/sparse-fusion-audit.json` stays **byte-identical** (this audit has +no `source_sha256` map). Every screen field, all 4,096 joint-frame inequalities, +finite phase identities, candidate budgets and the retained historical language +are unchanged. Selected frontier untouched. + +## Reproduce + +Python **3.12**, standard library only, from the repository root: + +```sh +python3.12 -I -B research/sparse-fusion-orbits-production/verify.py +python3.12 -I -O -B research/sparse-fusion-orbits-production/verify.py +python3.12 -B scripts/research_package.py --package research/sparse-fusion-orbits-production +python3.12 -I -B research/sparse-fusion-orbits-production/benchmark.py --rounds 5 +``` + +Expected: + +```text +PASS_SPARSE_FUSION_ORBITS_PRODUCTION screen_heights=[22, 25, 28] screen_cases=3 certs=1 no_new_kappa +PASS_REGISTERED_RESEARCH_PACKAGE research/sparse-fusion-orbits-production outcome=completed +PASS_IDENTICAL_SPARSE_FUSION_ORBITS_PRODUCTION_RECEIPTS +``` + +Default verify is read-only. Use `--write-certificate` only after editing the +production source if regeneration is ever needed; the mathematical certificate +must still match the base bytes. Timing is host-descriptive and is not a +correctness gate. + +On Linux / CPython 3.12.3, five alternating fresh-process pairs gave median +**screen-only 0.559 → 0.041 s (≈13.6×)** and **complete certificate 0.568 → +0.054 s (≈10.5×)** in the orientation profile; retained samples are written by +`benchmark.py` into [`RESULT.json`](RESULT.json). + +## Why the orbits are equivalent + +For each of the 64 symmetric three-coordinate blocks `S`, the screen builds +`Q = diag(S, I_(h-3))`. Permutations fixing coordinates 0,1,2 satisfy +`P Q P^T = Q`, so + +```text +rank(Q + t t^T) = rank(Q + (P t)(P t)^T). +``` + +Weight-three indicators with the same low three bits form one orbit of size +`C(h-3, 3-wt(low))`. Summing the eight weighted representatives therefore equals +the historical sum over all `C(h,3)` triples. At `h=25`, unary ranks fall from +147,200 to 512; the 128 frame ranks and 4,096 joint-pair ranks stay unchanged. +This is the same argument as `research/sparse-fusion-orbits/PROOF.md`. + +## Overlap and credit + +Closest priors: + +- [ToikY / sparse-fusion-orbits](../sparse-fusion-orbits/) — opt-in orbit + adapter; this package is the production wiring. +- [CrocSwap/integer-mult-bounds#756](https://github.com/CrocSwap/integer-mult-bounds/pull/756) + — identical-receipt tooling quality bar. +- Open leave-alone tooling on other objects (#1922 joint frames, #2054/#2150 + shared/mixed-point, #2100 ternary, #2117 DisjointTensor.frame_data, #2194 + production verify_factor, #2210 production leech_minor, #1861 parity-side) + was not reopened. Fresh overlap refresh over 464 open PRs found no competing + production rewrite of `central_gate_screen`. + +Douglas R. Colkitt authored the sparse/fusion screen and original checker. +ToikY authored the orbit algorithm. Prepared by Wentao Li +([VictorLiwentao](https://github.com/VictorLiwentao), +[@Is__Victor](https://x.com/Is__Victor)) with substantial AI assistance, under +Apache-2.0. + +## Open next questions + +1. **Question:** Should `research/sparse-fusion-orbits/` note that production + now ships the same orbit reduction? + **Why it matters:** That package's source-admission pins expect the + historical pairwise enumeration block. + **First step:** Add a one-line status note without editing pinned evidence. + **Blocked by:** Maintainer preference on touching incorporated historical + packages. + +2. **Question:** After orbit wiring, is the remaining joint-pair double loop + the next productive production pass? + **Why it matters:** With unary ranks reduced, joint pairs dominate residual + screen time. + **First step:** Profile production `central_gate_screen` with orbits merged. + **Blocked by:** No open identical-receipt adapter yet for the joint-pair + stage. diff --git a/research/sparse-fusion-orbits-production/SOURCES.json b/research/sparse-fusion-orbits-production/SOURCES.json new file mode 100644 index 0000000000..842ecc95df --- /dev/null +++ b/research/sparse-fusion-orbits-production/SOURCES.json @@ -0,0 +1,60 @@ +{ + "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": "certificates/sparse-fusion-audit.json", + "usage": "input", + "git_blob": "584ea8d56bbc3c6c12867f9551b425764fbe653d", + "sha256": "b7f0976e757998011f16022181246ad1b70db5b17ed32167f7e92368d2b43ee6" + }, + { + "path": "docs/research/sparse-fusion-audit.md", + "usage": "provenance", + "git_blob": "32a3553a9e8a5072f1b669130e628d92ca868b5c", + "sha256": "631c852e068adf8d2943bf8f7373d822f423c2180ed0c8d413188a30ff51d75a" + }, + { + "path": "scripts/audit_sparse_fusion.py", + "usage": "provenance", + "git_blob": "4e8e789d686b85a49fc12d36f87619eed705d6a8", + "sha256": "bbaa32f9786f083409e363b081bfb7a1e597c8d32e4183c13a4105c2170934ce" + }, + { + "path": "tests/test_sparse_fusion.py", + "usage": "provenance", + "git_blob": "6c0fa720b4c67db5cee64dba962ec920ea21852c", + "sha256": "ad078502dbbcff04147665aed61609b31dc09a8e9a404d4e344aa5d462f568eb" + }, + { + "path": "research/sparse-fusion-orbits/accelerator.py", + "usage": "input", + "git_blob": "24531ac40bdf283cab9d82f2a46d761ca9f03911", + "sha256": "17e5c373f6a45afb47e99219edec7f3aaf76facaeb0c42797683a0690d1c0fcd" + }, + { + "path": "research/sparse-fusion-orbits/PROOF.md", + "usage": "provenance", + "git_blob": "118374b851be7164b05d476fdb0e329eb1e54cc3", + "sha256": "9c4dab77ef666c0c5dd6fd868e539597b88587d25574dde86b61736b77b617a2" + }, + { + "path": "research/sparse-fusion-orbits/README.md", + "usage": "provenance", + "git_blob": "890e47e856f6d969843a2d8be57aaa5f98f281ac", + "sha256": "e25eb7c087e6b80dd6a191677720818dbdd65a01331b0e557d901c115ed24447" + } + ] +} diff --git a/research/sparse-fusion-orbits-production/TASK.json b/research/sparse-fusion-orbits-production/TASK.json new file mode 100644 index 0000000000..4a069bd0ec --- /dev/null +++ b/research/sparse-fusion-orbits-production/TASK.json @@ -0,0 +1,70 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "priority_revision": 4, + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "chooser_seed": "daa8525f8946aff290000e81ce05cf4b", + "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 the production sparse-fusion central_gate_screen (scripts/audit_sparse_fusion.py, exercised by make verify / certificates/sparse-fusion-audit.json) adopt the exact spectator-orbit weighted representatives from research/sparse-fusion-orbits/ so the shipped verify path is faster while every screen field, joint-pair inequality and complete certificate stays identical?", + "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 after profiling make verify poles. Leave-alone objects (joint frames, shared-point, mixed-point verify, ternary frames, parity-side, DisjointTensor.frame_data, production verify_factor, leech_minor production, quadratic-affine) and deferred micro-opts were not reopened. ToikY's incorporated sparse-fusion-orbits adapter already proved an opt-in identical-receipt accelerator; production still enumerated all C(h,3) triples pairwise.", + "bottleneck_link": "Side result on review throughput: sparse-fusion is part of make verify. Faster identical central_gate_screen ranks do not change kappa or the binding complex supplier.", + "ai_assistance": "Substantial AI assistance for orientation, overlap search, profiling, production wiring, packaging, benchmarking and writing", + "outcome": "completed", + "evidence": "PASS_SPARSE_FUSION_ORBITS_PRODUCTION via research/sparse-fusion-orbits-production/verify.py (also under -O); PASS_IDENTICAL_SPARSE_FUSION_ORBITS_PRODUCTION_RECEIPTS via benchmark.py; certificates/sparse-fusion-audit.json remains byte-identical to the base commit.", + "author": "Wentao Li", + "email": "wentaol4@illinois.edu", + "github": "VictorLiwentao", + "budget_minutes": 60, + "stop_rule": "Ship an equivalence-preserving production central_gate_screen change with frozen baseline, identical screen and complete-certificate payloads, rejection/temp-corruption controls, unchanged certificate bytes, registered replay and a measured before/after median. Do not invent kappa or reopen leave-alone objects.", + "open_questions": [ + { + "question": "Should research/sparse-fusion-orbits/ note that production now ships the same orbit reduction?", + "why_it_matters": "That opt-in package's source-admission pins expect the historical pairwise enumeration block.", + "first_step": "Add a one-line status note to that package README without editing its pinned evidence.", + "blocked_by": "Maintainer preference on touching incorporated historical packages." + }, + { + "question": "After orbit wiring, is the remaining joint-pair double loop (4096 ranks) the next productive production pass?", + "why_it_matters": "With unary ranks reduced from 147200 to 512 at h=25, joint pairs dominate residual screen time.", + "first_step": "Profile production central_gate_screen with orbits merged and name any further exact symmetry.", + "blocked_by": "No open identical-receipt adapter yet for the joint-pair stage." + } + ] +} diff --git a/research/sparse-fusion-orbits-production/VERIFY.json b/research/sparse-fusion-orbits-production/VERIFY.json new file mode 100644 index 0000000000..b5295431d2 --- /dev/null +++ b/research/sparse-fusion-orbits-production/VERIFY.json @@ -0,0 +1,23 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/sparse-fusion-orbits/accelerator.py", + "certificates/sparse-fusion-audit.json", + "scripts/audit_sparse_fusion.py" + ], + "commands": [ + { + "argv": ["{python}", "-I", "-B", "{package}/verify.py"], + "timeout_seconds": 300, + "checks": "Exact baseline copy of the base-commit audit_sparse_fusion.py; identical central_gate_screen receipts at h=22,25,28; identical complete certificate; orbit cover C(h,3); rejection and temp-copy weight-omission controls; certificate bytes unchanged from base; duplicate JSON-key check; read-only default." + }, + { + "argv": ["{python}", "-I", "-O", "-B", "{package}/verify.py"], + "timeout_seconds": 300, + "checks": "Same equivalence and certificate discipline under -O (require() gates remain)." + } + ] +} diff --git a/research/sparse-fusion-orbits-production/baseline.py b/research/sparse-fusion-orbits-production/baseline.py new file mode 100644 index 0000000000..4e8e789d68 --- /dev/null +++ b/research/sparse-fusion-orbits-production/baseline.py @@ -0,0 +1,268 @@ +#!/usr/bin/env python3 +"""Bounded sparse/fused-primitive audit; no new multiplication bound. + +Quadratic phase signatures describe exact products of directional C kernels. +They do not grant permission to commute a phase through a scalar mixing gate. +""" +from collections import deque +from fractions import Fraction as Q +from itertools import combinations, product +import json +from pathlib import Path + +from certify import require, verify_sources +from prepare_layers import BIT_SAVING, scenarios, serializable + +ROOT=Path(__file__).resolve().parents[1] + + +def parity(value): + return value.bit_count()%2 + + +def signature(dimension, directions=()): + """q(x)=sum d_i*x_i+2 sum b_ij*x_i*x_j mod 4. + + Each (v,sign) contributes sign*[v dot x], the Fourier eigenphase of C_v. + A zero direction is the identity. Signs may be arbitrary integers. + """ + require(dimension>=1,'Positive dimension required') + diagonal=[0]*dimension + cross=[0]*(dimension*(dimension-1)//2) + for v,sign in directions: + require(0<=v<1<>i)&1))%4 + k=0 + for i in range(dimension): + for j in range(i+1,dimension): + cross[k]=(cross[k]+sign*((v>>i)&1)*((v>>j)&1))%2 + k+=1 + return tuple(diagonal+cross) + + +def phase_value(dimension, phase, x): + require(len(phase)==dimension+dimension*(dimension-1)//2,'Wrong signature size') + value=sum(phase[i]*((x>>i)&1) for i in range(dimension)) + k=dimension + for i in range(dimension): + for j in range(i+1,dimension): + value+=2*phase[k]*((x>>i)&1)*((x>>j)&1) + k+=1 + return value%4 + + +def add_phase(dimension,left,right): + return tuple((a+b)%(4 if i=22,'Use the admissible complex family') + triples=[sum(1<>at&1: + Qcols[j]^=1<>i&1 else 0) + for i,col in enumerate(Qcols)])+r for t in triples) + frames.append((Qcols,k,r,unary)) + if r==0:continue + actual=unary+2*centers*k + proved_increase=v*(k+r-h)+2*(Q(v,h)-centers)*(h-k) + require(actual-baseline>=proved_increase>0,'Central-frame lower bound failed') + minimum_changed=actual if minimum_changed is None else min(actual,minimum_changed) + # Allow both middle central frames to change. The other two central + # frames can be eliminated from this LOWER bound by triangle inequalities. + joint_baseline=2*v*(h-1)+3*centers*h + joint_min_changed=None + for A,kA,rA,unaryA in frames: + for IC,kIC,rIC,unaryIC in frames: + # The second middle frame is C=I+IC. + AC=[x^y^(1<=lower>=0,'Joint central-frame bound failed') + if rA or rIC: + require(lower>0,'Nonoriginal middle frames escaped strict bound') + joint_min_changed=actual if joint_min_changed is None else min(joint_min_changed,actual) + else:require(actual==joint_baseline,'Original central frame score changed') + return dict(h=h,triples=v,center_roles=centers,baseline_incident_rank=baseline, + sampled_changed_frames=63,minimum_sampled_changed_rank=minimum_changed, + rank_density=Q(v,h),density_minus_center_count=Q(v,h)-centers, + joint_frame_pairs=4096,joint_baseline=joint_baseline, + joint_minimum_changed_rank=joint_min_changed, + theorem='The original four central frames jointly minimize the directional rank lower bound when side frames and the active h-factor are fixed.', + scope='All four central frames may vary, but side frames, topology and the tensor factor are retained. Does not exclude changing those ingredients or the tape primitive.') + + +def finite_audit(): + words=minimum_words(3) + # All seven nonzero 3-bit linear forms have phase sum zero modulo four. + all_seven=[(v,1) for v in range(1,8)] + require(signature(3,all_seven)==signature(3),'Seven-direction identity failed') + six=[(v,1) for v in range(1,8) if v!=1] + require(signature(3,six)==signature(3,[(1,-1)]),'Six-to-one identity failed') + require(len(words[signature(3,six)])==1,'Scalar minimum not reproduced') + + # A nontrivial collective symmetry in dimension six: M=I+J over F2. + columns=[63^(1<>i&1]) + right=signature(3,[(1<>i&1]) + if left==right: + preserving+=1 + require(all(columns3[i]&~active==0 for i in range(3) if active>>i&1), + 'A coordinate phase stabilizer moved its active subspace') + require(total==168,'GL(3,2) enumeration is incomplete') + + # Moving a phase through a mixing gate is a separate algebraic condition. + zero=signature(3) + one=signature(3,[(1,1)]) + shear=((1,0),(1,1)) + require(not mixes_commute(shear,(one,zero)),'Unequal-frame shear unexpectedly commutes') + require(mixes_commute(shear,(one,one)),'Common phase must commute') + require(mixes_commute(((1,0),(0,-1)),(one,zero)), + 'A diagonal scalar gate should allow independent phases') + + return dict(phase_group_dimension=3,phase_group_size=len(words), + maximum_minimum_direction_calls=max(map(len,words.values())), + all_seven_product_is_identity=True, + six_direction_product_equals_inverse_of_missing_direction=True, + six_direction_minimum_calls=1, + collective_symmetry_dimension=6,collective_symmetry_columns=columns, + gl3_invertible_matrices=total,gl3_phase_preserving_pairs=preserving, + unequal_phase_shear_commutes=False, + scope='Exact operator identities and optimistic directional-call distances; no tape cost or legal cross-gate fusion is inferred.') + + +def candidate_budgets(): + rows={} + for name,row in scenarios().items(): + if not row['recurrence']['hypothetical']:continue + p=row['parameters'] + target_gap=p['kappa']/p['epsilon'] + r=p['tau'];beta=p['beta'];sigma=p['sigma'];c=p['c'] + # Feasibility requires chi<1-kappa/epsilon, before choosing lambda. + max_theta=(1-target_gap-r-(1-beta)*max(sigma-r,Q(0)))/c + # Alternative theta=1/1000 in the sigma>r branch. + theta=Q(1,1000) + required_active_saving=(theta*c+target_gap-(1-beta)*(1-sigma))/beta + require(01-sigma, + 'Alternative active-saving regime does not apply') + rows[name]=dict(target=p['kappa'],beta=beta,c=c, + maximum_spacing_exponent_at_current_active_saving=max_theta, + alternative_spacing_exponent=theta, + necessary_active_saving_for_alternative=required_active_saving, + note='Strict necessary internal-cost budgets for these fixed parameters, not a primitive or sufficient whole-algorithm certificate.') + return rows + + +def certificate(): + a=BIT_SAVING;tau=1-a + return dict(status='BOUNDED SPARSE/FUSION AUDIT; NO NEW MULTIPLICATION EXPONENT', + upstream_commit=verify_sources(),finite=finite_audit(), + central_frame_screen=central_gate_screen(), + candidate_budgets=candidate_budgets(), + batching=dict(existing_active_exponent=tau,spacing_exponent=tau, + necessary_c_upper=a/tau, + proof='For positive batch sizes b_i summing to f, sum b_i^tau >= f^tau. Separate calls to the existing whole-slot bound cannot improve its exponent by batching alone.', + scope='Optimizing these certified separate-call upper bounds, not a lower bound on actual tape time.'), + next_step='Search coordinated side/central changes, a new gate topology, or a new sparse address primitive. Central-only relabeling is excluded in the audited model. Require the complete gate product and tape accounting.') + + +if __name__=='__main__': + result=certificate() + (ROOT/'certificates/sparse-fusion-audit.json').write_text( + json.dumps(serializable(result),indent=2,sort_keys=True)+'\n') + print('PASS bounded sparse/fusion audit; phase group size',result['finite']['phase_group_size']) + print('Six-to-one scalar fusion verified; intervening mixing gates remain an obstruction.') diff --git a/research/sparse-fusion-orbits-production/benchmark.py b/research/sparse-fusion-orbits-production/benchmark.py new file mode 100644 index 0000000000..d774218367 --- /dev/null +++ b/research/sparse-fusion-orbits-production/benchmark.py @@ -0,0 +1,177 @@ +#!/usr/bin/env python3 +"""Alternating fresh-process before/after timings for production orbit screens. + +Timing is descriptive evidence for RESULT.json. Equivalence is enforced by +verify.py; this script fails only on unequal receipts or subprocess errors. +""" +from __future__ import annotations + +import argparse +from hashlib import sha256 +import json +import os +from pathlib import Path +import platform +import statistics +import subprocess +import sys + +ROOT = Path(__file__).resolve().parents[2] +PACKAGE = Path(__file__).resolve().parent + +WORKER = r""" +import importlib.util +import json +import sys +import time +from pathlib import Path + +root = Path(sys.argv[1]) +engine = sys.argv[2] +scope = sys.argv[3] +sys.path.insert(0, str(root / "scripts")) + +if engine == "baseline": + spec = importlib.util.spec_from_file_location( + "audit_sparse_fusion_baseline", + root / "research/sparse-fusion-orbits-production/baseline.py", + ) + audit = importlib.util.module_from_spec(spec) + spec.loader.exec_module(audit) +else: + import audit_sparse_fusion as audit + +from prepare_layers import serializable + +if scope == "screen": + t0 = time.perf_counter() + receipt = audit.central_gate_screen(25) + elapsed = time.perf_counter() - t0 + print(json.dumps({"elapsed": elapsed, "receipt": serializable(receipt)}, sort_keys=True)) +else: + t0 = time.perf_counter() + cert = audit.certificate() + elapsed = time.perf_counter() - t0 + print(json.dumps({"elapsed": elapsed, "payload": serializable(cert)}, sort_keys=True)) +""" + + +def run_engine(engine: str, scope: str) -> dict: + env = os.environ.copy() + env.pop("PYTHONOPTIMIZE", None) + env["PYTHONDONTWRITEBYTECODE"] = "1" + proc = subprocess.run( + [sys.executable, "-I", "-B", "-c", WORKER, str(ROOT), engine, scope], + cwd=ROOT, + env=env, + capture_output=True, + text=True, + ) + if proc.returncode != 0: + raise SystemExit(f"engine={engine} scope={scope} failed\n{proc.stderr}\n{proc.stdout}") + return json.loads(proc.stdout.strip().splitlines()[-1]) + + +def measure(scope: str, rounds: int) -> dict: + baseline_samples = [] + optimized_samples = [] + reference = None + samples = [] + key = "receipt" if scope == "screen" else "payload" + for round_index in range(rounds): + order = ("baseline", "optimized") if round_index % 2 == 0 else ("optimized", "baseline") + pair = {} + for engine in order: + payload = run_engine(engine, scope) + if reference is None: + reference = payload[key] + elif payload[key] != reference: + raise SystemExit(f"receipt mismatch scope={scope} round={round_index} engine={engine}") + pair[engine] = payload["elapsed"] + baseline_samples.append(pair["baseline"]) + optimized_samples.append(pair["optimized"]) + samples.append( + { + "round": round_index, + "order": list(order), + "baseline_seconds": pair["baseline"], + "optimized_seconds": pair["optimized"], + "ratio": pair["baseline"] / pair["optimized"] if pair["optimized"] else None, + } + ) + print( + f"scope={scope} round={round_index} order={order[0]}->{order[1]} " + f"baseline={pair['baseline']:.6f}s optimized={pair['optimized']:.6f}s", + flush=True, + ) + base_med = statistics.median(baseline_samples) + opt_med = statistics.median(optimized_samples) + return { + "scope": scope, + "rounds": rounds, + "median_baseline_seconds": base_med, + "median_optimized_seconds": opt_med, + "median_ratio": base_med / opt_med if opt_med else None, + "samples": samples, + } + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--rounds", type=int, default=5) + parser.add_argument("--output", type=Path, default=PACKAGE / "RESULT.json") + args = parser.parse_args(argv) + if args.rounds < 1: + raise SystemExit("--rounds must be >= 1") + + screen = measure("screen", args.rounds) + audit = measure("certificate", args.rounds) + result = { + "status": "PASS_IDENTICAL_SPARSE_FUSION_ORBITS_PRODUCTION_RECEIPTS", + "ai_assistance": ( + "Substantial AI assistance for orientation, overlap search, profiling, " + "production wiring, packaging, benchmarking and writing. Not independent " + "human peer review." + ), + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "predecessor": "research/sparse-fusion-orbits/", + "engines": { + "baseline": "research/sparse-fusion-orbits-production/baseline.py", + "optimized": "scripts/audit_sparse_fusion.py", + }, + "source_sha256": { + "baseline.py": sha256((PACKAGE / "baseline.py").read_bytes()).hexdigest(), + "scripts/audit_sparse_fusion.py": sha256( + (ROOT / "scripts/audit_sparse_fusion.py").read_bytes() + ).hexdigest(), + "research/sparse-fusion-orbits/accelerator.py": sha256( + (ROOT / "research/sparse-fusion-orbits/accelerator.py").read_bytes() + ).hexdigest(), + }, + "environment": { + "python": sys.version, + "executable": sys.executable, + "platform": platform.platform(), + "implementation": platform.python_implementation(), + "os_caches_flushed": False, + "cpu_affinity_set": False, + }, + "screen_only": screen, + "complete_certificate": audit, + "no_new_kappa": True, + } + args.output.write_text(json.dumps(result, indent=2, sort_keys=True) + "\n", encoding="utf-8") + print(result["status"]) + print( + f"screen_median {screen['median_baseline_seconds']:.6f} -> " + f"{screen['median_optimized_seconds']:.6f} ({screen['median_ratio']:.3f}x)" + ) + print( + f"certificate_median {audit['median_baseline_seconds']:.6f} -> " + f"{audit['median_optimized_seconds']:.6f} ({audit['median_ratio']:.3f}x)" + ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/research/sparse-fusion-orbits-production/verify.py b/research/sparse-fusion-orbits-production/verify.py new file mode 100644 index 0000000000..2924c41781 --- /dev/null +++ b/research/sparse-fusion-orbits-production/verify.py @@ -0,0 +1,207 @@ +#!/usr/bin/env python3 +"""Equivalence, rejection and certificate controls for production orbit screens. + +Read-only by default. Regenerates no certificate unless --write-certificate is +passed. Timing is not a pass gate; see benchmark.py / RESULT.json. +""" +from __future__ import annotations + +import argparse +from hashlib import sha256 +import importlib.util +import json +from math import comb +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile + +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 +from prepare_layers import serializable # noqa: E402 +import audit_sparse_fusion as production # noqa: E402 + +BASE_COMMIT = "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2" +ORIGINAL_BLOB = "4e8e789d686b85a49fc12d36f87619eed705d6a8" +ORIGINAL_SHA256 = "bbaa32f9786f083409e363b081bfb7a1e597c8d32e4183c13a4105c2170934ce" +BASE_CERTIFICATE_SHA256 = "b7f0976e757998011f16022181246ad1b70db5b17ed32167f7e92368d2b43ee6" +SCREEN_HEIGHTS = (22, 25, 28) + + +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) + spec.loader.exec_module(module) + return module + + +def digest_file(path: Path) -> str: + return sha256(path.read_bytes()).hexdigest() + + +def unique_object(pairs): + out = {} + for key, value in pairs: + require(key not in out, f"duplicate JSON key: {key}") + out[key] = value + return out + + +def load_json_unique(path: Path) -> dict: + return json.loads(path.read_text(encoding="utf-8"), object_pairs_hook=unique_object) + + +def load_base_certificate_bytes() -> bytes: + return subprocess.check_output( + ["git", "show", f"{BASE_COMMIT}:certificates/sparse-fusion-audit.json"], + cwd=ROOT, + ) + + +def check_baseline_bytes() -> None: + original = subprocess.check_output( + ["git", "show", f"{BASE_COMMIT}:scripts/audit_sparse_fusion.py"], + cwd=ROOT, + ) + require(sha256(original).hexdigest() == ORIGINAL_SHA256, "base audit_sparse_fusion.py sha256 drift") + require( + subprocess.check_output( + ["git", "rev-parse", f"{BASE_COMMIT}:scripts/audit_sparse_fusion.py"], + cwd=ROOT, + ) + .decode() + .strip() + == ORIGINAL_BLOB, + "base audit_sparse_fusion.py blob drift", + ) + require( + (PACKAGE / "baseline.py").read_bytes() == original, + "baseline.py must be an exact copy of the base-commit source", + ) + + +def check_orbit_inventory() -> None: + for h in SCREEN_HEIGHTS: + reps = production.orbit_representatives(h) + require(len(reps) == 8, f"expected eight orbits at h={h}") + require(sum(weight for _, weight in reps) == comb(h, 3), f"orbit cover failed at h={h}") + lows = sorted(t & 7 for t, _ in reps) + require(lows == list(range(8)), f"orbit low masks incomplete at h={h}") + + +def check_screen_equivalence(baseline, optimized) -> list[dict]: + rows = [] + for h in SCREEN_HEIGHTS: + old = baseline.central_gate_screen(h) + new = optimized.central_gate_screen(h) + require(old == new, f"central_gate_screen receipt differs at h={h}") + require(old["triples"] == comb(h, 3), f"triple count wrong at h={h}") + require(old["joint_frame_pairs"] == 4096, f"joint pairs lost at h={h}") + rows.append(old) + return rows + + +def check_certificate_equivalence(baseline, optimized) -> dict: + old = serializable(baseline.certificate()) + new = serializable(optimized.certificate()) + require(old == new, "complete sparse-fusion certificate differs from baseline") + return new + + +def check_rejections(baseline, optimized) -> None: + for eng, name in ((baseline, "baseline"), (optimized, "optimized")): + try: + eng.central_gate_screen(21) + raise AssertionError(f"{name} accepted h=21") + except ValueError as exc: + require("admissible" in str(exc).lower(), str(exc)) + try: + production.orbit_representatives(21) + raise AssertionError("orbit_representatives accepted h=21") + except ValueError as exc: + require("admissible" in str(exc).lower(), str(exc)) + + +def check_temp_corruption(optimized) -> None: + with tempfile.TemporaryDirectory(prefix="sparse-fusion-orbits-prod-") as tmp: + dest = Path(tmp) / "audit_sparse_fusion.py" + shutil.copy2(SCRIPTS / "audit_sparse_fusion.py", dest) + text = dest.read_text(encoding="utf-8") + # Force every orbit weight to 1 so the unary sum undercounts while the + # v=C(h,3) baseline stays large; the proved lower-bound require fails. + mutated = text.replace( + "comb(h - 3, 3 - low.bit_count())", + "1", + 1, + ) + require(mutated != text, "mutation did not edit production source text") + dest.write_text(mutated, encoding="utf-8") + mutant = load_module(dest, "audit_sparse_fusion_mutant") + try: + mutant.central_gate_screen(25) + raise AssertionError("weight-omission mutant accepted the h=25 screen") + except ValueError as exc: + require( + "lower bound" in str(exc).lower() or "central-frame" in str(exc).lower(), + str(exc), + ) + # Live production path still accepts the historical screen. + optimized.central_gate_screen(25) + + +def check_certificate(write: bool, regenerated: dict) -> None: + path = ROOT / "certificates" / "sparse-fusion-audit.json" + text = json.dumps(regenerated, indent=2, sort_keys=True) + "\n" + if write: + path.write_text(text, encoding="utf-8") + committed = path.read_text(encoding="utf-8") + require( + committed == text, + "working certificates/sparse-fusion-audit.json does not match regenerated certificate()", + ) + load_json_unique(path) + base = load_base_certificate_bytes() + require(sha256(base).hexdigest() == BASE_CERTIFICATE_SHA256, "base certificate sha256 drift") + # This audit has no source_sha256 map; the mathematical certificate must + # remain byte-identical to the base after the production wiring. + require(committed.encode("utf-8") == base, "certificate bytes changed after orbit wiring") + require( + digest_file(SCRIPTS / "audit_sparse_fusion.py") != ORIGINAL_SHA256, + "production source unexpectedly unchanged", + ) + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--write-certificate", + action="store_true", + help="rewrite certificates/sparse-fusion-audit.json (default: read-only check)", + ) + args = parser.parse_args(argv) + + check_baseline_bytes() + check_orbit_inventory() + baseline = load_module(PACKAGE / "baseline.py", "audit_sparse_fusion_baseline") + screens = check_screen_equivalence(baseline, production) + regenerated = check_certificate_equivalence(baseline, production) + check_rejections(baseline, production) + check_temp_corruption(production) + check_certificate(write=args.write_certificate, regenerated=regenerated) + print( + "PASS_SPARSE_FUSION_ORBITS_PRODUCTION " + f"screen_heights={list(SCREEN_HEIGHTS)} " + f"screen_cases={len(screens)} " + "certs=1 no_new_kappa" + ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/audit_sparse_fusion.py b/scripts/audit_sparse_fusion.py index 4e8e789d68..adcadd25d8 100644 --- a/scripts/audit_sparse_fusion.py +++ b/scripts/audit_sparse_fusion.py @@ -6,7 +6,8 @@ """ from collections import deque from fractions import Fraction as Q -from itertools import combinations, product +from itertools import product +from math import comb import json from pathlib import Path @@ -16,6 +17,21 @@ ROOT=Path(__file__).resolve().parents[1] +def orbit_representatives(h): + """Weight-three indicators for spectator orbits fixing the first three axes. + + Production form of research/sparse-fusion-orbits/: permutations that fix + coordinates 0,1,2 conjugate Q=diag(S,I) to itself, so every triple with the + same low three bits shares one rank. Multiplicity is C(h-3, 3-wt(low)). + """ + require(h >= 22, 'Use the admissible complex family') + return tuple( + (low | (((1 << (3 - low.bit_count())) - 1) << 3), + comb(h - 3, 3 - low.bit_count())) + for low in range(8) + ) + + def parity(value): return value.bit_count()%2 @@ -120,10 +136,14 @@ def central_gate_screen(h=25): The written proof covers every symmetric polar matrix Q. This bounded screen checks all symmetric 3x3 changes embedded in the original I_h. It is not a search over new gate topologies or coupled frame changes. + + Unary ranks use exact spectator-orbit representatives (equivalent to the + historical full weight-three enumeration); joint pairs and every require + remain unchanged. """ require(h>=22,'Use the admissible complex family') - triples=[sum(1<>i&1 else 0) - for i,col in enumerate(Qcols)])+r for t in triples) + unary=sum(weight*(binary_rank([col^(t if t>>i&1 else 0) + for i,col in enumerate(Qcols)])+r) + for t,weight in triples) frames.append((Qcols,k,r,unary)) if r==0:continue actual=unary+2*centers*k From a98f0fd3e9c9cb48b4298cf964508996c7a237bc Mon Sep 17 00:00:00 2001 From: Wentao Li Date: Thu, 15 Oct 2026 00:57:55 +0000 Subject: [PATCH 2/2] Record sparse-fusion orbit production benchmark medians and README timings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Five alternating fresh-process pairs on Linux/CPython 3.12.3: screen-only 15.05× and complete certificate 10.07× with identical receipts. --- .../sparse-fusion-orbits-production/README.md | 5 +- .../RESULT.json | 142 ++++++++++++++++++ 2 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 research/sparse-fusion-orbits-production/RESULT.json diff --git a/research/sparse-fusion-orbits-production/README.md b/research/sparse-fusion-orbits-production/README.md index b39e9ccd52..75a4d9f799 100644 --- a/research/sparse-fusion-orbits-production/README.md +++ b/research/sparse-fusion-orbits-production/README.md @@ -38,9 +38,8 @@ must still match the base bytes. Timing is host-descriptive and is not a correctness gate. On Linux / CPython 3.12.3, five alternating fresh-process pairs gave median -**screen-only 0.559 → 0.041 s (≈13.6×)** and **complete certificate 0.568 → -0.054 s (≈10.5×)** in the orientation profile; retained samples are written by -`benchmark.py` into [`RESULT.json`](RESULT.json). +**screen-only 0.661 → 0.044 s (15.05×)** and **complete certificate 0.608 → +0.060 s (10.07×)**. Retained samples are in [`RESULT.json`](RESULT.json). ## Why the orbits are equivalent diff --git a/research/sparse-fusion-orbits-production/RESULT.json b/research/sparse-fusion-orbits-production/RESULT.json new file mode 100644 index 0000000000..84522e6c6c --- /dev/null +++ b/research/sparse-fusion-orbits-production/RESULT.json @@ -0,0 +1,142 @@ +{ + "ai_assistance": "Substantial AI assistance for orientation, overlap search, profiling, production wiring, packaging, benchmarking and writing. Not independent human peer review.", + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "complete_certificate": { + "median_baseline_seconds": 0.6076670360000662, + "median_optimized_seconds": 0.060372408999910476, + "median_ratio": 10.065310397022046, + "rounds": 5, + "samples": [ + { + "baseline_seconds": 0.6030950699999948, + "optimized_seconds": 0.0608979090000048, + "order": [ + "baseline", + "optimized" + ], + "ratio": 9.903378948527564, + "round": 0 + }, + { + "baseline_seconds": 0.7542092740000044, + "optimized_seconds": 0.05746237099992868, + "order": [ + "optimized", + "baseline" + ], + "ratio": 13.125272432648845, + "round": 1 + }, + { + "baseline_seconds": 0.6360726619999468, + "optimized_seconds": 0.060372408999910476, + "order": [ + "baseline", + "optimized" + ], + "ratio": 10.535817147877767, + "round": 2 + }, + { + "baseline_seconds": 0.6076670360000662, + "optimized_seconds": 0.060805378999930326, + "order": [ + "optimized", + "baseline" + ], + "ratio": 9.993639477204187, + "round": 3 + }, + { + "baseline_seconds": 0.581783529000063, + "optimized_seconds": 0.05653849500004071, + "order": [ + "baseline", + "optimized" + ], + "ratio": 10.290042722213318, + "round": 4 + } + ], + "scope": "certificate" + }, + "engines": { + "baseline": "research/sparse-fusion-orbits-production/baseline.py", + "optimized": "scripts/audit_sparse_fusion.py" + }, + "environment": { + "cpu_affinity_set": false, + "executable": "/usr/bin/python3.12", + "implementation": "CPython", + "os_caches_flushed": false, + "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]" + }, + "no_new_kappa": true, + "predecessor": "research/sparse-fusion-orbits/", + "screen_only": { + "median_baseline_seconds": 0.6611210399998981, + "median_optimized_seconds": 0.04393979999997555, + "median_ratio": 15.046063932932467, + "rounds": 5, + "samples": [ + { + "baseline_seconds": 0.61670235400004, + "optimized_seconds": 0.04277718100001948, + "order": [ + "baseline", + "optimized" + ], + "ratio": 14.416619786136893, + "round": 0 + }, + { + "baseline_seconds": 0.672001172000023, + "optimized_seconds": 0.0456580989999793, + "order": [ + "optimized", + "baseline" + ], + "ratio": 14.718115443227884, + "round": 1 + }, + { + "baseline_seconds": 0.6611210399998981, + "optimized_seconds": 0.04393979999997555, + "order": [ + "baseline", + "optimized" + ], + "ratio": 15.046063932932467, + "round": 2 + }, + { + "baseline_seconds": 0.6881904790000135, + "optimized_seconds": 0.04753297199999906, + "order": [ + "optimized", + "baseline" + ], + "ratio": 14.478170626486959, + "round": 3 + }, + { + "baseline_seconds": 0.6025585070000261, + "optimized_seconds": 0.04304783800000678, + "order": [ + "baseline", + "optimized" + ], + "ratio": 13.997416246547184, + "round": 4 + } + ], + "scope": "screen" + }, + "source_sha256": { + "baseline.py": "bbaa32f9786f083409e363b081bfb7a1e597c8d32e4183c13a4105c2170934ce", + "research/sparse-fusion-orbits/accelerator.py": "17e5c373f6a45afb47e99219edec7f3aaf76facaeb0c42797683a0690d1c0fcd", + "scripts/audit_sparse_fusion.py": "6d1997fba802a8fc41099996b29e3add5d2b4f904da02548a98bed32c50aa773" + }, + "status": "PASS_IDENTICAL_SPARSE_FUSION_ORBITS_PRODUCTION_RECEIPTS" +}