diff --git a/research/complex-center-quarter/SOURCES.json b/research/complex-center-quarter/SOURCES.json index ebddee64ac..d66153dde8 100644 --- a/research/complex-center-quarter/SOURCES.json +++ b/research/complex-center-quarter/SOURCES.json @@ -20,10 +20,6 @@ "mode": "bytes", "sha256": "36e9e421230c4cb7b6a537d76a4bdfb6f667730d383e56062d4e45957484ab9e" }, - "research/complex-k492-owner-repair/code/hpe_audit_local.py": { - "mode": "bytes", - "sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" - }, "research/complex-k492-owner-repair/code/hpe_emit_local.py": { "mode": "bytes", "sha256": "7e4a6fbc38c8228157b6311457d1496bf460291393043932d2c365f004f77805" @@ -63,6 +59,10 @@ "research/complex-k492-owner-repair/code/invoice_allcold.py": { "mode": "bytes", "sha256": "141bd2fd58bbfb5b8d0fc8f56f61c45586d5608a5af3487c6b883dd987f998ec" + }, + "research/complex-sw4-frame8/local/hpe_audit_local.py": { + "mode": "bytes", + "sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" } } } diff --git a/research/complex-center-quarter/verify.py b/research/complex-center-quarter/verify.py index 67c196fdef..bf00a9a9b0 100644 --- a/research/complex-center-quarter/verify.py +++ b/research/complex-center-quarter/verify.py @@ -23,7 +23,7 @@ SELECTED = "certificates/selected-result.json" SPEC = "research/complex-k492-owner-repair/data/SPEC.json" INVENTORY = "research/community-k492-audit/SELECTED-SOURCE.json" -AUDITOR = "research/complex-k492-owner-repair/code/hpe_audit_local.py" +AUDITOR = "research/complex-sw4-frame8/local/hpe_audit_local.py" EMITTER = "research/complex-k492-owner-repair/code/hpe_emit_local.py" INVOICE = "research/complex-k492-owner-repair/code/invoice_allcold.py" REPLAY = "research/community-k492-audit/pr626/replay/mixed-global/base/providers" @@ -67,8 +67,15 @@ def check_sources(): require(selection["audited_source_head"] == pins["reviewed_heads"]["626"], "selected head") for pr, head in pins["reviewed_heads"].items(): require(selection["reviewed_dependency_heads"][pr] == head, "reviewed head: " + pr) + inventory_keys = { + SPEC: SPEC, + AUDITOR: "research/complex-k492-owner-repair/code/hpe_audit_local.py", + EMITTER: EMITTER, + INVOICE: INVOICE, + } for rel in (SPEC, AUDITOR, EMITTER, INVOICE): - require(inventory["files"][rel] == pins["files"][rel]["sha256"], "inventory pin: " + rel) + require(inventory["files"][inventory_keys[rel]] == pins["files"][rel]["sha256"], + "inventory pin: " + rel) for name in PROVIDERS: desc = spec["providers"][name] for filename in ("CANONICAL-WORD.json.gz", "LOCAL-PROGRAMS.json.gz"): diff --git a/research/complex-k492-owner-repair/code/hpe_audit_local.py b/research/complex-k492-owner-repair/code/hpe_audit_local.py index 17bccb64fd..2de8e2f9ef 100644 --- a/research/complex-k492-owner-repair/code/hpe_audit_local.py +++ b/research/complex-k492-owner-repair/code/hpe_audit_local.py @@ -5,6 +5,65 @@ import copy,gzip,hashlib,json,sys from collections import Counter from fractions import Fraction as Q + +# Production integer-row acceleration from research/emitted-local-integer-replay-seed90. +# Identical receipts to pairwise Fraction-dict rows; see research/emitted-local-integer-production/. +class Row: + """Sparse integer numerators divided by 2**exponent.""" + + def __init__(self, values=None): + self.values = {} + self.exponent = 0 + if values: + self.values = {k: int(v) for k, v in values.items()} + if any((Q(v).denominator != 1 for v in values.values())): + raise ValueError('initial Row must be integral') + + def clone(self): + result = Row() + result.values = self.values.copy() + result.exponent = self.exponent + return result + + def scale(self, q): + a, b = (q.numerator, q.denominator) + if b & b - 1: + raise ValueError('non-dyadic row scale') + result = self.clone() + result.exponent += b.bit_length() - 1 + result.values = {k: a * v for k, v in self.values.items()} + return result + + def add_scaled(self, other, q): + a, b = (q.numerator, q.denominator) + if b & b - 1: + raise ValueError('non-dyadic row addition') + source_exp = other.exponent + b.bit_length() - 1 + exponent = max(self.exponent, source_exp) + left_shift = exponent - self.exponent + right_shift = exponent - source_exp + if left_shift: + self.values = {k: v << left_shift for k, v in self.values.items()} + for k, v in other.values.items(): + total = self.values.get(k, 0) + (a * v << right_shift) + if total: + self.values[k] = total + else: + self.values.pop(k, None) + self.exponent = exponent + + def __bool__(self): + return bool(self.values) + + def __eq__(self, other): + if isinstance(other, Row): + exponent = max(self.exponent, other.exponent) + return {k: v << exponent - self.exponent for k, v in self.values.items()} == {k: v << exponent - other.exponent for k, v in other.values.items()} + if isinstance(other, dict): + if set(self.values) != set(other): + return False + return all((v * Q(other[k]).denominator == Q(other[k]).numerator * (1 << self.exponent) for k, v in self.values.items())) + return NotImplemented from pathlib import Path OUT=Path(sys.argv[1]) c=json.load(gzip.open(OUT/'CANONICAL-WORD.json.gz')) @@ -25,7 +84,7 @@ def contains(a,b): # COLD-HPE: cold helpers (start frame 0) ending at U carry the (0, U) wrappers too; without cold ends wrapped == entering cold=sorted(hpe-set(entering));wrapped=sorted(set(entering)|hpe);plain={r for r in range(n) if r not in set(wrapped)} def local(events,back): - rows={('L',r):{r:Q(1)} for r in range(n)} + rows={('L',r):Row({r:1}) for r in range(n)} norm={('L',r):Q(1) for r in range(n)};prefix=Q(1);cur=c['start'].copy();private={} hist=Counter();phases=[];entry=[];exit=[];centers=[];matrix_hash=hashlib.sha256();chain={};wrappers=[] wset=set(wrapped);pre_seen=set();post_seen=set() # WRAPPER ORDER (Lemma A): R^-1 precedes, L^-1 follows, every scalar touching a wrapped helper @@ -76,12 +135,12 @@ def local(events,back): else: if r==target and r not in private:private[r]=f assert private[r]==f - if op=='clear':rows[target]={};norm[target]=Q(0) - elif op=='copy':rows[target]=dict(rows[source]);norm[target]=norm[source] + if op=='clear':rows[target]=Row();norm[target]=Q(0) + elif op=='copy':rows[target]=rows[source].clone();norm[target]=norm[source] elif op=='scale': q=Q(e[2],e[3]);a,b=abs(q.numerator),q.denominator assert a&(a-1)==0 and b&(b-1)==0 - rows[target]={j:q*x for j,x in rows[target].items()};norm[target]*=abs(q) + rows[target]=rows[target].scale(q);norm[target]*=abs(q) else: q=Q(e[3],e[4]);a,b=abs(q.numerator),q.denominator assert source!=target and b&(b-1)==0 @@ -91,11 +150,8 @@ def local(events,back): assert Q(w,b)*(1 if q>0 else -1)==q prefix=max(prefix,Q(a)*norm[source]) norm[target]=norm.get(target,Q(0))+abs(q)*norm[source] - row=rows.setdefault(target,{}) - for j,x in list(rows[source].items()): - z=row.get(j,Q(0))+q*x - if z:row[j]=z - else:row.pop(j,None) + row=rows.setdefault(target,Row()) + row.add_scaled(rows[source],q) prefix=max(prefix,norm[target]) else:raise AssertionError(tag) assert phases==allowed and set(centers)==set(range(len(c['centers']))) and not private @@ -122,6 +178,7 @@ def local(events,back): assert dict(profiles[name])=={int(r):z for r,z in c['local_profile'].items()} print('independent emitted replay PASS',name,flush=True) controls=[] +_encoded_program=json.dumps(ir['local_programs']['forward']) for name,mut in [ ('wrong_scale',lambda es:next(e for e in es if e[0]=='scalar' and e[1][0]=='scale')[1].__setitem__(2,3)), ('missing_center',lambda es:es.pop(next(i for i,e in enumerate(es) if e[0]=='center'))), @@ -155,7 +212,7 @@ def local(events,back): ('cold_hpe_post_wrapper_wrong_terminal_frame',lambda es:next(e for e in es if e[0]=='residual_adapter' and e[1]=='post' and e[2]==cold[0]).__setitem__(4,1)), ('cold_hpe_premix_gate_before_pre_wrapper',lambda es:(lambda ev:es.insert(next(i for i,e in enumerate(es) if e[0]=='residual_adapter' and e[1]=='pre' and e[2]==cold[0]),ev))(es.pop(next(i for i,e in enumerate(es) if e[0]=='scalar' and (('L',cold[0]) in [tuple(e[1][1])]+([tuple(e[1][2])] if e[1][0] in ('add','copy') else []))))) ), ] if cold else []): - es=copy.deepcopy(ir['local_programs']['forward']);mut(es) + es=json.loads(_encoded_program);mut(es) try:local(es,False) except (AssertionError,KeyError):controls.append(name) else:raise AssertionError('mutation accepted: '+name) diff --git a/research/complex-signed-prefix-audit/SOURCES.json b/research/complex-signed-prefix-audit/SOURCES.json index 8c592e4c83..bae6a09722 100644 --- a/research/complex-signed-prefix-audit/SOURCES.json +++ b/research/complex-signed-prefix-audit/SOURCES.json @@ -28,9 +28,10 @@ }, { "path": "research/complex-k492-owner-repair/code/hpe_audit_local.py", - "usage": "input", + "usage": "provenance", "git_blob": "17bccb64fdca54f329a3ce16e369449cb76c2802", - "sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" + "sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810", + "note": "Pairwise-era digest retained as provenance after research/emitted-local-integer-production/; working k492 checker ships integer rows. Live checker retargeted to complex-sw4-frame8/local/hpe_audit_local.py (SELECTED-SOURCE-bound, still pairwise)." }, { "path": "research/gauge44-slots-t16/code/invoice_allcold.py", @@ -49,6 +50,13 @@ "usage": "input", "git_blob": "a94a2ac168c088a1282ea411766bc859178620df", "sha256": "1cbce5cf0ff0152f71e8ae7bef25841d1ce13010af248ff7209182d2328c21c9" + }, + { + "path": "research/complex-sw4-frame8/local/hpe_audit_local.py", + "usage": "input", + "git_blob": "17bccb64fdca54f329a3ce16e369449cb76c2802", + "sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810", + "note": "SELECTED-SOURCE-bound local checker; byte-identical to pairwise-era k492 hpe_audit_local.py." } ] } diff --git a/research/complex-signed-prefix-audit/VERIFY.json b/research/complex-signed-prefix-audit/VERIFY.json index 6842edcfe5..20a775172b 100644 --- a/research/complex-signed-prefix-audit/VERIFY.json +++ b/research/complex-signed-prefix-audit/VERIFY.json @@ -6,10 +6,10 @@ "inputs": [ "research/community-frontier1094-audit/SELECTED-SOURCE.json", "research/community-frontier1094-audit/selected-replay.tar.gz", - "research/complex-k492-owner-repair/code/hpe_audit_local.py", "research/gauge44-slots-t16/code/invoice_allcold.py", "research/e8-lemma-g-lean/PROOF.md", - "research/hyperplane-end-lean/PROOF.md" + "research/hyperplane-end-lean/PROOF.md", + "research/complex-sw4-frame8/local/hpe_audit_local.py" ], "commands": [ { diff --git a/research/complex-signed-prefix-audit/verify.py b/research/complex-signed-prefix-audit/verify.py index 9b9acbff43..d70b21e07f 100644 --- a/research/complex-signed-prefix-audit/verify.py +++ b/research/complex-signed-prefix-audit/verify.py @@ -17,7 +17,7 @@ ROOT = PACKAGE.parent.parent ARCHIVE = "research/community-frontier1094-audit/selected-replay.tar.gz" MANIFEST = "research/community-frontier1094-audit/SELECTED-SOURCE.json" -LOCAL_CHECKER = "research/complex-k492-owner-repair/code/hpe_audit_local.py" +LOCAL_CHECKER = "research/complex-sw4-frame8/local/hpe_audit_local.py" INVOICE = "research/gauge44-slots-t16/code/invoice_allcold.py" BASE = "candidate/strict/global/base/providers/gauge44/" INPUTS = {ARCHIVE, MANIFEST, LOCAL_CHECKER, INVOICE, diff --git a/research/complex-stage-diagonal-normalization-seed24/SOURCES.json b/research/complex-stage-diagonal-normalization-seed24/SOURCES.json index 7b7374290e..7b2c190a21 100644 --- a/research/complex-stage-diagonal-normalization-seed24/SOURCES.json +++ b/research/complex-stage-diagonal-normalization-seed24/SOURCES.json @@ -2,6 +2,6 @@ "research/community-frontier1042-audit/ASSEMBLY.json": "093f35445812ea96fe1bfe6a3af7d769cb7f274e08f4fb30f71a17ed1161e54e", "research/community-frontier1042-audit/selected-replay.tar.gz": "22c3f4dce4b897a1d423d1388801933e288b6a6b1906cb15e1b16a5eb68db754", "research/complex-dyadic-lowering/lower.py": "eb37d00063dc09323e9aca041d23da749ce17fbd71dade9aaf1c059cab0b9753", - "research/complex-k492-owner-repair/code/hpe_audit_local.py": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810", - "research/complex-k492-owner-repair/code/hpe_emit_local.py": "7e4a6fbc38c8228157b6311457d1496bf460291393043932d2c365f004f77805" + "research/complex-k492-owner-repair/code/hpe_emit_local.py": "7e4a6fbc38c8228157b6311457d1496bf460291393043932d2c365f004f77805", + "research/complex-sw4-frame8/local/hpe_audit_local.py": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" } diff --git a/research/complex-stage-diagonal-normalization-seed24/verify.py b/research/complex-stage-diagonal-normalization-seed24/verify.py index 71a4a1cecf..e0bc0b7e51 100644 --- a/research/complex-stage-diagonal-normalization-seed24/verify.py +++ b/research/complex-stage-diagonal-normalization-seed24/verify.py @@ -7,7 +7,7 @@ from pathlib import Path HERE=Path(__file__).resolve().parent;ROOT=HERE.parents[1] ARCHIVE='research/community-frontier1042-audit/selected-replay.tar.gz' -CHECKER='research/complex-k492-owner-repair/code/hpe_audit_local.py' +CHECKER='research/complex-sw4-frame8/local/hpe_audit_local.py' LOWER='research/complex-dyadic-lowering/lower.py' HORNER='research/complex-k492-owner-repair/code/hpe_emit_local.py' REQUIRED={ARCHIVE,CHECKER,LOWER,HORNER,'research/community-frontier1042-audit/ASSEMBLY.json'} diff --git a/research/dyadic-fractional-grid/SOURCES.json b/research/dyadic-fractional-grid/SOURCES.json index 58d46ada74..eace936f12 100644 --- a/research/dyadic-fractional-grid/SOURCES.json +++ b/research/dyadic-fractional-grid/SOURCES.json @@ -15,10 +15,11 @@ "git_blob_of_committed_file": "534fdc71f7641c704575efc038363d7eb206b2df" }, { - "path": "research/complex-k492-owner-repair/code/hpe_audit_local.py", + "path": "research/complex-sw4-frame8/local/hpe_audit_local.py", "encoding": "file", "sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810", - "git_blob_of_committed_file": "17bccb64fdca54f329a3ce16e369449cb76c2802" + "git_blob_of_committed_file": "17bccb64fdca54f329a3ce16e369449cb76c2802", + "note": "Retargeted to SELECTED-SOURCE-bound pairwise checker after research/emitted-local-integer-production/ rewrote k492 hpe_audit_local.py." }, { "path": "research/complex-k492-owner-repair/code/invoice_allcold.py", diff --git a/research/dyadic-horner-direction/SOURCES.json b/research/dyadic-horner-direction/SOURCES.json index 9825196b85..06abb0a068 100644 --- a/research/dyadic-horner-direction/SOURCES.json +++ b/research/dyadic-horner-direction/SOURCES.json @@ -19,9 +19,13 @@ "sha256": "7e4a6fbc38c8228157b6311457d1496bf460291393043932d2c365f004f77805" }, { - "path": "research/complex-k492-owner-repair/code/hpe_audit_local.py", + "path": "research/complex-sw4-frame8/local/hpe_audit_local.py", "encoding": "file", - "sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" + "sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810", + "archived_paths": [ + "research/complex-sw4-frame8/local/hpe_audit_local.py" + ], + "note": "Retargeted to SELECTED-SOURCE-bound pairwise checker after research/emitted-local-integer-production/." }, { "path": "research/complex-k492-owner-repair/code/invoice_allcold.py", diff --git a/research/emitted-local-integer-production/NOTICE.md b/research/emitted-local-integer-production/NOTICE.md new file mode 100644 index 0000000000..a7db270a1a --- /dev/null +++ b/research/emitted-local-integer-production/NOTICE.md @@ -0,0 +1,16 @@ +# Notice + +Production wiring of the exact shared-denominator integer-row emitted-local +audit into `research/complex-k492-owner-repair/code/hpe_audit_local.py`. + +## Credit + +- woklerx / [CrocSwap/integer-mult-bounds#1184](https://github.com/CrocSwap/integer-mult-bounds/pull/1184) + (`research/emitted-local-integer-replay-seed90/`): proved opt-in integer rows + with identical complete local-audit receipts. +- icekylinx for the independent local checker lineage retained in PR514/PR433 + and later cold14/k492 packages. +- Shared-denominator representation follows prior PR367/824/1137/1156 work. + +Prepared by Wentao Li (VictorLiwentao, @Is__Victor, wentaol4@illinois.edu) +with substantial AI assistance. Apache-2.0. diff --git a/research/emitted-local-integer-production/README.md b/research/emitted-local-integer-production/README.md new file mode 100644 index 0000000000..8002582d0a --- /dev/null +++ b/research/emitted-local-integer-production/README.md @@ -0,0 +1,95 @@ +# Production integer-row emitted local audit + +**Tooling improvement; no new kappa.** At base +`0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2`, +`research/complex-k492-owner-repair/code/hpe_audit_local.py` still stored every +scalar row as a dictionary of `Fraction` values. woklerx’s opt-in adapter +`research/emitted-local-integer-replay-seed90/` (incorporated +[#1184](https://github.com/CrocSwap/integer-mult-bounds/pull/1184)) already +proved shared-denominator sparse integer rows with identical complete local-audit +receipts. This package wires that equivalent rewrite into the **production** +k492 checker used by emitted-local tooling. + +SELECTED-SOURCE-bound +`research/complex-sw4-frame8/local/hpe_audit_local.py` copies are intentionally +left pairwise so the selected inventory stays untouched. Dependent VERIFY +packages that previously live-pinned the k492 path retarget to that sw4 checker. + +## Reproduce + +Python **3.12**, standard library only, from the repository root: + +```sh +python3.12 -I -B research/emitted-local-integer-production/verify.py +python3.12 -I -O -B research/emitted-local-integer-production/verify.py +python3.12 -B scripts/research_package.py --package research/emitted-local-integer-production +taskset -c 0 python3.12 -I -B research/emitted-local-integer-production/benchmark.py --rounds 5 --write-result +``` + +Expected: + +```text +PASS_EMITTED_LOCAL_INTEGER_PRODUCTION assertions=… controls=25 corruption=… certs=1 no_new_kappa +PASS_REGISTERED_RESEARCH_PACKAGE research/emitted-local-integer-production outcome=completed +PASS_IDENTICAL_EMITTED_LOCAL_INTEGER_PRODUCTION_RECEIPTS +``` + +Default verify is read-only. Temp-copy ADD-drop foil rejects via audit failure +or receipt divergence. Package gates under `-O` still launch asserting checker +children (`python -B` with `PYTHONOPTIMIZE` cleared). 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 with `taskset -c 0`, five alternating fresh-process +pairs gave median complete selected-R480 local-audit wall time **7.080 → 3.131 s (2.26×)**. Details are in +[`RESULT.json`](RESULT.json). Timing is host-descriptive and is not a +correctness gate. Every receipt matches digest +`13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17` +(25 retained negative controls). + +## Why the integer rows are equivalent + +Each row stores integer numerators over a shared power-of-two denominator +(`2**exponent`). Scale and ADD updates shift exponents exactly when the +coefficient is dyadic, matching `Fraction` arithmetic on this dyadic scalar +macro language. Zero entries are omitted just as in the original dictionaries. +JSON mutation fixtures are decoded once and reloaded per control, preserving +the original deepcopy isolation. See +`research/emitted-local-integer-replay-seed90/PROOF.md`. + +## Overlap and credit + +Closest priors (different delivery): + +- `research/emitted-local-integer-replay-seed90/` / [#1184](https://github.com/CrocSwap/integer-mult-bounds/pull/1184) + — opt-in integer rows; this 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, #2039/#2054 + shared-point, #2100 ternary, #2117 DisjointTensor, #2150 mixed-point, + #2194/#2210/#2231/#2239/#2257/#2263/#2276/#2320/#2329/#2348 production + rewrites; #1076 quadratic-affine) was not reopened. + +Credit woklerx, icekylinx, and the retained local-checker lineage. 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 the SELECTED-SOURCE-bound sw4 `hpe_audit_local.py` + copies adopt the same integer-row rewrite with a coordinated + `SELECTED-SOURCE.json` digest refresh? + **Why it matters:** Selected cold-chain local-replay still runs the pairwise + checker. + **First step:** Enumerate SELECTED-SOURCE paths with sha256 `6bd9a1e2…` and + dependent VERIFY binders. + **Blocked by:** Maintainer inventory-refresh preference. + +2. **Question:** Should other byte-identical vendored `hpe_audit_local.py` + copies adopt the same rewrite? + **Why it matters:** Historical trees still pin pairwise-era digests. + **First step:** Diff each copy against the production transform site. + **Blocked by:** One-object stop rule. diff --git a/research/emitted-local-integer-production/RESULT.json b/research/emitted-local-integer-production/RESULT.json new file mode 100644 index 0000000000..e175daa239 --- /dev/null +++ b/research/emitted-local-integer-production/RESULT.json @@ -0,0 +1,77 @@ +{ + "status": "PASS_IDENTICAL_EMITTED_LOCAL_INTEGER_PRODUCTION_RECEIPTS", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "platform": "Linux-6.12.94+-x86_64-with-glibc2.39", + "rounds": 5, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17", + "baseline_median_seconds": 7.080149261000088, + "production_median_seconds": 3.1314290130000018, + "median_ratio": 2.2609962517454916, + "samples": [ + [ + { + "engine": "baseline", + "seconds": 7.247105462000036, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + }, + { + "engine": "production", + "seconds": 3.2579698360000293, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + } + ], + [ + { + "engine": "production", + "seconds": 3.2883312999999816, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + }, + { + "engine": "baseline", + "seconds": 6.848966455999971, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + } + ], + [ + { + "engine": "baseline", + "seconds": 6.73192682399997, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + }, + { + "engine": "production", + "seconds": 3.0631277979999822, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + } + ], + [ + { + "engine": "production", + "seconds": 3.0750692359999903, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + }, + { + "engine": "baseline", + "seconds": 7.080149261000088, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + } + ], + [ + { + "engine": "baseline", + "seconds": 7.135924542999987, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + }, + { + "engine": "production", + "seconds": 3.1314290130000018, + "receipt_sha256": "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + } + ] + ], + "implementation_sha256": { + "baseline.py": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810", + "production": "cbf68feab9fcf57d8d5ed8a525a8f8cd5d79b2a61faf98cff672e137a3bcf99f", + "benchmark.py": "fde0c5500a24cef9e0c29170d39dd76ca6ee595d7a1243a649ee6f03b5b3eafc" + } +} diff --git a/research/emitted-local-integer-production/SOURCES.json b/research/emitted-local-integer-production/SOURCES.json new file mode 100644 index 0000000000..f6709e660a --- /dev/null +++ b/research/emitted-local-integer-production/SOURCES.json @@ -0,0 +1,37 @@ +{ + "schema_version": 1, + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "e8870e5917057d59b730eb14721a778639eca050", + "sha256": "d46eb6d5b3e279428753d770653663fbdf1063e55c255ea073d768f344927ef7" + }, + { + "path": "research/complex-k492-owner-repair/code/hpe_audit_local.py", + "usage": "provenance", + "git_blob": "17bccb64fdca54f329a3ce16e369449cb76c2802", + "sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810", + "note": "Pairwise-era production bytes at base_commit; working tree carries the integer-row rewrite. Live equivalence uses package baseline.py plus working production path." + }, + { + "path": "research/community-frontier1042-audit/selected-replay.tar.gz", + "usage": "input", + "git_blob": "6f4dc6fe7631d8aacf8081fcaecf32197181685b", + "sha256": "22c3f4dce4b897a1d423d1388801933e288b6a6b1906cb15e1b16a5eb68db754" + }, + { + "path": "research/emitted-local-integer-replay-seed90/fast.py", + "usage": "input", + "git_blob": "1ba70ce834ddf4838b81cd48b9ca871fea39d9a2", + "sha256": "1c4d791dd7a2113f0069681502174e866b5bc6c7fe34f738f6d00efccbf1b96b" + } + ] +} diff --git a/research/emitted-local-integer-production/TASK.json b/research/emitted-local-integer-production/TASK.json new file mode 100644 index 0000000000..5c9f723246 --- /dev/null +++ b/research/emitted-local-integer-production/TASK.json @@ -0,0 +1,70 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "priority_revision": 4, + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "chooser_seed": "57d4f6dd8c8917a4931ef1142801d65e", + "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 k492-owner-repair hpe_audit_local.py used by emitted-local audits adopt the proved exact shared-denominator integer rows from research/emitted-local-integer-replay-seed90/ so that shipped local-replay path is faster while every receipt field stays identical, without editing SELECTED-SOURCE-bound sw4 checker copies?", + "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 leave-alone production rewrites and remaining proved opt-in adapters. Leave-alone objects (joint frames, shared-point, mixed-point, ternary, parity-side, R420 rref/geometry/mutants, frameopt.close, leech_minor, verify_factor #2194, sparse-fusion, joint-dual replay, quadratic-affine for #1076, data_corners #2320, clifford_exact #2329, bit-hosted-digest #2348, e8-bit-r420 MANIFEST-only edits) were skipped. Wiring into SELECTED-SOURCE-bound complex-sw4-frame8 hpe_audit_local.py copies was rejected to keep the selected inventory untouched. woklerx's merged #1184 opt-in adapter already proved ~2.33\u00d7 on the complete selected R480 local audit with identical receipts; production research/complex-k492-owner-repair/code/hpe_audit_local.py still used Fraction-dict rows. This session wires that equivalent rewrite into the shipped k492 source, vendors pairwise baseline bytes, and demotes/retargets dependent VERIFY pins to the still-pairwise SELECTED-SOURCE sw4 checker.", + "bottleneck_link": "Side result on review throughput: emitted local replay appears across cold/gauge construction tooling. A faster identical receipt does not change kappa or the binding complex supplier.", + "budget_minutes": 60, + "stop_rule": "Ship an equivalence-preserving production hpe_audit_local.py integer-row change with frozen baseline, identical local-audit receipts, corruption controls, pin discipline, registered replay and a measured before/after median. Do not invent kappa, reopen leave-alone objects, or edit SELECTED-SOURCE-bound sw4 checker copies.", + "outcome": "completed", + "evidence": "PASS_EMITTED_LOCAL_INTEGER_PRODUCTION via research/emitted-local-integer-production/verify.py (also under -O); PASS_REGISTERED_RESEARCH_PACKAGE; PASS_IDENTICAL_EMITTED_LOCAL_INTEGER_PRODUCTION_RECEIPTS via pinned-CPU benchmark.py --rounds 5 (median 7.080\u21923.131 s, 2.261\u00d7); complex-signed-prefix-audit and selected1094-wire-prefix-audit demote the k492 live pin and retarget to complex-sw4-frame8/local/hpe_audit_local.py; emitted-local-integer-replay-seed90 vendors baseline.py and regenerates CERTIFICATE sources.", + "author": "Wentao Li", + "github": "VictorLiwentao", + "email": "wentaol4@illinois.edu", + "ai_assistance": "Substantial AI assistance for orientation, overlap search, profiling, production wiring, packaging, benchmarking and writing. Not independent human peer review.", + "open_questions": [ + { + "question": "Should the SELECTED-SOURCE-bound complex-sw4-frame8 hpe_audit_local.py copies adopt the same integer-row rewrite in a coordinated follow-up that updates SELECTED-SOURCE.json digests?", + "why_it_matters": "Selected cold-chain local-replay still runs the pairwise sw4 checker; accelerating it would shorten make frontier1094-verify without changing receipts.", + "first_step": "List every SELECTED-SOURCE path with sha256 6bd9a1e2\u2026 and the VERIFY packages that bind against those digests.", + "blocked_by": "Maintainer willingness to refresh the selected source inventory for an equivalence-preserving tooling change." + }, + { + "question": "Should other byte-identical vendored hpe_audit_local.py copies under research/*/code/ adopt the same integer rows?", + "why_it_matters": "Those trees still pin pairwise-era digests; a coordinated refresh would remove stale inventory digests without changing receipts.", + "first_step": "Diff each copy against the production transform site and list which SOURCE inventories would need provenance demotion or honest refresh.", + "blocked_by": "Out of this session's one-object stop rule." + } + ] +} diff --git a/research/emitted-local-integer-production/VERIFY.json b/research/emitted-local-integer-production/VERIFY.json new file mode 100644 index 0000000000..136d0ce5c4 --- /dev/null +++ b/research/emitted-local-integer-production/VERIFY.json @@ -0,0 +1,24 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/emitted-local-integer-production/baseline.py", + "research/complex-k492-owner-repair/code/hpe_audit_local.py", + "research/community-frontier1042-audit/selected-replay.tar.gz", + "research/emitted-local-integer-replay-seed90/fast.py" + ], + "commands": [ + { + "argv": ["{python}", "-I", "-B", "{package}/verify.py"], + "timeout_seconds": 180, + "checks": "Exact baseline copy of the base-commit hpe_audit_local.py; production equals the integer-row transform; identical complete local-audit receipts; temp-copy ADD-drop corruption control; duplicate JSON-key check; read-only default verify." + }, + { + "argv": ["{python}", "-I", "-O", "-B", "{package}/verify.py"], + "timeout_seconds": 180, + "checks": "Same equivalence and pin discipline under -O (require() gates remain; checker children still assert via python -B without PYTHONOPTIMIZE)." + } + ] +} diff --git a/research/emitted-local-integer-production/baseline.py b/research/emitted-local-integer-production/baseline.py new file mode 100644 index 0000000000..17bccb64fd --- /dev/null +++ b/research/emitted-local-integer-production/baseline.py @@ -0,0 +1,171 @@ +# Local-only extraction of the attributed PR514 / PR433 independent replay. +# Prepared for icekylinx with OpenAI Codex assistance. Apache-2.0. +# The complete local checker and its negative controls are retained verbatim. +# Global hosting is verified separately for the changed 112-port geometry. +import copy,gzip,hashlib,json,sys +from collections import Counter +from fractions import Fraction as Q +from pathlib import Path +OUT=Path(sys.argv[1]) +c=json.load(gzip.open(OUT/'CANONICAL-WORD.json.gz')) +ir={'local_programs':json.load(gzip.open(OUT/'LOCAL-PROGRAMS.json.gz'))} +v,R,h=c['v'],c['R'],c['h'];n=2*v+R;frames=c['frames'] +levels={int(t):f for t,f in c.get('target_levels',{}).items()} +entering=[r for r,f in enumerate(c['start']) if r>=2*v and f!=0] +plain={r for r in range(n) if r not in set(entering)} + +def contains(a,b): + for x in a: + for y in b: + if x>>(y.bit_length()-1)&1:x^=y + if x:return False + return True +hpe={r for r in range(2*v,n) if c['final'][r]!=1} # HPE: helpers whose terminal frame is a proper subspace U of FULL +assert all(len(frames[c['final'][r]])0 + hist[rank]+=1;cur[r]=b + elif tag=='center': + _,k,a,b,rank=event + assert phases[-1]=='centers' and private=={('C',k):a} + cf=c['center_frames'][k];cr=len(frames[cf]) + # GK: stepwise descent cf -> served levels -> lowest (forward), reversed ascent (backward); each step is a nested child + assert contains(frames[a],frames[b]) if back else contains(frames[b],frames[a]) + assert rank==abs(len(frames[a])-len(frames[b]))>0 + chain.setdefault(k,[]).append((a,b)) + private['C',k]=b;hist[rank]+=1;centers.append(k) + elif tag=='scalar': + _,e,f=event;op=e[0];target=tuple(e[1]);source=tuple(e[2]) if op in ('copy','add') else None + if target[0]=='C' and op=='clear': + assert private.get(target,f)==f + private.pop(target,None) + else: + for r in (target,source): + if r is None:continue + if r[0]=='L':assert cur[r[1]]==f and (r[1] not in wset or (r[1] in pre_seen and r[1] not in post_seen)),('common frame / wrapper order',r,cur[r[1]],f) + else: + if r==target and r not in private:private[r]=f + assert private[r]==f + if op=='clear':rows[target]={};norm[target]=Q(0) + elif op=='copy':rows[target]=dict(rows[source]);norm[target]=norm[source] + elif op=='scale': + q=Q(e[2],e[3]);a,b=abs(q.numerator),q.denominator + assert a&(a-1)==0 and b&(b-1)==0 + rows[target]={j:q*x for j,x in rows[target].items()};norm[target]*=abs(q) + else: + q=Q(e[3],e[4]);a,b=abs(q.numerator),q.denominator + assert source!=target and b&(b-1)==0 + # Independent symbolic replay of the cleared coefficient work. + w=0 + for bit in bin(a)[2:]:w=2*w+int(bit) + assert Q(w,b)*(1 if q>0 else -1)==q + prefix=max(prefix,Q(a)*norm[source]) + norm[target]=norm.get(target,Q(0))+abs(q)*norm[source] + row=rows.setdefault(target,{}) + for j,x in list(rows[source].items()): + z=row.get(j,Q(0))+q*x + if z:row[j]=z + else:row.pop(j,None) + prefix=max(prefix,norm[target]) + else:raise AssertionError(tag) + assert phases==allowed and set(centers)==set(range(len(c['centers']))) and not private + assert sorted(r for k,r,_ in wrappers if k=='pre')==wrapped and sorted(r for k,r,_ in wrappers if k=='post')==wrapped # GK + for k,st in chain.items(): # GK: the steps of each centre chain link up and end at the centre frame + cf=c['center_frames'][k] + if back:assert st[-1][1]==cf and all(st[i][1]==st[i+1][0] for i in range(len(st)-1)) + else:assert st[0][0]==cf and all(st[i][1]==st[i+1][0] for i in range(len(st)-1)) + assert all(not row for reg,row in rows.items() if reg[0]=='C') + for r in range(n): + expected={r:Q(1)} + if back and r None: + with tarfile.open(ARCHIVE) as archive: + for name in ("CANONICAL-WORD.json.gz", "LOCAL-PROGRAMS.json.gz"): + members = [m for m in archive.getmembers() if m.name == "slots/local/" + name] + (directory / name).write_bytes(archive.extractfile(members[0]).read()) + + +def clean_env(): + env = {k: v for k, v in os.environ.items() if k != "PYTHONOPTIMIZE"} + env["PYTHONDONTWRITEBYTECODE"] = "1" + return env + + +def run_once(engine: str, work: Path) -> dict: + source = BASELINE if engine == "baseline" else PRODUCTION + materialize(work) + start = time.perf_counter() + proc = subprocess.run( + [sys.executable, "-B", str(source), str(work)], + cwd=work, + env=clean_env(), + capture_output=True, + text=True, + ) + elapsed = time.perf_counter() - start + if proc.returncode != 0: + raise SystemExit(f"{engine} failed\n{proc.stderr}\n{proc.stdout}") + receipt = (work / "INDEPENDENT-LOCAL-REPLAY.json").read_bytes() + digest = hashlib.sha256(receipt.replace(b"\r\n", b"\n")).hexdigest() + if digest != RECEIPT_SHA256: + raise SystemExit(f"{engine} receipt digest {digest} != {RECEIPT_SHA256}") + json.loads(receipt.decode(), object_pairs_hook=unique_object) + return {"engine": engine, "seconds": elapsed, "receipt_sha256": digest} + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--rounds", type=int, default=5) + parser.add_argument( + "--write-result", + action="store_true", + help="write RESULT.json (default prints only; use explicitly to refresh the artifact)", + ) + args = parser.parse_args(argv) + samples = [] + with tempfile.TemporaryDirectory(prefix="emitted-local-bench-") as tmp: + for round_index in range(args.rounds): + order = ("baseline", "production") if round_index % 2 == 0 else ("production", "baseline") + pair = [] + for engine in order: + work = Path(tmp) / f"r{round_index}-{engine}" + work.mkdir() + pair.append(run_once(engine, work)) + samples.append(pair) + + def median_for(engine: str) -> float: + values = [sample["seconds"] for pair in samples for sample in pair if sample["engine"] == engine] + return statistics.median(values) + + baseline_median = median_for("baseline") + production_median = median_for("production") + ratio = baseline_median / production_median if production_median else None + payload = { + "status": "PASS_IDENTICAL_EMITTED_LOCAL_INTEGER_PRODUCTION_RECEIPTS", + "python": sys.version, + "platform": platform.platform(), + "rounds": args.rounds, + "receipt_sha256": RECEIPT_SHA256, + "baseline_median_seconds": baseline_median, + "production_median_seconds": production_median, + "median_ratio": ratio, + "samples": samples, + "implementation_sha256": { + "baseline.py": hashlib.sha256(BASELINE.read_bytes()).hexdigest(), + "production": hashlib.sha256(PRODUCTION.read_bytes()).hexdigest(), + "benchmark.py": hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), + }, + } + text = json.dumps(payload, indent=2) + "\n" + print(text, end="") + print( + f"PASS_IDENTICAL_EMITTED_LOCAL_INTEGER_PRODUCTION_RECEIPTS " + f"median {baseline_median:.3f}->{production_median:.3f}s " + f"({ratio:.3f}×)" if ratio else "ratio undefined", + flush=True, + ) + if args.write_result: + (PACKAGE / "RESULT.json").write_text(text, encoding="utf-8") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/research/emitted-local-integer-production/verify.py b/research/emitted-local-integer-production/verify.py new file mode 100644 index 0000000000..e02a9886b7 --- /dev/null +++ b/research/emitted-local-integer-production/verify.py @@ -0,0 +1,207 @@ +#!/usr/bin/env python3 +"""Equivalence, pin and rejection controls for production emitted-local integer rows. + +Read-only by default. Timing is not a pass gate; see benchmark.py / RESULT.json. +""" +from __future__ import annotations + +import argparse +import ast +import gzip +import hashlib +import io +import json +import os +from pathlib import Path +import subprocess +import sys +import tarfile +import tempfile + +ROOT = Path(__file__).resolve().parents[2] +PACKAGE = Path(__file__).resolve().parent +PRODUCTION = ROOT / "research/complex-k492-owner-repair/code/hpe_audit_local.py" +BASELINE = PACKAGE / "baseline.py" +ARCHIVE = ROOT / "research/community-frontier1042-audit/selected-replay.tar.gz" +OPT_IN_FAST = ROOT / "research/emitted-local-integer-replay-seed90/fast.py" + +BASE_COMMIT = "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2" +ORIGINAL_BLOB = "17bccb64fdca54f329a3ce16e369449cb76c2802" +ORIGINAL_SHA256 = "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" +OPTIMIZED_SHA256 = "cbf68feab9fcf57d8d5ed8a525a8f8cd5d79b2a61faf98cff672e137a3bcf99f" +RECEIPT_SHA256 = "13dd18297162569532983db1a2ab67926b064330cd7edd3587e7b546b2dedf17" + + +def require(condition, message): + if not condition: + raise AssertionError(message) + + +def digest_file(path: Path) -> str: + return hashlib.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 check_baseline_bytes() -> None: + original = subprocess.check_output( + ["git", "show", f"{BASE_COMMIT}:research/complex-k492-owner-repair/code/hpe_audit_local.py"], + cwd=ROOT, + ) + require(hashlib.sha256(original).hexdigest() == ORIGINAL_SHA256, "base hpe_audit_local.py sha256 drift") + blob = ( + subprocess.check_output( + ["git", "rev-parse", f"{BASE_COMMIT}:research/complex-k492-owner-repair/code/hpe_audit_local.py"], + cwd=ROOT, + ) + .decode() + .strip() + ) + require(blob == ORIGINAL_BLOB, "base hpe_audit_local.py blob drift") + require(BASELINE.read_bytes() == original, "baseline.py must equal the base-commit hpe_audit_local.py") + require( + digest_file(PRODUCTION) == OPTIMIZED_SHA256, + "production hpe_audit_local.py does not match the claimed optimized digest", + ) + require(PRODUCTION.read_bytes() != original, "production must differ from the pairwise baseline") + # Production must be the opt-in transform of the baseline, with Row inlined. + sys.path.insert(0, str(OPT_IN_FAST.parent)) + import fast as fast_mod # type: ignore + + transformed = fast_mod.transform(original.replace(b"\r\n", b"\n").decode()) + require("class Row" in PRODUCTION.read_text(encoding="utf-8"), "production must define Row") + require("rows={('L',r):Row({r:1}) for r in range(n)}" in PRODUCTION.read_text(encoding="utf-8"), + "production must use Row initialization") + require(transformed.count("rows={('L',r):Row({r:1}) for r in range(n)}") == 1, + "opt-in transform boundary drift") + + +def materialize(directory: Path) -> None: + with tarfile.open(ARCHIVE) as archive: + for name in ("CANONICAL-WORD.json.gz", "LOCAL-PROGRAMS.json.gz"): + members = [m for m in archive.getmembers() if m.name == "slots/local/" + name] + require(len(members) == 1 and members[0].isfile(), "unique selected member: " + name) + (directory / name).write_bytes(archive.extractfile(members[0]).read()) + payload = gzip.decompress((directory / "CANONICAL-WORD.json.gz").read_bytes()) + require( + hashlib.sha256(payload).hexdigest() + == "4ddb29fb9bc6f27e0c0fbfcf19a2a93a3496ad900d0f6d89059d0305c9576c0c", + "selected R480 payload", + ) + + +def run_checker(checker: Path, directory: Path) -> tuple[bytes, str]: + env = {k: v for k, v in os.environ.items() if k != "PYTHONOPTIMIZE"} + env["PYTHONDONTWRITEBYTECODE"] = "1" + proc = subprocess.run( + [sys.executable, "-B", str(checker), str(directory)], + cwd=directory, + env=env, + capture_output=True, + text=True, + ) + require(proc.returncode == 0, f"checker failed\n{proc.stderr}\n{proc.stdout}") + receipt = (directory / "INDEPENDENT-LOCAL-REPLAY.json").read_bytes() + return receipt, proc.stdout + + +def check_identical_receipts() -> dict: + with tempfile.TemporaryDirectory(prefix="emitted-local-prod-") as tmp: + base_dir = Path(tmp) / "baseline" + prod_dir = Path(tmp) / "production" + base_dir.mkdir() + prod_dir.mkdir() + materialize(base_dir) + materialize(prod_dir) + base_receipt, base_log = run_checker(BASELINE, base_dir) + prod_receipt, prod_log = run_checker(PRODUCTION, prod_dir) + require(base_receipt == prod_receipt, "complete receipts differ") + require(base_log == prod_log, "stdout differs") + require( + hashlib.sha256(prod_receipt.replace(b"\r\n", b"\n")).hexdigest() == RECEIPT_SHA256, + "receipt digest drift", + ) + payload = json.loads(prod_receipt.decode(), object_pairs_hook=unique_object) + require( + payload["status"] == "PASS_INDEPENDENT_LOCAL_SCALAR_FRAME_AND_WRAPPER_REPLAY", + "unexpected status", + ) + require(len(payload["negative_controls_rejected"]) == 25, "retained mutation coverage") + return { + "receipt_sha256": RECEIPT_SHA256, + "controls": len(payload["negative_controls_rejected"]), + "status": payload["status"], + } + + +def check_assertions_preserved() -> int: + def assertion_list(text: str): + return [ast.dump(n, include_attributes=False) for n in ast.walk(ast.parse(text)) if isinstance(n, ast.Assert)] + + base = assertion_list(BASELINE.read_text(encoding="utf-8")) + prod = assertion_list(PRODUCTION.read_text(encoding="utf-8")) + require(base == prod, "original assertions changed") + return len(base) + + +def check_temp_corruption_rejection() -> dict: + """On-disk foil that drops ADD updates must fail closed or change the receipt.""" + with tempfile.TemporaryDirectory(prefix="emitted-local-prod-honest-") as tmp: + honest_dir = Path(tmp) / "honest" + honest_dir.mkdir() + materialize(honest_dir) + honest, _ = run_checker(PRODUCTION, honest_dir) + + text = PRODUCTION.read_text(encoding="utf-8") + needle = "def add_scaled(self, other, q):" + require(needle in text, "Row.add_scaled site missing for corruption control") + # Foil: keep the signature but drop all ADD updates. + foil_text = text.replace( + needle, + "def add_scaled(self, other, q):\n return\n def add_scaled_disabled(self, other, q):", + 1, + ) + require(foil_text != text, "mutant must differ on disk") + + with tempfile.TemporaryDirectory(prefix="emitted-local-prod-foil-") as tmp: + mutant = Path(tmp) / "hpe_audit_local.py" + mutant.write_text(foil_text, encoding="utf-8") + work = Path(tmp) / "work" + work.mkdir() + materialize(work) + try: + bad, _ = run_checker(mutant, work) + except Exception as exc: + return {"rejected": True, "mode": "subprocess_failure", "detail": str(exc)[:240]} + require(bad != honest, "ADD-drop foil must change the local receipt") + return {"rejected": True, "mode": "receipt_divergence"} + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.parse_args(argv) + # -O policy: require() gates remain; checker children use -B with PYTHONOPTIMIZE cleared. + check_baseline_bytes() + assertions = check_assertions_preserved() + receipts = check_identical_receipts() + corruption = check_temp_corruption_rejection() + require(corruption["rejected"], "corruption control must reject") + print( + "PASS_EMITTED_LOCAL_INTEGER_PRODUCTION " + f"assertions={assertions} " + f"controls={receipts['controls']} " + f"corruption={corruption['mode']} " + "certs=1 no_new_kappa", + flush=True, + ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/research/emitted-local-integer-replay-seed90/CERTIFICATE.json b/research/emitted-local-integer-replay-seed90/CERTIFICATE.json index 691b88f0b3..8e7fc2bcbf 100644 --- a/research/emitted-local-integer-replay-seed90/CERTIFICATE.json +++ b/research/emitted-local-integer-replay-seed90/CERTIFICATE.json @@ -245,7 +245,7 @@ "research/community-frontier1042-audit/selected-replay.tar.gz": "22c3f4dce4b897a1d423d1388801933e288b6a6b1906cb15e1b16a5eb68db754", "research/community-frontier1094-audit/ASSEMBLY.json": "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045", "research/community-frontier1094-audit/RESULT.json": "1e3e47e9ec24bcb6fb5f703b7fce0aab658d84ff72bfae5da3ae429d17b6e752", - "research/complex-k492-owner-repair/code/hpe_audit_local.py": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" + "research/emitted-local-integer-replay-seed90/baseline.py": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" }, "stdout_sha256": "dd643a58258431c3b07d3b06d9060c49677fa23b4fafc9f10988ed1f6867bd9a" } diff --git a/research/emitted-local-integer-replay-seed90/README.md b/research/emitted-local-integer-replay-seed90/README.md index f3bf4580e8..099d3644c8 100644 --- a/research/emitted-local-integer-replay-seed90/README.md +++ b/research/emitted-local-integer-replay-seed90/README.md @@ -1,5 +1,7 @@ # Faster emitted local replay, seed 90 +After `research/emitted-local-integer-production/`, the pairwise checker bytes live in [`baseline.py`](baseline.py); production `hpe_audit_local.py` ships the integer-row rewrite. + An opt-in port accelerates the complete emitted local audit used in the selected PR1094 lineage, preserving both full orientations and all 25 inherited negative controls. It combines shared-denominator sparse integer rows with independent JSON mutation-fixture copies. These techniques are credited prior work: this package applies them to the distinct `hpe_audit_local.py` workload, leaving selected sources and commands unchanged. Three alternating fresh-process pairs on Windows/CPython 3.14.5 measured a **2.33x median total process speedup** (2.41x inside the complete audit, 2.46x audit CPU). The full-audit paired wall ratios were 2.409, 2.393 and 2.440. Each timed run includes both orientations, all 25 mutations, input reads and output serialization; archive preparation is excluded. These are local measurements, not a general speed guarantee. diff --git a/research/emitted-local-integer-replay-seed90/SOURCES.json b/research/emitted-local-integer-replay-seed90/SOURCES.json index 577d2de4c8..62bce84fbb 100644 --- a/research/emitted-local-integer-replay-seed90/SOURCES.json +++ b/research/emitted-local-integer-replay-seed90/SOURCES.json @@ -3,5 +3,5 @@ "research/community-frontier1042-audit/selected-replay.tar.gz": "22c3f4dce4b897a1d423d1388801933e288b6a6b1906cb15e1b16a5eb68db754", "research/community-frontier1094-audit/ASSEMBLY.json": "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045", "research/community-frontier1094-audit/RESULT.json": "1e3e47e9ec24bcb6fb5f703b7fce0aab658d84ff72bfae5da3ae429d17b6e752", - "research/complex-k492-owner-repair/code/hpe_audit_local.py": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" + "research/emitted-local-integer-replay-seed90/baseline.py": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" } diff --git a/research/emitted-local-integer-replay-seed90/baseline.py b/research/emitted-local-integer-replay-seed90/baseline.py new file mode 100644 index 0000000000..17bccb64fd --- /dev/null +++ b/research/emitted-local-integer-replay-seed90/baseline.py @@ -0,0 +1,171 @@ +# Local-only extraction of the attributed PR514 / PR433 independent replay. +# Prepared for icekylinx with OpenAI Codex assistance. Apache-2.0. +# The complete local checker and its negative controls are retained verbatim. +# Global hosting is verified separately for the changed 112-port geometry. +import copy,gzip,hashlib,json,sys +from collections import Counter +from fractions import Fraction as Q +from pathlib import Path +OUT=Path(sys.argv[1]) +c=json.load(gzip.open(OUT/'CANONICAL-WORD.json.gz')) +ir={'local_programs':json.load(gzip.open(OUT/'LOCAL-PROGRAMS.json.gz'))} +v,R,h=c['v'],c['R'],c['h'];n=2*v+R;frames=c['frames'] +levels={int(t):f for t,f in c.get('target_levels',{}).items()} +entering=[r for r,f in enumerate(c['start']) if r>=2*v and f!=0] +plain={r for r in range(n) if r not in set(entering)} + +def contains(a,b): + for x in a: + for y in b: + if x>>(y.bit_length()-1)&1:x^=y + if x:return False + return True +hpe={r for r in range(2*v,n) if c['final'][r]!=1} # HPE: helpers whose terminal frame is a proper subspace U of FULL +assert all(len(frames[c['final'][r]])0 + hist[rank]+=1;cur[r]=b + elif tag=='center': + _,k,a,b,rank=event + assert phases[-1]=='centers' and private=={('C',k):a} + cf=c['center_frames'][k];cr=len(frames[cf]) + # GK: stepwise descent cf -> served levels -> lowest (forward), reversed ascent (backward); each step is a nested child + assert contains(frames[a],frames[b]) if back else contains(frames[b],frames[a]) + assert rank==abs(len(frames[a])-len(frames[b]))>0 + chain.setdefault(k,[]).append((a,b)) + private['C',k]=b;hist[rank]+=1;centers.append(k) + elif tag=='scalar': + _,e,f=event;op=e[0];target=tuple(e[1]);source=tuple(e[2]) if op in ('copy','add') else None + if target[0]=='C' and op=='clear': + assert private.get(target,f)==f + private.pop(target,None) + else: + for r in (target,source): + if r is None:continue + if r[0]=='L':assert cur[r[1]]==f and (r[1] not in wset or (r[1] in pre_seen and r[1] not in post_seen)),('common frame / wrapper order',r,cur[r[1]],f) + else: + if r==target and r not in private:private[r]=f + assert private[r]==f + if op=='clear':rows[target]={};norm[target]=Q(0) + elif op=='copy':rows[target]=dict(rows[source]);norm[target]=norm[source] + elif op=='scale': + q=Q(e[2],e[3]);a,b=abs(q.numerator),q.denominator + assert a&(a-1)==0 and b&(b-1)==0 + rows[target]={j:q*x for j,x in rows[target].items()};norm[target]*=abs(q) + else: + q=Q(e[3],e[4]);a,b=abs(q.numerator),q.denominator + assert source!=target and b&(b-1)==0 + # Independent symbolic replay of the cleared coefficient work. + w=0 + for bit in bin(a)[2:]:w=2*w+int(bit) + assert Q(w,b)*(1 if q>0 else -1)==q + prefix=max(prefix,Q(a)*norm[source]) + norm[target]=norm.get(target,Q(0))+abs(q)*norm[source] + row=rows.setdefault(target,{}) + for j,x in list(rows[source].items()): + z=row.get(j,Q(0))+q*x + if z:row[j]=z + else:row.pop(j,None) + prefix=max(prefix,norm[target]) + else:raise AssertionError(tag) + assert phases==allowed and set(centers)==set(range(len(c['centers']))) and not private + assert sorted(r for k,r,_ in wrappers if k=='pre')==wrapped and sorted(r for k,r,_ in wrappers if k=='post')==wrapped # GK + for k,st in chain.items(): # GK: the steps of each centre chain link up and end at the centre frame + cf=c['center_frames'][k] + if back:assert st[-1][1]==cf and all(st[i][1]==st[i+1][0] for i in range(len(st)-1)) + else:assert st[0][0]==cf and all(st[i][1]==st[i+1][0] for i in range(len(st)-1)) + assert all(not row for reg,row in rows.items() if reg[0]=='C') + for r in range(n): + expected={r:Q(1)} + if back and r