diff --git a/research/literal-gate-setup-reuse/BENCHMARK.json b/research/literal-gate-setup-reuse/BENCHMARK.json new file mode 100644 index 0000000000..1e2c4cc6f9 --- /dev/null +++ b/research/literal-gate-setup-reuse/BENCHMARK.json @@ -0,0 +1,51 @@ +{ + "first_pair": { + "baseline_cpu_seconds": 282.46999999999997, + "baseline_wall_seconds": 283.3212143800047, + "candidate_cpu_seconds": 207.42000000000002, + "candidate_wall_seconds": 207.92062770601478, + "complete_stdout_equal": true, + "cpu_fraction_saved": 0.2656919318865719, + "profile_included_in_comparison": false, + "samples_per_arm": 1, + "wall_fraction_saved": 0.26613110083898917 + }, + "packaged_normal_confirmation": { + "baseline_wall_seconds": 283.3212143800047, + "candidate_wall_seconds": 209.92502825299744, + "baseline_cpu_seconds": 282.46999999999997, + "candidate_cpu_seconds": 209.2, + "wall_fraction_saved": 0.25905644336454303, + "cpu_fraction_saved": 0.2593903777392289, + "note": "Same baseline, later self-contained packaged candidate. Not a second independent pair or a median." + }, + "setup": { + "binding": { + "original_method_sha256": "ebb92d6870d73dc452faf6d8c3c62710539ffb9bae3a5588dc694fe2693c6509", + "prepared_ast_sha256": "eb4c3f7790c6b262fb0e4167b26be34f358d82498606d1ba9b448716274fe5b8", + "sites": { + "D": 1, + "P": 1, + "mv": 1, + "qvalue": 1 + } + }, + "cache": { + "currsize": 512, + "hits": 61214, + "maxsize": 512, + "misses": 23983 + }, + "second_literal": "Original unchanged independent native_verify.state", + "source_head": "a0171b8d2f942cdfc5295307548fe484c570b1ba" + }, + "profile_excluded_from_comparison": true, + "execution_order": [ + "profile", + "baseline", + "prototype candidate", + "packaged normal", + "packaged optimized", + "sealed optimized" + ] +} diff --git a/research/literal-gate-setup-reuse/COVERAGE-GATE.json b/research/literal-gate-setup-reuse/COVERAGE-GATE.json new file mode 100644 index 0000000000..c4ff1c9e00 --- /dev/null +++ b/research/literal-gate-setup-reuse/COVERAGE-GATE.json @@ -0,0 +1,16 @@ +{ + "stage": "PASS_BEFORE_COMPLETE_CANDIDATE", + "source": "a0171b8d2f942cdfc5295307548fe484c570b1ba", + "retained": "Both PR5818 entry points and orchestration, original full RESULT/CROSS and actual trace, all original controls, all dense/sparse amplitude comparisons and second literal interpreter.", + "changes": "Only the freshly loaded cross dense-literal Op.zero_state receives a hash-bound AST derivation: compute a P/D setup once per gate, replace two per-address pure calls by exact lookups. All amplitude arithmetic, gate order, phases, denominator reductions, return shape and failures remain. Setup uses captured original dense-literal mv/qvalue, never the sparse interpreter or quadratic engine.", + "proof": "For each fixed gate and address x in 0..2^n-1, table[x] is its original pure function value. Induction on the unchanged gate loop gives identical dense vectors and denominator after every gate. Typed complete immutable (width,gate) keys and a bounded process cache preserve this equality under hits, mutation and eviction.", + "finite_gate": { + "cases": 1522, + "amplitudes": 22700, + "full_width_cases": 4, + "normal_optimized": "PASS", + "cache_controls": 20, + "source_bound_ast_sites": 4 + }, + "limitations": "Fixed source, widths0..9; entry-wise validation and original source/receipts remain mandatory. It changes one literal method execution by exact setup reuse, not the underlying state algorithm or the second interpreter." +} diff --git a/research/literal-gate-setup-reuse/NOTICE b/research/literal-gate-setup-reuse/NOTICE new file mode 100644 index 0000000000..613a66b875 --- /dev/null +++ b/research/literal-gate-setup-reuse/NOTICE @@ -0,0 +1,42 @@ +New selected-caller integration, format adapter, bounded input cache and checks: +Ali Romman with substantial OpenAI Codex assistance. Apache-2.0. +The same assistant wrote the code and performed the author-side checks. + +The exact quadratic engine and its proof are retained from Ali Romman PR 5704, +head daa4d9dbd102d2a3677afc5614c56466bd2cf3a2. Its NOTICE.md remains byte-exact +and credits classical stabilizer simulation, Charles Bethin PR 662 and all +native/compiler predecessors. This package does not claim that engine as new. + +The complete selected source is Ali Romman PR 5599, audited source head +09dd0965711ca7eeb169057a420abab1c9052137. Its exact word, receipt, proof and +NOTICE remain inputs. That notice retains Pierre-Loic Doulcet/hexapode, +Joel Pulikkan/GamingPuzzled, DreamingOfClouds, thu-nmrc, Gareth Davidson/bitplane, +David Arias, Cinna Davis, Jacob Alan Sussman, zxv, Cao Yifan and earlier geometry, +BIT and analytic credit. The derived files retain their original module text. + +Classical deterministic memoization and exact affine-support enumeration are +not new general algorithms. The new result is their checked integration into +this complete source replay, with every scalar/native/invoice/compiler check, +independent literal-state evidence and whole-replay measurements. No original +source, selected record, native bill or kappa is changed. Archive inclusion, +local replay and hosted CI are separate from independent mathematical review. + +Native-channel attribution from its pinned README: Rohan Arun PR 1972 supplied +the scalar/frame channel; Adam Gall PR 1940 supplied the schedule. Josie Elliston +PR 1071 supplied the P104 fixture/decoder, with Ali Romman PR 1125 and the retained +PR 968/717/446/595/620 lineage. icekylinx's frame-sa504 retains the exact compiler; +Ali Romman PR 1862/1931 retains the independent Gaussian interpreter. Native +lowering and physical binding were prepared for Chafik Boukhalfa with OpenAI +Codex assistance. These are predecessor contributions, not work of this adapter. +Source: https://github.com/CrocSwap/integer-mult-bounds/blob/553d26d796fde9871ff2661a49ac7732e945410f/research/p104-native-channel/README.md + + +Independent Linux qualification +------------------------------ +This package retains the exact PR #5757 official export, including the original source notices. Ali Romman supplied the acceleration, integration, original controls and macOS measurements. Chris R / Clear1nsight supplied the new Linux measurements, applicability review, guarded reproduction and recorded-evidence checks, with substantial OpenAI Codex assistance. No subagents or independent human/proof-kernel acceptance are claimed. The retained construction, controller, native, compiler and stabilizer sources keep their original attribution and Apache-2.0 obligations. No new mathematical construction, physical multiplier speedup or kappa gain is claimed. + +Single-pass qualification orchestration +-------------------------------------- +Chris R / Clear1nsight with substantial OpenAI Codex assistance supplied the process-local observer/handoff, coverage review, controls and paired Linux measurements. Both original PR5757 entry points, their literal interpreters, archived source and expected scientific receipts remain unchanged. The guard.py harness is retained from PR5816. No subagents or independent human/proof-kernel review. Apache-2.0. No kappa or physical multiplier gain. + +Literal P/D setup reuse, exact source-bound derivation, controls and Linux measurements: Chris R / Clear1nsight, with substantial OpenAI Codex assistance; no subagents. Apache-2.0. Original PR5818 and nested source notices retained unchanged. diff --git a/research/literal-gate-setup-reuse/PROFILE.json b/research/literal-gate-setup-reuse/PROFILE.json new file mode 100644 index 0000000000..28f33be2da --- /dev/null +++ b/research/literal-gate-setup-reuse/PROFILE.json @@ -0,0 +1,46 @@ +{ + "coverage": "Both original RESULT/CROSS, full actual trace, both literal interpreters and all original controls executed.", + "gate_visits_across_literal_state_circuits": { + "C": 64523, + "D": 47273, + "P": 37924, + "X": 14668, + "phase": 12477 + }, + "largest_circuit_repeat": 1, + "method": "Whole-function perf_counter timings; nested totals overlap. No per-amplitude profiler.", + "repeated_tableau_calls": 0, + "source_head": "a0171b8d2f942cdfc5295307548fe484c570b1ba", + "tableau_calls": 17651, + "timings": { + "complete_source_replay": { + "calls": 1, + "seconds": 130.806565787 + }, + "cross_circuit_tableau": { + "calls": 17651, + "seconds": 7.222084413999962 + }, + "cross_dense_literal": { + "calls": 17651, + "seconds": 117.68412035899925 + }, + "cross_entry_inclusive": { + "calls": 1, + "seconds": 147.107770699 + }, + "cross_sparse_literal": { + "calls": 17651, + "seconds": 15.022373065999984 + }, + "quadratic_support_all_phases": { + "calls": 84083, + "seconds": 9.472371723999984 + }, + "verify_entry_inclusive": { + "calls": 1, + "seconds": 131.399111236 + } + }, + "unique_width_circuits": 17651 +} diff --git a/research/literal-gate-setup-reuse/PROOF.md b/research/literal-gate-setup-reuse/PROOF.md new file mode 100644 index 0000000000..9aa4c256c3 --- /dev/null +++ b/research/literal-gate-setup-reuse/PROOF.md @@ -0,0 +1,37 @@ +# Exact gate setup reuse inside one literal interpreter + +The object is the complete PR #5818 qualification at `a0171b8d2f942cdfc5295307548fe484c570b1ba`, retaining exact PR #5757 `53006fe6031dab5c23d5b7d1cf6a92f411a04a68`. The second sparse literal interpreter and quadratic engine are unchanged and share no new setup cache with the dense literal interpreter. + +## What the profile permits + +There are 17,651 distinct width/circuit keys among 17,651 actual state inputs: a whole-circuit tableau cache has no hits. Tableau construction takes 7.222 seconds in the profiled run, too little to meet the requested 15% whole-run threshold even if removed. This rejected nomination is preserved in PROFILE.json. + +The dense literal state loop takes 117.684 seconds. Its P gates compute the same pure address map for every amplitude; its D gates compute a fixed quadratic phase for every amplitude. The actual corpus visits 37,924 P and 47,273 D gates. Setup reuse is limited to their independently computed scalar tables, not state vectors, accepted results or the other interpreter's data. + +## Exactness and complete keys + +Fix a valid width `0 <= n <= 9`. For a P gate define `images[x] = original_mv(rows,x)` for every `0 <= x < 2^n`. For a D gate define `phases[x] = original_qvalue(Q,alpha,x,n)` on the same domain. Both functions are the unchanged helpers captured from this dense literal compiler; no quadratic engine or sparse-interpreter result is consulted. + +The cache key is the complete typed immutable pair `(n, gate)`, including every matrix row and every phase coefficient. Lists are recursively copied to tuples. Boolean/float aliases, shape changes and unsupported widths reject before lookup. A hit returns the same immutable integer tuple a fresh evaluation would compute. The LRU stores at most 512 tables, each with at most 512 entries; source-key storage is additional. Eviction merely requires recomputation; exceptions are never accepted or cached. Bounds concern this frozen source and declared width/key domain, not arbitrary-size compiler workloads. + +## Source-bound method derivation + +The complete original `Op.zero_state` text is pinned by SHA256 `ebb92d6870d73dc452faf6d8c3c62710539ffb9bae3a5588dc694fe2693c6509`. The AST transformer requires exactly one P branch, one D branch, one `mv(e[1],x)` and one `qvalue(e[1],e[2],x,self.n)` call. It adds one setup retrieval at the start of each of those branches and replaces only those two scalar calls with indexed lookups. All other statements are retained. The derived AST has SHA256 `eb4c3f7790c6b262fb0e4167b26be34f358d82498606d1ba9b448716274fe5b8`. + +For every amplitude address the replacement value equals the original pure function by construction. Therefore the vector after a P gate, including zero entries, is identical; after a D gate every signed Gaussian amplitude and absolute phase is identical. The C/X/global-phase arithmetic, gate chronology and all denominator/divisibility reductions are untouched. Induction over the unchanged circuit loop proves equality of the returned complete dense vector and denominator on this domain. Fresh output allocation is unchanged; no mutable state-vector answer is stored. + +The hook applies only when the unchanged cross checker loads `selected_cross_literal_compiler`. The original source execution and original adapter controls execute before that point. The loader and method are restored in `finally`, and exactly one installation plus actual bounded cache hits are required. The second literal interpreter, its tableaux and its own existing implementation are unchanged. These are still two separate arithmetic implementations, although the dense one now reuses its own exact setup. + +## Full qualification and failure coverage + +The original complete RESULT/CROSS comparisons remain active. They bind all actual state-call counts, all 17,651 inputs, 9,037,312 amplitude entries per literal interpreter, exact denominators and trace SHA256 `73ac04db73d83151efb474925d48298664cc7490d31bdec7a70dcf79b448f481`. Every amplitude comparison still occurs; no sampling, orbit quotient, cached PASS or stored state vector replaces one. + +All PR #5818 stage/contamination/exception and source-custody controls are retained. Every positive run also executes original PR #5757 controls: the adapter corpus, complete cache/type/mutation/capacity/eviction checks, three proof-omission controls and explicit optimized width rejection. The new finite setup corpus independently compares the original dense method with its derived method on 1,522 complete state cases and 22,700 amplitude entries, including four width-nine cases. It tests complete keys, changed inputs/phase/width, immutable results, numeric aliases, bounded capacity, eviction, uncached exceptions and the literal-method source pin. Normal and deliberate optimized validation remain separate. + +The complete original PR #5818 package is retained as its authenticated official 45-file export. All member hashes, inventory and head are checked before imports; private baseline and scientific source exports are Git-free/read-only and checked after success. An unmerged Git object is not a runtime dependency. No frozen predecessor, source word, scientific receipt or selected metadata is edited. + +## Limits and attribution + +The PR #5818 single-process source-sharing boundary remains: this is not a second cold source replay. This proof concerns exact verification computations, not native provider legality or a multiplication theorem. The five framework assumptions, conditional kappa and selected record remain unchanged. Same-agent implementation/checking and hosted CI do not constitute independent human or proof-kernel acceptance. Performance is a source/host-bound measurement, not a universal guarantee. + +Ali Romman supplied the original dense/sparse interpreters, PR #5704 engine, PR #5757 integration and controls; PR #5816 supplied Linux qualification and the guard; PR #5818 supplied single-pass orchestration. Preserve their full native/controller/compiler/helper/BIT/classical stabilizer notices in the retained bundle and NOTICE. New setup derivation, controls, profiling and validation: Chris R / Clear1nsight with substantial OpenAI Codex assistance, no subagents. Memoization and tabulation are standard techniques. Apache-2.0. diff --git a/research/literal-gate-setup-reuse/README.md b/research/literal-gate-setup-reuse/README.md new file mode 100644 index 0000000000..8ff7d0f78a --- /dev/null +++ b/research/literal-gate-setup-reuse/README.md @@ -0,0 +1,66 @@ +# Exact literal-gate setup reuse after PR #5818 + +This opt-in verification runner reduces the complete frozen [PR #5818](https://github.com/CrocSwap/integer-mult-bounds/pull/5818) qualification bill by reusing exact P-gate address tables and D-gate phase tables inside its dense literal interpreter. Both literal interpreters still execute every actual state and compare every amplitude, including zeros, absolute phases and denominators. All original source/native/caller/invoice/compiler/outer, adapter, omission and complete RESULT/CROSS checks remain active. No state vector or accepted result is cached. + +The initial fresh-process baseline/prototype pair saves **26.61% wall time and 26.57% CPU time**. The later self-contained packaged normal command also passes: **209.93 seconds wall / 209.20 CPU**, versus the same baseline's **283.32 / 282.47**, saving **25.91% wall / 25.94% CPU**. These are source/host-bound measurements, exceeding the user's 15% gate. One baseline with two candidate observations is not two independent pairs, a median or a universal speedup. + +## Profile before construction + +[PROFILE.json](PROFILE.json) records a complete profiled run. It rejects the original whole-circuit tableau-cache nomination: 17,651 actual circuit keys are all distinct, so there are zero repeat hits. Tableau setup costs only 7.222 seconds, insufficient for 15% whole-run savings even if eliminated. Dense literal work costs 117.684 seconds; repeated pure P/D gate setup is the bounded alternative. Whole-function nested timings overlap and profiling is excluded from the speed comparison. + +The pre-construction [coverage gate](COVERAGE-GATE.json) and [PROOF.md](PROOF.md) identify every changed statement and retained obligation. The complete original dense-method source and prepared AST are pinned. Only two scalar helper calls are replaced by indexed tables computed with that interpreter's own unchanged helpers. The second sparse interpreter and quadratic engine share no new setup cache with it. All gate chronology, signed Gaussian arithmetic, denominator/divisibility checks and fresh vector allocation remain unchanged. + +## Measurements and retained coverage + +Ubuntu 24.04.5 LTS, Linux x86_64, CPython 3.12.3, Intel Core i7-4790; serial fresh processes and no retries: + +| Complete qualification | Wall seconds | CPU seconds | Kernel peak MiB | +| --- | ---: | ---: | ---: | +| PR #5818 baseline | 283.32 | 282.47 | 519.03 | +| Initial setup prototype | 207.92 | 207.42 | 521.11 | +| Self-contained packaged normal | 209.93 | 209.20 | 522.85 | + +The initial candidate reuses **61,214** setup tables with **23,983** misses and at most **512** resident immutable tables. Each has at most 512 integer entries; complete-key storage is additional. No amplitude or state answer is stored. The complete scientific stdout is byte-identical, SHA256 `c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba`. + +Every full run checks **17,651 actual inputs** against both literal implementations, **9,037,312 amplitude entries per interpreter**, original complete receipts and trace SHA256 `73ac04db73d83151efb474925d48298664cc7490d31bdec7a70dcf79b448f481`. The unchanged original 1,522-state/22,700-amplitude adapter corpus, cache/type/mutation/capacity/eviction tests, three proof-omission controls and explicit optimized width guard remain. New finite conformance compares the original dense method to its derived method on another 1,522 complete cases / 22,700 amplitudes, including four width-nine cases, with 23 controls. Deliberately corrupt P addresses and D absolute phases are detected; mutable outputs remain fresh. All 13 predecessor orchestration and seven predecessor custody controls remain, plus top-level bundle-byte corruption rejection before imports. + +[BENCHMARK.json](BENCHMARK.json), [VALIDATION.json](VALIDATION.json) and `evidence/` preserve complete stdout, stderr, resource receipts and failures/limitations. Public resource receipts remove only the local absolute script path and record the original local receipt hash. Method wrapper snapshots are documentary text from the local round, not standalone entry points. The normal/optimized/sealed qualification observations are distinct from the first-pair speed comparison. Shared host load, sequential order and unflushed OS caches limit timing conclusions; no slow sample is discarded. Kernel and sampled group RSS are different measurements, and sampling can miss short peaks. + +## Reproduce a fresh full qualification + +Python 3.12, standard library only: + +```sh +python3 -B scripts/research_package.py --package research/literal-gate-setup-reuse +``` + +The first two commands run finite setup and inherited controls. The third runs a **fresh full scientific qualification**, typically about 3.5 minutes on this host. It emits the original `PASS_COMPLETE_SELECTED_QUADRATIC_REPLAY`, `PASS_ALL_SELECTED_LITERAL_STATES` and `PASS_SINGLE_PASS_COMPLETE_QUALIFICATION` outputs, without an extra performance/PASS shortcut. + +The official complete 45-file PR #5818 export at `a0171b8d2f942cdfc5295307548fe484c570b1ba` is retained as immutable `inputs/PR5818.tar`, SHA256 `f166f27e7c247315e852f78e30b2d348e9b66518645b783b5344a6767d87e7cc`. Its source is authenticated before importing; its nested original 54-file PR #5757 export is also authenticated unchanged. Private materializations are read-only and Git-free and checked after success. No network, Git command, unmerged-object cache, third-party Python dependency, edited source or changed expected scientific receipt is needed at runtime. + +To repeat a bounded comparison on Linux with `/usr/bin/python3.12`, GNU `/usr/bin/time` and `/proc`, choose a new work directory: + +```sh +python3 -B research/literal-gate-setup-reuse/benchmark.py pair --workdir /tmp/setup-reuse-fresh +python3 -B research/literal-gate-setup-reuse/benchmark.py optimized --workdir /tmp/setup-reuse-fresh +``` + +The pair runs the complete PR #5818 baseline then complete candidate serially, with 600 seconds per command, 900 seconds aggregate, 1 GiB sampled process-group RSS, bounded output and no retries. Expansion requires byte-identical complete stdout and at least 15% lower wall and CPU time. The separately gated optimized phase allows 1,500 seconds cumulative, retaining the same command and memory caps. Existing work directories and run receipts are not overwritten. This opt-in reproduction does not silently repeat the original six-command development round or any historical suite. + +## Qualification and source scope + +The local round profiles once, measures one unprofiled pair, then separately qualifies the packaged normal, optimized and sealed optimized forms. Normal and deliberate optimized finite controls pass. The complete optimized package passes in 214.55 seconds; its read-only, Git-free implementation export passes under `-I -O -B`, empty PATH and an explicit authenticated import root in 213.97 seconds, with all 42 exported files unchanged. All six local scientific commands pass in 1408.80 seconds total, including the profiler, within the staged 900/1,500-second aggregate limits. These mode/export qualifications are outside the initial speed comparison. Exact committed bytes/modes and hosted CI are recorded separately in VALIDATION.json and the canonical PR handoff. Full-history preflight is unavailable in this shallow checkout; immediate declared input-pin ancestry is checked without claiming a complete history audit. + +Canonical main at entry is `de5ec2e7a6074068452f45b1a191b5c72832df4a`, priority revision 8. Targeted PR/body and relevant Discussion overlap checks found no matching setup follow-up; they do not establish exhaustive novelty or unpublished-work coverage. The branch retains Ali Romman's exact [PR #5761](https://github.com/CrocSwap/integer-mult-bounds/pull/5761) test-only repair with original authorship/provenance, already used by PR #5818. No shared research framework, frozen predecessor package, selected record or scientific expected output is changed. + +The inherited PR #5818 process-sharing boundary remains: this is not a second cold source execution. The two literal arithmetic implementations still execute fully, with this dense implementation reusing only its own exact scalar setup. Same-agent checks and hosted CI are not independent human or proof-kernel acceptance. The five framework assumptions, conditional kappa and selected record are unchanged. Kappa research, its monitors, automations, literature work and workers remain paused. + +## Open next questions + +- Does this speedup hold on a second host? Repeat the exact bounded pair and retain all samples; no universal guarantee follows from one baseline here. +- Can a changed compiler use the technique? Authenticate its full closure, remap all AST and key-domain obligations and run finite feasibility before construction. The current source/AST pins deliberately reject changed methods. +- Is the remaining complete source replay now the bottleneck? Profile again only under a separately authorized task. This submission releases its bounded scope and starts no successor work or kappa experiment. + +## Credit + +Ali Romman supplied [PR #5704](https://github.com/CrocSwap/integer-mult-bounds/pull/5704), [PR #5757](https://github.com/CrocSwap/integer-mult-bounds/pull/5757), the original literal interpreters, controls and engine; preserve [PR #5599](https://github.com/CrocSwap/integer-mult-bounds/pull/5599) and the native/controller/compiler/helper/BIT/classical stabilizer lineage. [PR #5816](https://github.com/CrocSwap/integer-mult-bounds/pull/5816) supplied Linux qualification and the resource guard; [PR #5818](https://github.com/CrocSwap/integer-mult-bounds/pull/5818) supplied single-pass orchestration. The retained archive and NOTICE preserve full attribution. New setup derivation, finite controls, profiling and measurements: Chris R / Clear1nsight, with substantial OpenAI Codex assistance; no subagents. Memoization and tabulation are standard techniques. Apache-2.0. diff --git a/research/literal-gate-setup-reuse/SOURCES.json b/research/literal-gate-setup-reuse/SOURCES.json new file mode 100644 index 0000000000..10dc2560db --- /dev/null +++ b/research/literal-gate-setup-reuse/SOURCES.json @@ -0,0 +1,35 @@ +{ + "schema_version": 1, + "base_commit": "de5ec2e7a6074068452f45b1a191b5c72832df4a", + "files": [ + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "581f8d87008354eb5b869f7ed9de1317ad837ce8", + "sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + }, + { + "path": "research/literal-gate-setup-reuse/inputs/PR5818.tar", + "usage": "input", + "git_blob": "6437d14d3bc53a6e87fe49a7fc4a3e4d708713f9", + "sha256": "f166f27e7c247315e852f78e30b2d348e9b66518645b783b5344a6767d87e7cc", + "pin": "head:aa49178b0b16cf61ddacfd487226b77baa62d708:research/literal-gate-setup-reuse/inputs/PR5818.tar" + } + ], + "external_origin": { + "pr": 5818, + "head": "a0171b8d2f942cdfc5295307548fe484c570b1ba", + "note": "Complete official 45-file export retained as immutable input; original 54-file scientific closure and notices unchanged. Pending origin is not claimed as upstream main ancestry." + }, + "predecessor_validation": { + "pr": 5816, + "head": "dd59757bd1d938e2aed75e73f24e7ae7b8054211", + "science_commit": "5195ab6d93425bb47b2bb8f9acba05d2ae307413" + } +} diff --git a/research/literal-gate-setup-reuse/TASK.json b/research/literal-gate-setup-reuse/TASK.json new file mode 100644 index 0000000000..261b0e2c9e --- /dev/null +++ b/research/literal-gate-setup-reuse/TASK.json @@ -0,0 +1,66 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "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_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Resolve the current selected review, separate complex/ordinary BIT/admitted BIT/outer budgets, and compare the card against live handoffs before starting. Historical ceilings require exact source/model equivalence.", + "scope": "Source-binding orientation only; not a scientific replay or all-size proof. Materialize selected inputs if this checkout is sparse." + }, + "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", + "scope_change_reason": "Profiling rejects whole-circuit tableau reuse (zero repeated circuits); optimize the measured dense literal pure P/D address/phase setup instead, retaining the second interpreter and all amplitude comparisons.", + "actual_scope": "PR5818/frozen-a0171b8/literal-only-P-D-gate-setup-tables/all-input-full-qualification", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "stop_rule": "Stop without retry on source/coverage/receipt/mode drift, unexpected stderr or resource failure. One serial profile plus first pair: 900 seconds aggregate, 600 seconds per command, 1 GiB sampled group RSS; require >=15% wall and CPU saving before expanding to separately gated qualification under 1500 seconds cumulative.", + "time_budget_minutes": 90, + "outcome": "completed", + "evidence": "PROFILE.json, BENCHMARK.json, PROOF.md, VALIDATION.json and evidence/ retain source-bound profiling, complete stdout equivalence, finite controls and guarded full runs; exact-head hosted CI is separate.", + "author": "Chris R / Clear1nsight", + "ai_assistance": "Substantial OpenAI Codex assistance for source review, execution, tooling and report; no subagents, independent human or proof-kernel acceptance.", + "open_questions": [ + { + "question": "Does this exact source-bound speedup hold on a second host?", + "why_it_matters": "One baseline observation and shared host load limit the performance conclusion.", + "first_step": "Repeat the bounded pair in a fresh work directory, retaining every sample and complete outputs.", + "blocked_by": "Separate authorized measurement; no new source or kappa transfer." + }, + { + "question": "Can this setup reuse be transferred to a changed literal compiler?", + "why_it_matters": "The method and AST sites are pinned to one original implementation.", + "first_step": "Authenticate the changed source and prove every substituted scalar lookup before any full run.", + "blocked_by": "New coverage, overlap and feasibility gates; no automatic successor admission." + } + ], + "base_commit": "de5ec2e7a6074068452f45b1a191b5c72832df4a" +} diff --git a/research/literal-gate-setup-reuse/VALIDATION.json b/research/literal-gate-setup-reuse/VALIDATION.json new file mode 100644 index 0000000000..7a0433c3bc --- /dev/null +++ b/research/literal-gate-setup-reuse/VALIDATION.json @@ -0,0 +1,43 @@ +{ + "status": "PASS_COMPLETE_FROZEN_QUALIFICATION_ONLY", + "implementation_commit": "e55f42805ce373f9b680a9a2406a035b29e88b15", + "retention_commit": "aa49178b0b16cf61ddacfd487226b77baa62d708", + "source_head": "a0171b8d2f942cdfc5295307548fe484c570b1ba", + "main": "de5ec2e7a6074068452f45b1a191b5c72832df4a", + "complete_scientific_stdout_sha256": "c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba", + "scientific_runs": [ + "profile", + "baseline", + "sealed-optimized", + "packaged-normal", + "candidate", + "packaged-optimized" + ], + "scientific_wall_seconds_total": 1408.800033081061, + "per_command_seconds": 600, + "first_profile_pair_aggregate_seconds": 900, + "later_cumulative_aggregate_seconds": 1500, + "sampled_group_rss_bytes_cap": 1073741824, + "automatic_retries": 0, + "setup_controls": 23, + "inherited_orchestration_controls": 13, + "inherited_source_controls": 7, + "top_level_corruption_control": 1, + "small_controls_normal_and_optimized": "PASS", + "sealed_mode": "-I -O -B, explicit authenticated import root", + "sealed_PATH": "", + "sealed_git_free": true, + "sealed_export_read_only_files_unchanged": 42, + "sealed_wall_seconds": 213.97179915901506, + "optimized_wall_seconds": 214.55021543402108, + "complete_outputs_identical": true, + "original_54_source_files_unchanged_each_run": true, + "new_46_member_baseline_export_checked_before_import_and_after_success": true, + "coverage": "All 17651 actual states, 9037312 amplitude entries per interpreter, complete RESULT/CROSS and all original controls; no sampling or cached acceptance.", + "performance": "One baseline / prototype pair; packaged normal and later modes are additional confirmations against the same baseline, not independent pairs.", + "runtime_closure": "Only reports/evidence added after tested implementation; byte/mode preflight and official export checked separately.", + "full_history_preflight": "Unavailable in shallow checkout; immediate declared pin ancestry checked separately.", + "hosted_ci": "Reported separately on canonical exact-head PR handoff, not mathematical acceptance.", + "kappa_research": "PAUSED", + "subagents": 0 +} diff --git a/research/literal-gate-setup-reuse/VERIFY.json b/research/literal-gate-setup-reuse/VERIFY.json new file mode 100644 index 0000000000..767d0818c9 --- /dev/null +++ b/research/literal-gate-setup-reuse/VERIFY.json @@ -0,0 +1,38 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/literal-gate-setup-reuse/inputs/PR5818.tar" + ], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "{package}/setup_checks.py" + ], + "timeout_seconds": 45, + "checks": "1522 exact original-versus-derived dense states, 22700 amplitudes, four width-nine cases and 23 complete-key/boundary/eviction/mutation/corruption controls." + }, + { + "argv": [ + "{python}", + "-B", + "{package}/inherited_controls.py" + ], + "timeout_seconds": 45, + "checks": "All 13 unchanged PR5818 stage/exception/contamination controls and seven source-custody controls, plus top-level retained-bundle byte corruption rejection before scientific imports." + }, + { + "argv": [ + "{python}", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 600, + "checks": "Fresh full source/native/caller/invoice/compiler/outer and original adapter/omission checks, complete RESULT/CROSS, all 17651 actual states and 9037312 amplitudes per literal interpreter; exact stdout and unchanged read-only exports." + } + ] +} diff --git a/research/literal-gate-setup-reuse/benchmark.py b/research/literal-gate-setup-reuse/benchmark.py new file mode 100644 index 0000000000..ded1e8c746 --- /dev/null +++ b/research/literal-gate-setup-reuse/benchmark.py @@ -0,0 +1,72 @@ +"""Fresh bounded serial pair; no retry, sampling or cached acceptance.""" +import argparse +import fcntl +from hashlib import sha256 +import json +from pathlib import Path +import runpy +import sys + +from retained import baseline +from setup_cache import require + +HERE = Path(__file__).resolve().parent +EXPECTED = 'c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba' + + +def compare(folder): + labels = ('baseline', 'candidate') + receipts = {n: json.loads((folder / 'runs' / n / 'receipt.json').read_bytes()) for n in labels} + outputs = [(folder / 'runs' / n / 'stdout.txt').read_bytes() for n in labels] + require(outputs[0] == outputs[1] and sha256(outputs[0]).hexdigest() == EXPECTED, + 'Complete frozen scientific output equivalence') + require(all(r['status'] == 'PASS' for r in receipts.values()), 'Both complete runs passed') + cpu = lambda r: r['usage']['user_seconds'] + r['usage']['system_seconds'] + old, new = (receipts[n] for n in labels) + result = {'baseline_wall_seconds': old['wall_seconds'], 'candidate_wall_seconds': new['wall_seconds'], + 'baseline_cpu_seconds': cpu(old), 'candidate_cpu_seconds': cpu(new), + 'wall_fraction_saved': 1 - new['wall_seconds'] / old['wall_seconds'], + 'cpu_fraction_saved': 1 - cpu(new) / cpu(old), 'complete_stdout_equal': True, + 'samples_per_arm': 1, 'limitations': 'One pair on a shared host; not statistical or universal.'} + (folder / 'COMPARISON.json').write_text(json.dumps(result, indent=2, sort_keys=True) + '\n') + require(min(result['wall_fraction_saved'], result['cpu_fraction_saved']) >= .15, + 'At least 15 percent wall and CPU saving') + print('PASS_LITERAL_SETUP_FIRST_PAIR', json.dumps(result, sort_keys=True), flush=True) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('phase', choices=('pair', 'optimized')) + parser.add_argument('--workdir', type=Path, required=True) + args = parser.parse_args() + folder = args.workdir.resolve() + if args.phase == 'pair': + folder.mkdir(parents=True) # Existing evidence is never overwritten. + require(folder.is_dir(), 'Existing comparison directory') + with (folder / 'execution.lock').open('a') as lock: + fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) + if args.phase == 'optimized': + saved = json.loads((folder / 'COMPARISON.json').read_bytes()) + require(saved['complete_stdout_equal'] and min(saved['wall_fraction_saved'], + saved['cpu_fraction_saved']) >= .15, 'First pair gate before optimized run') + with baseline() as base: + sys.path.insert(0, str(base)) + from source import prepared + with prepared() as root: + run = runpy.run_path(str(base / 'guard.py'))['run'] + run.__globals__.update(HERE=folder, SOURCE=root, MANIFEST=base / 'INPUT-MANIFEST.json', + AGGREGATE=900 if args.phase == 'pair' else 1500) + if args.phase == 'pair': + run('baseline', str(base / 'joint.py')) + run('candidate', str(HERE / 'verify.py')) + compare(folder) + else: + run('candidate-optimized', str(HERE / 'verify.py'), True) + require((folder / 'runs/candidate/stdout.txt').read_bytes() == + (folder / 'runs/candidate-optimized/stdout.txt').read_bytes(), + 'Complete normal and optimized stdout identical') + print('PASS_LITERAL_SETUP_OPTIMIZED_QUALIFICATION', flush=True) + + +if __name__ == '__main__': + main() diff --git a/research/literal-gate-setup-reuse/candidate.py b/research/literal-gate-setup-reuse/candidate.py new file mode 100644 index 0000000000..117c23a4ce --- /dev/null +++ b/research/literal-gate-setup-reuse/candidate.py @@ -0,0 +1,40 @@ +"""Install literal-only setup in the frozen complete PR5818 qualification.""" +from pathlib import Path +import runpy +import sys + +from setup_cache import bind, require + + +def run(base): + sys.path.insert(0, str(base)) + from source import prepared + with prepared() as root: + entry = root / 'research/selected-quadratic-replay' + sys.path.insert(0, str(entry)) + import checks + original_load = checks.load + installations = [] + + def load(name, path): + module = original_load(name, path) + if name == 'selected_cross_literal_compiler': + setup, method, binding = bind(module) + installations.append((module, method, setup, binding)) + return module + + checks.load = load + try: + joint = runpy.run_path(str(base / 'joint.py')) + joint['run'](root) + require(len(installations) == 1, 'Exactly one literal setup installation') + _, _, setup, binding = installations[0] + require(setup.cached.cache_info().hits > 0 and setup.cached.cache_info().currsize <= 512, + 'Actual bounded setup reuse') + return {'binding': binding, 'cache': setup.cached.cache_info()._asdict(), + 'source_head': 'a0171b8d2f942cdfc5295307548fe484c570b1ba', + 'second_literal': 'Original unchanged independent native_verify.state'} + finally: + checks.load = original_load + for module, method, _, _ in installations: + module.Op.zero_state = method diff --git a/research/literal-gate-setup-reuse/evidence/INHERITED-NORMAL.txt b/research/literal-gate-setup-reuse/evidence/INHERITED-NORMAL.txt new file mode 100644 index 0000000000..fd610f7344 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/INHERITED-NORMAL.txt @@ -0,0 +1,3 @@ +PASS_LITERAL_SETUP_BUNDLE_CORRUPTION_BEFORE_IMPORT +PASS_SINGLE_PASS_SMALL_FEASIBILITY {"amplitudes_per_interpreter": 1536, "complete_tiny_receipts_equal": true, "controls": {"cache_leak": "Unchanged pre-oracle cache", "control_contamination": "No control trace contamination", "counter_leak": "Unchanged pre-oracle counters", "cross_argv": "Exact cross source arguments", "cross_exception": "sentinel cross exception", "dirty_counter": "Controls reset state counters", "omit_handoff": "Complete cross entry point", "omit_source": "Complete verify entry point", "repeat_handoff": "One trace handoff", "repeat_source": "Exactly one source execution", "source_argv": "Exact source arguments", "stale_cross": "Fresh cross observer", "verify_exception": "sentinel verify exception"}, "literal_interpreters": 2, "source_executions": 1, "tiny_inputs": 3} +PASS_SINGLE_PASS_SOURCE_CONTROLS {"compiler": {"predicate": "Official export hash", "scientific_import_started": false}, "cross_entry": {"predicate": "Official export hash", "scientific_import_started": false}, "engine": {"predicate": "Official export hash", "scientific_import_started": false}, "expected_cross": {"predicate": "Official export hash", "scientific_import_started": false}, "manifest": {"predicate": "Complete manifest hash", "scientific_import_started": false}, "verify_entry": {"predicate": "Official export hash", "scientific_import_started": false}, "word": {"predicate": "Official export hash", "scientific_import_started": false}} diff --git a/research/literal-gate-setup-reuse/evidence/INHERITED-OPTIMIZED.txt b/research/literal-gate-setup-reuse/evidence/INHERITED-OPTIMIZED.txt new file mode 100644 index 0000000000..fd610f7344 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/INHERITED-OPTIMIZED.txt @@ -0,0 +1,3 @@ +PASS_LITERAL_SETUP_BUNDLE_CORRUPTION_BEFORE_IMPORT +PASS_SINGLE_PASS_SMALL_FEASIBILITY {"amplitudes_per_interpreter": 1536, "complete_tiny_receipts_equal": true, "controls": {"cache_leak": "Unchanged pre-oracle cache", "control_contamination": "No control trace contamination", "counter_leak": "Unchanged pre-oracle counters", "cross_argv": "Exact cross source arguments", "cross_exception": "sentinel cross exception", "dirty_counter": "Controls reset state counters", "omit_handoff": "Complete cross entry point", "omit_source": "Complete verify entry point", "repeat_handoff": "One trace handoff", "repeat_source": "Exactly one source execution", "source_argv": "Exact source arguments", "stale_cross": "Fresh cross observer", "verify_exception": "sentinel verify exception"}, "literal_interpreters": 2, "source_executions": 1, "tiny_inputs": 3} +PASS_SINGLE_PASS_SOURCE_CONTROLS {"compiler": {"predicate": "Official export hash", "scientific_import_started": false}, "cross_entry": {"predicate": "Official export hash", "scientific_import_started": false}, "engine": {"predicate": "Official export hash", "scientific_import_started": false}, "expected_cross": {"predicate": "Official export hash", "scientific_import_started": false}, "manifest": {"predicate": "Complete manifest hash", "scientific_import_started": false}, "verify_entry": {"predicate": "Official export hash", "scientific_import_started": false}, "word": {"predicate": "Official export hash", "scientific_import_started": false}} diff --git a/research/literal-gate-setup-reuse/evidence/SETUP-CHECKS-NORMAL.txt b/research/literal-gate-setup-reuse/evidence/SETUP-CHECKS-NORMAL.txt new file mode 100644 index 0000000000..549e6e3291 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/SETUP-CHECKS-NORMAL.txt @@ -0,0 +1 @@ +PASS_LITERAL_SETUP_FEASIBILITY {"amplitude_entries": 22700, "binding": {"original_method_sha256": "ebb92d6870d73dc452faf6d8c3c62710539ffb9bae3a5588dc694fe2693c6509", "prepared_ast_sha256": "eb4c3f7790c6b262fb0e4167b26be34f358d82498606d1ba9b448716274fe5b8", "sites": {"D": 1, "P": 1, "mv": 1, "qvalue": 1}}, "cases": 1522, "controls": {"bad_matrix_length": "ValueError: Complete setup matrix", "bad_phase_length": "ValueError: Complete setup phase data", "bool_matrix": "ValueError: Exact setup key types", "bool_phase": "ValueError: Exact setup key types", "bool_width": "ValueError: Exact bounded setup width", "bounded_eviction": "PASS", "capacity_0": "ValueError: Bounded setup capacity", "capacity_513": "ValueError: Bounded setup capacity", "capacity_True": "ValueError: Bounded setup capacity", "changed_literal_method": "ValueError: Exact original literal method", "changed_phase": "PASS", "changed_width": "PASS", "corrupt_D_detected": "PASS", "corrupt_P_detected": "PASS", "exception_0": "RuntimeError: setup sentinel", "exception_1": "RuntimeError: setup sentinel", "float_matrix": "ValueError: Exact setup key types", "float_width": "ValueError: Exact bounded setup width", "fresh_dense_output": "PASS", "immutable_return": "AttributeError: 'tuple' object has no attribute '__setitem__'", "input_snapshot": "PASS", "unbounded_width": "ValueError: Exact bounded setup width", "unknown_gate": "ValueError: Literal setup gate"}, "full_width_cases": 4, "max_setup_capacity": 512} diff --git a/research/literal-gate-setup-reuse/evidence/SETUP-CHECKS-OPTIMIZED.txt b/research/literal-gate-setup-reuse/evidence/SETUP-CHECKS-OPTIMIZED.txt new file mode 100644 index 0000000000..549e6e3291 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/SETUP-CHECKS-OPTIMIZED.txt @@ -0,0 +1 @@ +PASS_LITERAL_SETUP_FEASIBILITY {"amplitude_entries": 22700, "binding": {"original_method_sha256": "ebb92d6870d73dc452faf6d8c3c62710539ffb9bae3a5588dc694fe2693c6509", "prepared_ast_sha256": "eb4c3f7790c6b262fb0e4167b26be34f358d82498606d1ba9b448716274fe5b8", "sites": {"D": 1, "P": 1, "mv": 1, "qvalue": 1}}, "cases": 1522, "controls": {"bad_matrix_length": "ValueError: Complete setup matrix", "bad_phase_length": "ValueError: Complete setup phase data", "bool_matrix": "ValueError: Exact setup key types", "bool_phase": "ValueError: Exact setup key types", "bool_width": "ValueError: Exact bounded setup width", "bounded_eviction": "PASS", "capacity_0": "ValueError: Bounded setup capacity", "capacity_513": "ValueError: Bounded setup capacity", "capacity_True": "ValueError: Bounded setup capacity", "changed_literal_method": "ValueError: Exact original literal method", "changed_phase": "PASS", "changed_width": "PASS", "corrupt_D_detected": "PASS", "corrupt_P_detected": "PASS", "exception_0": "RuntimeError: setup sentinel", "exception_1": "RuntimeError: setup sentinel", "float_matrix": "ValueError: Exact setup key types", "float_width": "ValueError: Exact bounded setup width", "fresh_dense_output": "PASS", "immutable_return": "AttributeError: 'tuple' object has no attribute '__setitem__'", "input_snapshot": "PASS", "unbounded_width": "ValueError: Exact bounded setup width", "unknown_gate": "ValueError: Literal setup gate"}, "full_width_cases": 4, "max_setup_capacity": 512} diff --git a/research/literal-gate-setup-reuse/evidence/UPSTREAM-REFRESH.json b/research/literal-gate-setup-reuse/evidence/UPSTREAM-REFRESH.json new file mode 100644 index 0000000000..026c676ac7 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/UPSTREAM-REFRESH.json @@ -0,0 +1,93 @@ +{ + "main": "de5ec2e7a6074068452f45b1a191b5c72832df4a", + "source": { + "head": "a0171b8d2f942cdfc5295307548fe484c570b1ba", + "state": "open", + "merged": false + }, + "source_comments": [ + { + "id": 6432373243, + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/5818#issuecomment-6432373243", + "author": "Clear1nsight", + "claim": false, + "handoff": true + }, + { + "id": 6432828801, + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/5818#issuecomment-6432828801", + "author": "Clear1nsight", + "claim": true, + "handoff": false + } + ], + "queries": [ + { + "query": "\"5818\"", + "issues": [ + { + "number": 5818, + "title": "Share complete P104 qualification: 33.7% less time, both literal oracles", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/5818" + } + ] + }, + { + "query": "\"literal\" \"setup\"", + "issues": [ + { + "number": 5721, + "title": "Use Windows Job Objects in the shared Git blob reader", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/5721" + }, + { + "number": 3423, + "title": "Certify actual P104 Newton producer and consumer interfaces", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/3423" + }, + { + "number": 3967, + "title": "Refresh R437/OQ4 adapter and bind actual rank26/COPY515 physical returns", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/3967" + }, + { + "number": 4062, + "title": "Compose shared radix and forward admission across actual pooled preparation", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/4062" + }, + { + "number": 4167, + "title": "Share closed primitive engines to remove parent parking at child calls", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/4167" + }, + { + "number": 4176, + "title": "Integrate the R437 carrier compiler, numerical invoice and paid local caller", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/4176" + }, + { + "number": 4177, + "title": "Prove a complete terminal-band QQ16 cost exclusion", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/4177" + }, + { + "number": 5399, + "title": "Independently validate \u03ba = 0.00302725 and the owned-transpose phase/cost proof", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/5399" + }, + { + "number": 3954, + "title": "research: derive P104 two-axis endpoint intertwiners and cost gate", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/3954" + }, + { + "number": 5467, + "title": "Share actual inverse-code quotients and compile native producer units (no new kappa)", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/5467" + } + ] + } + ], + "coverage": "Bounded targeted PR body searches and exact source PR comments; no exhaustive historical, unpublished, private or general feed coverage.", + "refreshed_utc": "2026-10-27T03:46:27Z" +} diff --git a/research/literal-gate-setup-reuse/evidence/baseline/receipt.json b/research/literal-gate-setup-reuse/evidence/baseline/receipt.json new file mode 100644 index 0000000000..ffcbd39b98 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/baseline/receipt.json @@ -0,0 +1,27 @@ +{ + "exit": 0, + "label": "baseline", + "manifest_sha256": "7be632febc51fa5040cdd06a86c1c4f8b95c2632cc885b49af05bba838b672be", + "optimized": false, + "original_local_receipt_sha256": "5aaff8c3c5fce72041db9feb86179ed108c3d0fbe6bbbf6797f7c0b859718f65", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "ae67bb805b68ed5d4c610c7ac427e955681b39faee398bffd3caf2d73ac574f2", + "sampled_process_group_rss_bytes": 540618752, + "script": "[local absolute script path removed]/joint.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "95719901778f8c6651f9cab2bf171d87d6fb015569d6d22897e0d40e3e385fc5", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 963, + "stdout_sha256": "c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 531488, + "system_seconds": 0.39, + "user_seconds": 282.08 + }, + "wall_seconds": 283.3212143800047 +} diff --git a/research/literal-gate-setup-reuse/evidence/baseline/stderr.txt b/research/literal-gate-setup-reuse/evidence/baseline/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/literal-gate-setup-reuse/evidence/baseline/stdout.txt b/research/literal-gate-setup-reuse/evidence/baseline/stdout.txt new file mode 100644 index 0000000000..c55ebcd2cd --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/baseline/stdout.txt @@ -0,0 +1,7 @@ +PASS 13 prefix/suffix cuts, every independent row and dense reverse columns +PASS every native phase, productive target and physical caller contact +PASS_P104_HELPER_SUBSPACE_KAPPA_00310045 +{"gain": "61/4000000", "kappa": "62009/20000000", "paid_calls": 66726, "productive_fields": 13048, "raw_root_interval": ["77511407681/25000000000000", "12401825229/4000000000000"]} +PASS_COMPLETE_SELECTED_QUADRATIC_REPLAY +PASS_ALL_SELECTED_LITERAL_STATES {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "amplitudes_per_literal_interpreter": 9037312, "distinct_inputs": 17651, "input_trace_sha256": "73ac04db73d83151efb474925d48298664cc7490d31bdec7a70dcf79b448f481", "literal_interpreters": 2} +PASS_SINGLE_PASS_COMPLETE_QUALIFICATION {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "distinct_inputs": 17651, "source_executions": 1, "trace_handoffs": 1} diff --git a/research/literal-gate-setup-reuse/evidence/baseline/usage.json b/research/literal-gate-setup-reuse/evidence/baseline/usage.json new file mode 100644 index 0000000000..434b555262 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/baseline/usage.json @@ -0,0 +1 @@ +{"user_seconds":282.08,"system_seconds":0.39,"kernel_max_rss_kib":531488,"exit":0} diff --git a/research/literal-gate-setup-reuse/evidence/candidate/receipt.json b/research/literal-gate-setup-reuse/evidence/candidate/receipt.json new file mode 100644 index 0000000000..b584d999df --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/candidate/receipt.json @@ -0,0 +1,27 @@ +{ + "exit": 0, + "label": "candidate", + "manifest_sha256": "7be632febc51fa5040cdd06a86c1c4f8b95c2632cc885b49af05bba838b672be", + "optimized": false, + "original_local_receipt_sha256": "a50f156fded8973b6e72def70fe58a542e9d67c2ac76f4e2a55965d32505c319", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "ae67bb805b68ed5d4c610c7ac427e955681b39faee398bffd3caf2d73ac574f2", + "sampled_process_group_rss_bytes": 543092736, + "script": "[local absolute script path removed]/candidate-run.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "95719901778f8c6651f9cab2bf171d87d6fb015569d6d22897e0d40e3e385fc5", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 963, + "stdout_sha256": "c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 533616, + "system_seconds": 0.4, + "user_seconds": 207.02 + }, + "wall_seconds": 207.92062770601478 +} diff --git a/research/literal-gate-setup-reuse/evidence/candidate/stderr.txt b/research/literal-gate-setup-reuse/evidence/candidate/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/literal-gate-setup-reuse/evidence/candidate/stdout.txt b/research/literal-gate-setup-reuse/evidence/candidate/stdout.txt new file mode 100644 index 0000000000..c55ebcd2cd --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/candidate/stdout.txt @@ -0,0 +1,7 @@ +PASS 13 prefix/suffix cuts, every independent row and dense reverse columns +PASS every native phase, productive target and physical caller contact +PASS_P104_HELPER_SUBSPACE_KAPPA_00310045 +{"gain": "61/4000000", "kappa": "62009/20000000", "paid_calls": 66726, "productive_fields": 13048, "raw_root_interval": ["77511407681/25000000000000", "12401825229/4000000000000"]} +PASS_COMPLETE_SELECTED_QUADRATIC_REPLAY +PASS_ALL_SELECTED_LITERAL_STATES {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "amplitudes_per_literal_interpreter": 9037312, "distinct_inputs": 17651, "input_trace_sha256": "73ac04db73d83151efb474925d48298664cc7490d31bdec7a70dcf79b448f481", "literal_interpreters": 2} +PASS_SINGLE_PASS_COMPLETE_QUALIFICATION {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "distinct_inputs": 17651, "source_executions": 1, "trace_handoffs": 1} diff --git a/research/literal-gate-setup-reuse/evidence/candidate/usage.json b/research/literal-gate-setup-reuse/evidence/candidate/usage.json new file mode 100644 index 0000000000..ee4e77da60 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/candidate/usage.json @@ -0,0 +1 @@ +{"user_seconds":207.02,"system_seconds":0.40,"kernel_max_rss_kib":533616,"exit":0} diff --git a/research/literal-gate-setup-reuse/evidence/method/candidate-run.py.txt b/research/literal-gate-setup-reuse/evidence/method/candidate-run.py.txt new file mode 100644 index 0000000000..90aa2806b1 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/method/candidate-run.py.txt @@ -0,0 +1,10 @@ +import json +from pathlib import Path +import sys + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE/'prototype')) +from candidate import run + +result = run() +(HERE/'SETUP-STATS.json').write_text(json.dumps(result,indent=2,sort_keys=True)+'\n') diff --git a/research/literal-gate-setup-reuse/evidence/method/first-pair.py.txt b/research/literal-gate-setup-reuse/evidence/method/first-pair.py.txt new file mode 100644 index 0000000000..3222c0184d --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/method/first-pair.py.txt @@ -0,0 +1,25 @@ +"""One unprofiled PR5818/candidate pair after the small feasibility gate.""" +from pathlib import Path +import subprocess +import sys +import json + +HERE = Path(__file__).resolve().parent +BASE = HERE.parent/'single-pass-qualification-20261027/repo/research/selected-single-pass-qualification' +for label, script in [('baseline', BASE/'joint.py'), ('candidate', HERE/'candidate-run.py')]: + completed = subprocess.run([sys.executable,'-B',str(HERE/'guarded.py'),label,str(script)]) + if completed.returncode: + raise SystemExit(completed.returncode) +old = json.loads((HERE/'runs/baseline/receipt.json').read_bytes()) +new = json.loads((HERE/'runs/candidate/receipt.json').read_bytes()) +cpu = lambda r: r['usage']['user_seconds'] + r['usage']['system_seconds'] +result = {'baseline_wall_seconds':old['wall_seconds'],'candidate_wall_seconds':new['wall_seconds'], + 'baseline_cpu_seconds':cpu(old),'candidate_cpu_seconds':cpu(new), + 'wall_fraction_saved':1-new['wall_seconds']/old['wall_seconds'], + 'cpu_fraction_saved':1-cpu(new)/cpu(old), + 'complete_stdout_equal':old['stdout_sha256']==new['stdout_sha256'], + 'profile_included_in_comparison':False,'samples_per_arm':1} +(HERE/'COMPARISON.json').write_text(json.dumps(result,indent=2,sort_keys=True)+'\n') +if not result['complete_stdout_equal'] or min(result['wall_fraction_saved'],result['cpu_fraction_saved'])<.15: + raise ValueError('The required full-coverage 15 percent wall and CPU gate failed') +print('PASS_LITERAL_SETUP_FIRST_PAIR',json.dumps(result,sort_keys=True)) diff --git a/research/literal-gate-setup-reuse/evidence/method/guarded.py.txt b/research/literal-gate-setup-reuse/evidence/method/guarded.py.txt new file mode 100644 index 0000000000..f79f518b80 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/method/guarded.py.txt @@ -0,0 +1,34 @@ +"""Reuse the unchanged PR5816/5818 resource guard for this bounded round.""" +import argparse +import fcntl +import json +from pathlib import Path +import runpy +import sys + +HERE = Path(__file__).resolve().parent +PACKAGE = HERE.parent / 'single-pass-qualification-20261027/repo/research/selected-single-pass-qualification' +sys.path.insert(0, str(PACKAGE)) +from source import prepared + +parser = argparse.ArgumentParser() +parser.add_argument('label') +parser.add_argument('script', type=Path) +parser.add_argument('--optimized', action='store_true') +parser.add_argument('--qualification', action='store_true') +args = parser.parse_args() +if args.qualification: + result = json.loads((HERE/'COMPARISON.json').read_bytes()) + if not result['complete_stdout_equal'] or min(result['wall_fraction_saved'],result['cpu_fraction_saved']) < .15: + raise ValueError('First-pair gate required before qualification') +with (HERE / 'execution.lock').open('a') as lock: + fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) + with prepared() as root: + module = runpy.run_path(str(PACKAGE / 'guard.py')) + run = module['run'] + run.__globals__.update(HERE=HERE, SOURCE=root, MANIFEST=PACKAGE/'INPUT-MANIFEST.json', + AGGREGATE=1500 if args.qualification else 900) + receipt = run(args.label, str(args.script.resolve()), args.optimized) + expected = 'c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba' + if receipt['stdout_sha256'] != expected: + raise ValueError('Complete PR5818 scientific stdout differs') diff --git a/research/literal-gate-setup-reuse/evidence/method/profile-run.py.txt b/research/literal-gate-setup-reuse/evidence/method/profile-run.py.txt new file mode 100644 index 0000000000..92a1631417 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/method/profile-run.py.txt @@ -0,0 +1,92 @@ +"""Lightweight whole-call timing; preserve every PR5818 scientific output.""" +from collections import Counter, defaultdict +import json +from pathlib import Path +import runpy +import sys +from time import perf_counter_ns + +HERE = Path(__file__).resolve().parent +PACKAGE = HERE.parent / 'single-pass-qualification-20261027/repo/research/selected-single-pass-qualification' +sys.path.insert(0, str(PACKAGE)) +from source import prepared + +timings = defaultdict(lambda: {'calls': 0, 'seconds': 0.0}) +circuits = Counter() +gate_visits = Counter() +restores = [] + + +def timed(label, function): + def call(*args, **kwargs): + started = perf_counter_ns() + try: + return function(*args, **kwargs) + finally: + timings[label]['calls'] += 1 + timings[label]['seconds'] += (perf_counter_ns() - started) / 1e9 + return call + + +with prepared() as root: + entry = root / 'research/selected-quadratic-replay' + sys.path.insert(0, str(entry)) + import checks + import state_adapter as adapter + original_load = checks.load + original_support = adapter.support + adapter.support = timed('quadratic_support_all_phases', original_support) + + def load(name, path): + module = original_load(name, path) + if name == 'selected_cross_literal_compiler': + original = module.Op.zero_state + module.Op.zero_state = timed('cross_dense_literal', original) + restores.append((module.Op, 'zero_state', original)) + elif name == 'selected_cross_literal_native': + original = module.tableau + timer = timed('cross_circuit_tableau', original) + + def tableau(circuit, n=9): + circuits[(n, adapter.frozen(circuit))] += 1 + gate_visits.update(gate[0] for gate in circuit) + return timer(circuit, n) + + module.tableau = tableau + restores.append((module, 'tableau', original)) + original = module.state + module.state = timed('cross_sparse_literal', original) + restores.append((module, 'state', original)) + return module + + checks.load = load + joint = runpy.run_path(str(PACKAGE / 'joint.py')) + original_qualify = joint['run'].__globals__['qualify'] + + def qualify(verify, cross, source, state): + original_main = source.main + source.main = timed('complete_source_replay', original_main) + try: + return original_qualify(timed('verify_entry_inclusive', verify), + timed('cross_entry_inclusive', cross), source, state) + finally: + source.main = original_main + + joint['run'].__globals__['qualify'] = qualify + try: + joint['run'](root) + finally: + checks.load = original_load + adapter.support = original_support + for owner, name, value in restores: + setattr(owner, name, value) + +result = {'method': 'Whole-function perf_counter timings; nested totals overlap. No per-amplitude profiler.', + 'timings': dict(timings), 'tableau_calls': sum(circuits.values()), + 'unique_width_circuits': len(circuits), + 'repeated_tableau_calls': sum(circuits.values()) - len(circuits), + 'gate_visits_across_literal_state_circuits': dict(gate_visits), + 'largest_circuit_repeat': max(circuits.values()), + 'source_head': 'a0171b8d2f942cdfc5295307548fe484c570b1ba', + 'coverage': 'Both original RESULT/CROSS, full actual trace, both literal interpreters and all original controls executed.'} +(HERE / 'PROFILE.json').write_text(json.dumps(result, indent=2, sort_keys=True) + '\n') diff --git a/research/literal-gate-setup-reuse/evidence/packaged-normal/receipt.json b/research/literal-gate-setup-reuse/evidence/packaged-normal/receipt.json new file mode 100644 index 0000000000..f28a01de7f --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/packaged-normal/receipt.json @@ -0,0 +1,27 @@ +{ + "exit": 0, + "label": "packaged-normal", + "manifest_sha256": "7be632febc51fa5040cdd06a86c1c4f8b95c2632cc885b49af05bba838b672be", + "optimized": false, + "original_local_receipt_sha256": "5d7fd585c48b3a7c5b2dce56e2abc9b08d8d5c9b5a293acb02c40dcc1e1fc5e9", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "ae67bb805b68ed5d4c610c7ac427e955681b39faee398bffd3caf2d73ac574f2", + "sampled_process_group_rss_bytes": 544227328, + "script": "[local absolute script path removed]/verify.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "95719901778f8c6651f9cab2bf171d87d6fb015569d6d22897e0d40e3e385fc5", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 963, + "stdout_sha256": "c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 535396, + "system_seconds": 0.41, + "user_seconds": 208.79 + }, + "wall_seconds": 209.92502825299744 +} diff --git a/research/literal-gate-setup-reuse/evidence/packaged-normal/stderr.txt b/research/literal-gate-setup-reuse/evidence/packaged-normal/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/literal-gate-setup-reuse/evidence/packaged-normal/stdout.txt b/research/literal-gate-setup-reuse/evidence/packaged-normal/stdout.txt new file mode 100644 index 0000000000..c55ebcd2cd --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/packaged-normal/stdout.txt @@ -0,0 +1,7 @@ +PASS 13 prefix/suffix cuts, every independent row and dense reverse columns +PASS every native phase, productive target and physical caller contact +PASS_P104_HELPER_SUBSPACE_KAPPA_00310045 +{"gain": "61/4000000", "kappa": "62009/20000000", "paid_calls": 66726, "productive_fields": 13048, "raw_root_interval": ["77511407681/25000000000000", "12401825229/4000000000000"]} +PASS_COMPLETE_SELECTED_QUADRATIC_REPLAY +PASS_ALL_SELECTED_LITERAL_STATES {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "amplitudes_per_literal_interpreter": 9037312, "distinct_inputs": 17651, "input_trace_sha256": "73ac04db73d83151efb474925d48298664cc7490d31bdec7a70dcf79b448f481", "literal_interpreters": 2} +PASS_SINGLE_PASS_COMPLETE_QUALIFICATION {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "distinct_inputs": 17651, "source_executions": 1, "trace_handoffs": 1} diff --git a/research/literal-gate-setup-reuse/evidence/packaged-normal/usage.json b/research/literal-gate-setup-reuse/evidence/packaged-normal/usage.json new file mode 100644 index 0000000000..f563a90140 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/packaged-normal/usage.json @@ -0,0 +1 @@ +{"user_seconds":208.79,"system_seconds":0.41,"kernel_max_rss_kib":535396,"exit":0} diff --git a/research/literal-gate-setup-reuse/evidence/packaged-optimized/receipt.json b/research/literal-gate-setup-reuse/evidence/packaged-optimized/receipt.json new file mode 100644 index 0000000000..c6f69e8c95 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/packaged-optimized/receipt.json @@ -0,0 +1,27 @@ +{ + "exit": 0, + "label": "packaged-optimized", + "manifest_sha256": "7be632febc51fa5040cdd06a86c1c4f8b95c2632cc885b49af05bba838b672be", + "optimized": true, + "original_local_receipt_sha256": "471b0af1131a388dbc6eaab1cf4c955e8dbac954433ee7f70304aaf8c1b4d3e3", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "ae67bb805b68ed5d4c610c7ac427e955681b39faee398bffd3caf2d73ac574f2", + "sampled_process_group_rss_bytes": 544104448, + "script": "[local absolute script path removed]/verify.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "95719901778f8c6651f9cab2bf171d87d6fb015569d6d22897e0d40e3e385fc5", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 963, + "stdout_sha256": "c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 534892, + "system_seconds": 0.41, + "user_seconds": 213.15 + }, + "wall_seconds": 214.55021543402108 +} diff --git a/research/literal-gate-setup-reuse/evidence/packaged-optimized/stderr.txt b/research/literal-gate-setup-reuse/evidence/packaged-optimized/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/literal-gate-setup-reuse/evidence/packaged-optimized/stdout.txt b/research/literal-gate-setup-reuse/evidence/packaged-optimized/stdout.txt new file mode 100644 index 0000000000..c55ebcd2cd --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/packaged-optimized/stdout.txt @@ -0,0 +1,7 @@ +PASS 13 prefix/suffix cuts, every independent row and dense reverse columns +PASS every native phase, productive target and physical caller contact +PASS_P104_HELPER_SUBSPACE_KAPPA_00310045 +{"gain": "61/4000000", "kappa": "62009/20000000", "paid_calls": 66726, "productive_fields": 13048, "raw_root_interval": ["77511407681/25000000000000", "12401825229/4000000000000"]} +PASS_COMPLETE_SELECTED_QUADRATIC_REPLAY +PASS_ALL_SELECTED_LITERAL_STATES {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "amplitudes_per_literal_interpreter": 9037312, "distinct_inputs": 17651, "input_trace_sha256": "73ac04db73d83151efb474925d48298664cc7490d31bdec7a70dcf79b448f481", "literal_interpreters": 2} +PASS_SINGLE_PASS_COMPLETE_QUALIFICATION {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "distinct_inputs": 17651, "source_executions": 1, "trace_handoffs": 1} diff --git a/research/literal-gate-setup-reuse/evidence/packaged-optimized/usage.json b/research/literal-gate-setup-reuse/evidence/packaged-optimized/usage.json new file mode 100644 index 0000000000..ee26011628 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/packaged-optimized/usage.json @@ -0,0 +1 @@ +{"user_seconds":213.15,"system_seconds":0.41,"kernel_max_rss_kib":534892,"exit":0} diff --git a/research/literal-gate-setup-reuse/evidence/profile/receipt.json b/research/literal-gate-setup-reuse/evidence/profile/receipt.json new file mode 100644 index 0000000000..d262a95e5b --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/profile/receipt.json @@ -0,0 +1,27 @@ +{ + "exit": 0, + "label": "profile", + "manifest_sha256": "7be632febc51fa5040cdd06a86c1c4f8b95c2632cc885b49af05bba838b672be", + "optimized": false, + "original_local_receipt_sha256": "116f5e3cd9bd736a73d072c494df537f547db287c971824c8cebfc941b75e6e4", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "ae67bb805b68ed5d4c610c7ac427e955681b39faee398bffd3caf2d73ac574f2", + "sampled_process_group_rss_bytes": 571953152, + "script": "[local absolute script path removed]/profile-run.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "95719901778f8c6651f9cab2bf171d87d6fb015569d6d22897e0d40e3e385fc5", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 963, + "stdout_sha256": "c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 562472, + "system_seconds": 0.43, + "user_seconds": 277.63 + }, + "wall_seconds": 279.11114814900793 +} diff --git a/research/literal-gate-setup-reuse/evidence/profile/stderr.txt b/research/literal-gate-setup-reuse/evidence/profile/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/literal-gate-setup-reuse/evidence/profile/stdout.txt b/research/literal-gate-setup-reuse/evidence/profile/stdout.txt new file mode 100644 index 0000000000..c55ebcd2cd --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/profile/stdout.txt @@ -0,0 +1,7 @@ +PASS 13 prefix/suffix cuts, every independent row and dense reverse columns +PASS every native phase, productive target and physical caller contact +PASS_P104_HELPER_SUBSPACE_KAPPA_00310045 +{"gain": "61/4000000", "kappa": "62009/20000000", "paid_calls": 66726, "productive_fields": 13048, "raw_root_interval": ["77511407681/25000000000000", "12401825229/4000000000000"]} +PASS_COMPLETE_SELECTED_QUADRATIC_REPLAY +PASS_ALL_SELECTED_LITERAL_STATES {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "amplitudes_per_literal_interpreter": 9037312, "distinct_inputs": 17651, "input_trace_sha256": "73ac04db73d83151efb474925d48298664cc7490d31bdec7a70dcf79b448f481", "literal_interpreters": 2} +PASS_SINGLE_PASS_COMPLETE_QUALIFICATION {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "distinct_inputs": 17651, "source_executions": 1, "trace_handoffs": 1} diff --git a/research/literal-gate-setup-reuse/evidence/profile/usage.json b/research/literal-gate-setup-reuse/evidence/profile/usage.json new file mode 100644 index 0000000000..e621fbec1b --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/profile/usage.json @@ -0,0 +1 @@ +{"user_seconds":277.63,"system_seconds":0.43,"kernel_max_rss_kib":562472,"exit":0} diff --git a/research/literal-gate-setup-reuse/evidence/sealed-optimized/receipt.json b/research/literal-gate-setup-reuse/evidence/sealed-optimized/receipt.json new file mode 100644 index 0000000000..9b095150b0 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/sealed-optimized/receipt.json @@ -0,0 +1,27 @@ +{ + "exit": 0, + "label": "sealed-optimized", + "manifest_sha256": "7be632febc51fa5040cdd06a86c1c4f8b95c2632cc885b49af05bba838b672be", + "optimized": true, + "original_local_receipt_sha256": "48a24439253d188f8a38e23598d75f22d57a75391d0b7f1c5441a6966e262adb", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "ae67bb805b68ed5d4c610c7ac427e955681b39faee398bffd3caf2d73ac574f2", + "sampled_process_group_rss_bytes": 544493568, + "script": "[local absolute script path removed]/sealed-driver.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "95719901778f8c6651f9cab2bf171d87d6fb015569d6d22897e0d40e3e385fc5", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 963, + "stdout_sha256": "c796be009d692546eab74e3ac084ec6badf45245841d81f101c2a164c0a6eaba", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 535144, + "system_seconds": 0.5, + "user_seconds": 212.63 + }, + "wall_seconds": 213.97179915901506 +} diff --git a/research/literal-gate-setup-reuse/evidence/sealed-optimized/stderr.txt b/research/literal-gate-setup-reuse/evidence/sealed-optimized/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/literal-gate-setup-reuse/evidence/sealed-optimized/stdout.txt b/research/literal-gate-setup-reuse/evidence/sealed-optimized/stdout.txt new file mode 100644 index 0000000000..c55ebcd2cd --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/sealed-optimized/stdout.txt @@ -0,0 +1,7 @@ +PASS 13 prefix/suffix cuts, every independent row and dense reverse columns +PASS every native phase, productive target and physical caller contact +PASS_P104_HELPER_SUBSPACE_KAPPA_00310045 +{"gain": "61/4000000", "kappa": "62009/20000000", "paid_calls": 66726, "productive_fields": 13048, "raw_root_interval": ["77511407681/25000000000000", "12401825229/4000000000000"]} +PASS_COMPLETE_SELECTED_QUADRATIC_REPLAY +PASS_ALL_SELECTED_LITERAL_STATES {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "amplitudes_per_literal_interpreter": 9037312, "distinct_inputs": 17651, "input_trace_sha256": "73ac04db73d83151efb474925d48298664cc7490d31bdec7a70dcf79b448f481", "literal_interpreters": 2} +PASS_SINGLE_PASS_COMPLETE_QUALIFICATION {"actual_state_calls": {"amplitude_entries": 19988992, "dense": 32777, "evaluations": 39041, "sparse": 6264}, "distinct_inputs": 17651, "source_executions": 1, "trace_handoffs": 1} diff --git a/research/literal-gate-setup-reuse/evidence/sealed-optimized/usage.json b/research/literal-gate-setup-reuse/evidence/sealed-optimized/usage.json new file mode 100644 index 0000000000..63b4482d31 --- /dev/null +++ b/research/literal-gate-setup-reuse/evidence/sealed-optimized/usage.json @@ -0,0 +1 @@ +{"user_seconds":212.63,"system_seconds":0.50,"kernel_max_rss_kib":535144,"exit":0} diff --git a/research/literal-gate-setup-reuse/inherited_controls.py b/research/literal-gate-setup-reuse/inherited_controls.py new file mode 100644 index 0000000000..390c1eaebd --- /dev/null +++ b/research/literal-gate-setup-reuse/inherited_controls.py @@ -0,0 +1,39 @@ +"""Run both unchanged PR5818 small-control commands in fresh interpreters.""" +import subprocess +import sys +from pathlib import Path +import tempfile + +import retained +from retained import baseline +from setup_cache import require + + +if __name__ == '__main__': + require(not sys.argv[1:], 'No inherited-control arguments') + original = retained.HERE + with tempfile.TemporaryDirectory(prefix='setup-custody-control-') as temporary: + root = Path(temporary) + (root / 'inputs').mkdir() + raw = bytearray((original / 'inputs/PR5818.tar').read_bytes()) + raw[len(raw) // 2] ^= 1 + (root / 'inputs/PR5818.tar').write_bytes(raw) + retained.HERE = root + try: + try: + retained.payload() + except ValueError as error: + require(str(error) == 'Exact PR5818 bundle', 'Exact top-level corruption predicate') + else: + raise ValueError('Corrupted top-level bundle accepted') + finally: + retained.HERE = original + print('PASS_LITERAL_SETUP_BUNDLE_CORRUPTION_BEFORE_IMPORT', flush=True) + with baseline() as base: + for script in ('checks.py', 'custody_controls.py'): + command = [sys.executable, '-B'] + if sys.flags.optimize: + command.append('-O') + command.append(str(base / script)) + completed = subprocess.run(command) + require(completed.returncode == 0, 'Original control command passed: ' + script) diff --git a/research/literal-gate-setup-reuse/inputs/PR5818.tar b/research/literal-gate-setup-reuse/inputs/PR5818.tar new file mode 100644 index 0000000000..6437d14d3b Binary files /dev/null and b/research/literal-gate-setup-reuse/inputs/PR5818.tar differ diff --git a/research/literal-gate-setup-reuse/retained.py b/research/literal-gate-setup-reuse/retained.py new file mode 100644 index 0000000000..76ea280517 --- /dev/null +++ b/research/literal-gate-setup-reuse/retained.py @@ -0,0 +1,67 @@ +"""Authenticate the unchanged complete PR5818 export before importing it.""" +from contextlib import contextmanager +from hashlib import sha256 +import json +from pathlib import Path +import tarfile +import tempfile + +HERE = Path(__file__).resolve().parent +BUNDLE_SHA256 = 'f166f27e7c247315e852f78e30b2d348e9b66518645b783b5344a6767d87e7cc' +SOURCE_HEAD = 'a0171b8d2f942cdfc5295307548fe484c570b1ba' + + +def require(ok, why): + if not ok: + raise ValueError(why) + + +def payload(): + archive = HERE / 'inputs/PR5818.tar' + require(sha256(archive.read_bytes()).hexdigest() == BUNDLE_SHA256, 'Exact PR5818 bundle') + with tarfile.open(archive, 'r:') as stream: + members = stream.getmembers() + require(len(members) == 46 and len({m.name for m in members}) == 46, 'Complete unique baseline bundle') + require(all(m.isfile() and 0 <= m.size <= 8 * 1024**2 for m in members), 'Regular bounded baseline members') + receipt = json.loads(stream.extractfile('.research-export.json').read()) + require(receipt['commit'] == SOURCE_HEAD, 'Exact baseline export head') + rows = {r['path']: r for r in receipt['files']} + require(len(rows) == len(receipt['files']) == 45, 'Complete baseline file census') + require({m.name for m in members} == set(rows) | {'.research-export.json'}, 'Exact baseline member set') + contents = {} + for member in members: + path = Path(member.name) + require(not path.is_absolute() and '..' not in path.parts and path.parts, 'Safe baseline path') + raw = stream.extractfile(member).read() + if member.name in rows: + row = rows[member.name] + require(len(raw) == row['size'] and sha256(raw).hexdigest() == row['sha256'], 'Exact baseline file bytes') + require(row['mode'] in (0o644, 0o755), 'Regular baseline file mode') + contents[member.name] = raw + return contents + + +@contextmanager +def baseline(): + contents = payload() + with tempfile.TemporaryDirectory(prefix='literal-setup-baseline-') as temporary: + root = Path(temporary) + try: + for name, raw in contents.items(): + path = root / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_bytes(raw) + path.chmod(0o444) + for path in root.rglob('*'): + if path.is_dir(): + path.chmod(0o555) + before = {str(p.relative_to(root)): [sha256(p.read_bytes()).hexdigest(), p.stat().st_mode & 0o777] + for p in root.rglob('*') if p.is_file()} + yield root / 'research/selected-single-pass-qualification' + after = {str(p.relative_to(root)): [sha256(p.read_bytes()).hexdigest(), p.stat().st_mode & 0o777] + for p in root.rglob('*') if p.is_file() and not p.is_symlink()} + require(after == before and not any(p.is_symlink() for p in root.rglob('*')), 'Baseline export unchanged') + finally: + for path in [root, *root.rglob('*')]: + if path.is_dir(): + path.chmod(0o755) diff --git a/research/literal-gate-setup-reuse/setup_cache.py b/research/literal-gate-setup-reuse/setup_cache.py new file mode 100644 index 0000000000..b14fddadc7 --- /dev/null +++ b/research/literal-gate-setup-reuse/setup_cache.py @@ -0,0 +1,96 @@ +"""Bounded immutable literal P/D setup, using that literal compiler alone.""" +import ast +from functools import lru_cache +from hashlib import sha256 +import inspect +import textwrap + +ORIGINAL_METHOD_SHA256 = 'ebb92d6870d73dc452faf6d8c3c62710539ffb9bae3a5588dc694fe2693c6509' + + +def require(ok, why): + if not ok: + raise ValueError(why) + + +def frozen(value): + if type(value) in (str, int): + return value + if type(value) in (tuple, list): + return tuple(frozen(item) for item in value) + raise ValueError('Exact setup key types') + + +class Setup: + def __init__(self, compiler, capacity=512): + require(type(capacity) is int and 1 <= capacity <= 512, 'Bounded setup capacity') + self.mv = compiler.mv + self.qvalue = compiler.qvalue + self.cached = lru_cache(maxsize=capacity)(self._table) + + def __call__(self, width, gate): + require(type(width) is int and 0 <= width <= 9, 'Exact bounded setup width') + gate = frozen(gate) + require(type(gate) is tuple and gate and gate[0] in ('P', 'D'), 'Literal setup gate') + require(len(gate) == (2 if gate[0] == 'P' else 3), 'Complete setup gate fields') + require(type(gate[1]) is tuple and len(gate[1]) == width and + all(type(x) is int for x in gate[1]), 'Complete setup matrix') + if gate[0] == 'D': + require(type(gate[2]) is tuple and len(gate[2]) == width and + all(type(x) is int for x in gate[2]), 'Complete setup phase data') + return self.cached(width, gate) + + def _table(self, width, gate): + if gate[0] == 'P': + return tuple(self.mv(gate[1], x) for x in range(1 << width)) + return tuple(self.qvalue(gate[1], gate[2], x, width) for x in range(1 << width)) + + +def dump(node): + return ast.dump(node, include_attributes=False) + + +def expression(text): + return ast.parse(text, mode='eval').body + + +class Preparation(ast.NodeTransformer): + def __init__(self): + self.counts = {'P': 0, 'D': 0, 'mv': 0, 'qvalue': 0} + + def visit_Call(self, node): + if dump(node) == dump(expression('mv(e[1], x)')): + self.counts['mv'] += 1 + return ast.copy_location(expression('_setup_images[x]'), node) + if dump(node) == dump(expression('qvalue(e[1], e[2], x, self.n)')): + self.counts['qvalue'] += 1 + return ast.copy_location(expression('_setup_phases[x]'), node) + return self.generic_visit(node) + + def visit_If(self, node): + node = self.generic_visit(node) + for tag, name in (('P', '_setup_images'), ('D', '_setup_phases')): + if dump(node.test) == dump(expression("e[0] == '" + tag + "'")): + self.counts[tag] += 1 + node.body.insert(0, ast.Assign([ast.Name(name, ast.Store())], + expression('_literal_setup(self.n, e)'))) + return node + + +def bind(compiler, capacity=512): + """Derive only two per-gate preparations and their two literal lookups.""" + original = compiler.Op.zero_state + text = textwrap.dedent(inspect.getsource(original)) + require(sha256(text.encode()).hexdigest() == ORIGINAL_METHOD_SHA256, 'Exact original literal method') + module = ast.parse(text) + require(len(module.body) == 1 and isinstance(module.body[0], ast.FunctionDef), 'One literal method') + transform = Preparation() + prepared = ast.fix_missing_locations(transform.visit(module)) + require(transform.counts == {'P': 1, 'D': 1, 'mv': 1, 'qvalue': 1}, 'Exact literal preparation sites') + setup = Setup(compiler, capacity) + namespace = dict(compiler.__dict__, _literal_setup=setup) + exec(compile(prepared, '', 'exec'), namespace) + compiler.Op.zero_state = namespace['zero_state'] + return setup, original, {'sites': transform.counts, + 'original_method_sha256': sha256(text.encode()).hexdigest(), + 'prepared_ast_sha256': sha256(dump(prepared).encode()).hexdigest()} diff --git a/research/literal-gate-setup-reuse/setup_checks.py b/research/literal-gate-setup-reuse/setup_checks.py new file mode 100644 index 0000000000..e55bea7302 --- /dev/null +++ b/research/literal-gate-setup-reuse/setup_checks.py @@ -0,0 +1,140 @@ +"""Finite conformance and cache-failure controls before a full candidate.""" +import json +from pathlib import Path +import sys +from types import SimpleNamespace +from unittest.mock import patch + +from setup_cache import Setup, bind, require + +from contextlib import contextmanager +from retained import baseline + + +@contextmanager +def prepared_source(): + with baseline() as base: + sys.path.insert(0, str(base)) + from source import prepared + with prepared() as root: + yield root + + +def reject(action, label, results): + try: + action() + except (ValueError, TypeError, RuntimeError, AttributeError) as error: + results[label] = type(error).__name__ + ': ' + str(error) + else: + raise ValueError('Invalid setup accepted: ' + label) + + +def main(): + with prepared_source() as root: + sys.path.insert(0, str(root / 'research/selected-quadratic-replay')) + import checks + C = checks.load('setup_feasibility_literal', 'research/p104-native-channel/vendor/clifford_exact.py') + setup, old, binding = bind(C) + cases = amplitudes = 0 + try: + for n in range(1, 5): + gates = [('phase', j) for j in range(4)] + gates += [('X', q) for q in range(1 << n)] + gates += [('C', q, s) for q in range(1, 1 << n) for s in (-1, 1)] + gates += [('P', tuple(1 << ((i + shift) % n) for i in range(n))) for shift in range(n)] + for mask in range(1 << n): + rows = tuple((1 << i) if mask >> i & 1 else 0 for i in range(n)) + gates.append(('D', rows, tuple((mask >> i) & 1 for i in range(n)))) + for j in range(len(gates)): + circuit = tuple(gates[k % len(gates)] for k in (j, 3*j+1, 7*j+2)) + operator = C.Op(n, (), list(circuit)) + for initial in range(1 << n): + expected = old(operator, initial) + require(operator.zero_state(initial) == expected, 'Every exact dense amplitude and denominator') + cases += 1 + amplitudes += 1 << n + n = 9 + permutation = tuple(1 << ((i + 3) % n) for i in range(n)) + quadratic = tuple((1 << i) | (1 << ((i+1) % n)) for i in range(n)) + linear = tuple(i % 4 for i in range(n)) + circuit = [('C', 511, 1), ('P', permutation), ('D', quadratic, linear), + ('phase', 3), ('C', 17, -1)] + operator = C.Op(n, (), circuit) + for initial in (0, 1, 17, 511): + require(operator.zero_state(initial) == old(operator, initial), 'Full-width literal conformance') + cases += 1 + amplitudes += 512 + controls = {} + p = ['P', [1, 2]] + value = setup(2, p) + setup(2, p) + before = setup.cached.cache_info() + require(before.hits > 0, 'Exact key reuse') + p[1][0] = 3 + require(setup(2, p) != value and value == (0, 1, 2, 3), 'Mutable input snapshot and invalidation') + controls['input_snapshot'] = 'PASS' + reject(lambda: value.__setitem__(0, 99), 'immutable_return', controls) + require(setup(2, ['D', [1, 2], [0, 0]]) != setup(2, ['D', [1, 2], [1, 0]]), 'Changed phase invalidates') + controls['changed_phase'] = 'PASS' + require(len(setup(3, ('P', (1, 2, 4)))) == 8, 'Changed width retains domain') + controls['changed_width'] = 'PASS' + for name, width, gate in [('bool_width', True, ('P', (1,))), + ('float_width', 1.0, ('P', (1,))), + ('bool_matrix', 2, ('P', (True, 2))), + ('float_matrix', 2, ('P', (1.0, 2))), + ('bool_phase', 2, ('D', (1, 2), (True, 0))), + ('bad_matrix_length', 3, ('P', (1, 2))), + ('bad_phase_length', 2, ('D', (1, 2), (0,))), + ('unknown_gate', 2, ('X', 1)), + ('unbounded_width', 10, ('P', tuple(1 << i for i in range(10))))]: + reject(lambda width=width, gate=gate: setup(width, gate), name, controls) + for capacity in (0, True, 513): + reject(lambda capacity=capacity: Setup(C, capacity), 'capacity_' + str(capacity), controls) + tiny = Setup(C, 3) + for phase in range(5): + tiny(1, ('D', (0,), (phase,))) + require(tiny.cached.cache_info().currsize == 3, 'Bounded cache residency') + misses = tiny.cached.cache_info().misses + tiny(1, ('D', (0,), (0,))) + require(tiny.cached.cache_info().misses == misses + 1, 'Eviction recomputes') + controls['bounded_eviction'] = 'PASS' + attempts = [] + def broken(rows, address): + attempts.append(address) + raise RuntimeError('setup sentinel') + failing = Setup(SimpleNamespace(mv=broken, qvalue=C.qvalue)) + for i in range(2): + reject(lambda: failing(1, ('P', (1,))), 'exception_' + str(i), controls) + require(attempts == [0, 0] and failing.cached.cache_info().currsize == 0, 'Exceptions never cached') + operator = C.Op(2, (), [('C', 1, 1), ('P', (1, 2)), ('D', (1, 2), (1, 0))]) + expected = old(operator, 0) + returned = operator.zero_state(0) + returned[0][0] = (99, 99) + require(operator.zero_state(0) == expected, 'Fresh dense output after mutation') + controls['fresh_dense_output'] = 'PASS' + saved_cache = setup.cached + for tag in ('P', 'D'): + def corrupted(width, gate, tag=tag): + values = saved_cache(width, gate) + if gate[0] == tag: + return tuple((x+1) % ((1 << width) if tag == 'P' else 4) for x in values) + return values + setup.cached = corrupted + fault = C.Op(2, (), [('P', (1, 2))] if tag == 'P' else [('D', (1, 2), (0, 0))]) + try: + require(fault.zero_state(0) != old(fault, 0), 'Wrong address or absolute phase detected') + controls['corrupt_' + tag + '_detected'] = 'PASS' + finally: + setup.cached = saved_cache + C.Op.zero_state = old + with patch('setup_cache.inspect.getsource', return_value='def zero_state(self):\n pass\n'): + reject(lambda: bind(C), 'changed_literal_method', controls) + finally: + C.Op.zero_state = old + result = {'cases': cases, 'amplitude_entries': amplitudes, 'controls': controls, + 'binding': binding, 'full_width_cases': 4, 'max_setup_capacity': 512} + print('PASS_LITERAL_SETUP_FEASIBILITY', json.dumps(result, sort_keys=True)) + + +if __name__ == '__main__': + main() diff --git a/research/literal-gate-setup-reuse/verify.py b/research/literal-gate-setup-reuse/verify.py new file mode 100644 index 0000000000..9d61078573 --- /dev/null +++ b/research/literal-gate-setup-reuse/verify.py @@ -0,0 +1,12 @@ +"""Fresh complete qualification; no saved acceptance receipt is reused.""" +import sys + +from candidate import run +from retained import baseline +from setup_cache import require + + +if __name__ == '__main__': + require(not sys.argv[1:], 'No verification arguments') + with baseline() as base: + run(base) diff --git a/tests/fixtures/README.md b/tests/fixtures/README.md new file mode 100644 index 0000000000..472a6a502f --- /dev/null +++ b/tests/fixtures/README.md @@ -0,0 +1,41 @@ +# Frozen research routing fixture + +`research-routing-v7.json` retains two exact task cards from priority revision 7: +`portable-replay` and `centre-path-sharing`. They exercise the generic-baseline +and historical-ceiling routes in `choose_current_research_task.py`. The fixture +records the source commit, path and SHA256. The card objects are unchanged. + +The source is commit `553d26d796fde9871ff2661a49ac7732e945410f`, file +`docs/research/agent-task-catalog.json`. The test places these cards in a small +catalogue with one track of weight 100. This carrier is test data, not a change +to research priorities. Current cards are checked separately from the live +catalogue. Every live card must preserve its other fields; each distinct direct +command also passes through both real CLIs. + +The CLI fixture copies the two real scripts. It creates inert reference files +for path validation and copies the current selected record for receipt fields. +It does not execute those references or verify a mathematical claim. Missing +references, sparse omissions, deleted files and staged replacements have separate +negative tests. No Git history, network request or change to the live catalogue +is needed to run the fixture. + +```sh +python3 -B -m unittest discover -s tests -p test_research_current_assignment.py -v +python3 -B -m unittest discover -s tests -p test_research_assignment.py -v +``` + +This fixture repairs the CI handoff in +[Discussion 5722](https://github.com/CrocSwap/integer-mult-bounds/discussions/5722). +The [investigation](https://github.com/CrocSwap/integer-mult-bounds/discussions/5758) +records the failure, checks and publication status. The original scripts, task +catalogue and selected frontier are unchanged. + +On base `de5ec2e7a6074068452f45b1a191b5c72832df4a`, the old suite has eight +failures and two errors. After the repair, all 12 current-assignment tests pass +under Python 3.14.7 and Python 3.12.14, including an isolated optimized run. +All 16 related assignment tests pass under Python 3.12.14. This is test coverage, +not a mathematical replay. See the investigation for hosted-plan status. + +Retain the original catalogue, routing and test authors, including Douglas +Colkitt, Ali Romman and Mihir Srivastava. New fixture and test repair: Ali Romman +with substantial OpenAI Codex assistance. No subagents. Apache-2.0. diff --git a/tests/fixtures/research-routing-v7.json b/tests/fixtures/research-routing-v7.json new file mode 100644 index 0000000000..f5d52ac21d --- /dev/null +++ b/tests/fixtures/research-routing-v7.json @@ -0,0 +1,87 @@ +{ + "source_commit": "553d26d796fde9871ff2661a49ac7732e945410f", + "source_path": "docs/research/agent-task-catalog.json", + "source_sha256": "f7a48bfa2659b88378282a8eee7d9fe52cdf505594124c4d1686b58510fffd72", + "scope": "Two exact revision-7 cards. The test carrier is not a research allocation.", + "cards": [ + { + "id": "centre-path-sharing", + "question": "Can the 64-per-call centre path (eight rank-8 COPY/ERASE totals through the private temporary) be shared across calls or shrunk?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/complex-local-word-ceiling/README.md", + "research/split-centres-global/proofs/PR386-BIT-GEOMETRY.txt", + "certificates/selected-result.json" + ], + "methods": [ + "Derive a fully charged favorable relaxation for sharing one centre path across k calls, including restoration, hosting and precision.", + "Prove a lower bound on copied information per call for the selected decoder contract." + ], + "acceptance_gate": "Show the changed centre charge and copy profile per call with every added restoration or hosting cost charged, and its ceiling via ceiling.ceiling(centre=...). A scoped local result may be retained without a complete supplier. Expanding it into further construction rounds requires the family-level budget and obligation gate in research-family-status.md; an optimistic passing relaxation alone is not acceptance.", + "first_step": { + "command": [ + "python3", + "-B", + "research/complex-local-word-ceiling/verify.py" + ], + "expected": "PASS_COMPLEX_LOCAL_WORD_CEILING", + "inspect": "Read the selected word's per-call local profile, its packing ceiling and the lever table; run levers.py for the ideal budget of the lever you target.", + "scope": "Positive control and planning budget only; this is not a new construction or full cold replay." + }, + "first_experiment": "Write the per-call centre charge and copy children for sharing across k = 2 calls, charge the sharing overhead, and screen it; stop this route if even the ideal sharing gains under 10%. Ideal budgets: free 2.80x, shared by two 1.90x (levers.py).", + "bottleneck_link": "The centre path consumes 64 of about 99.6 unpaid coordinates per call, i.e. about 64% of the raw deficit.", + "allowed_variations": [ + "One sharing pattern across a fixed number of calls.", + "One reduced copied-total contract for the existing decoder.", + "If the coverage law, template or guard changes, derive an applicable fully charged replacement bound instead of applying the incumbent ceiling outside its scope." + ], + "scope_change_triggers": [ + "Removing copies without a replacement contract for the decoder's copied totals.", + "Continuing a partial cost improvement while leaving the same unpriced consumer, restoration or central-readout obligation unresolved; refresh the family expansion decision first. Local product-retiming evidence has a narrow scope and is not a ban on changed graphs or contracts." + ], + "overlap_terms": [ + "centre path", + "copied totals", + "private temporary", + "shared centre", + "batching" + ] + }, + { + "id": "portable-replay", + "question": "Can one reproducible environment or artifact-comparison failure be repaired?", + "starting_points": [ + "research/gzip-container-reproducibility/README.md", + "docs/ci-verification.md" + ], + "methods": [ + "Reproduce one portability failure and add a minimal cross-environment fix.", + "Audit one canonical-payload comparison for omitted proof-relevant fields." + ], + "acceptance_gate": "Preserve immutable source hashes and proof-relevant content; a different compressed byte stream alone is not a mathematical mismatch.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the gzip-container reproducibility examples and distinguish frozen source bytes from regenerated payloads.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Reproduce one specific mismatch or audit one canonical comparison for omitted proof-relevant fields.", + "bottleneck_link": "Portable exact checks prevent environment failures from blocking valid contributions.", + "allowed_variations": [ + "One interpreter/version mismatch or one payload field comparison." + ], + "scope_change_triggers": [ + "Removing immutable-source pins because generated compressed bytes differ." + ], + "overlap_terms": [ + "gzip container", + "reproducibility", + "canonical payload" + ] + } + ] +} diff --git a/tests/test_research_current_assignment.py b/tests/test_research_current_assignment.py index 860f6b9b9e..c524c0037f 100644 --- a/tests/test_research_current_assignment.py +++ b/tests/test_research_current_assignment.py @@ -1,9 +1,15 @@ -"""Current orientation must preserve frozen task-selection evidence.""" +"""Current orientation must preserve frozen task-selection evidence. + +Frozen fixtures and live-catalog coverage: Ali Romman with OpenAI Codex +assistance. Retain the original routing and test authors. Apache-2.0. +""" import copy +from contextlib import contextmanager import importlib.util import json from pathlib import Path import subprocess +import shutil import sys import tempfile import unittest @@ -15,16 +21,49 @@ LEGACY = current.LEGACY legacy = current.runpy.run_path(str(LEGACY)) CATALOG = json.loads((ROOT / legacy["CATALOG"]).read_text(encoding="utf-8")) +FROZEN = json.loads((ROOT / "tests/fixtures/research-routing-v7.json").read_text()) +FROZEN_CATALOG = { + "schema_version": 1, "priority_revision": 7, + "priority_log": "docs/research/routing-fixture.md", + "tracks": [{"id": "routing-fixtures", "weight": 100, "tasks": FROZEN["cards"]}], +} + + +@contextmanager +def frozen_cli_tree(): + """Run the real scripts with exact old cards and inert reference files.""" + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + required = {FROZEN_CATALOG["priority_log"], + "scripts/research_selected_baseline.py", "scripts/research_package.py", + "research/historical-complex-ceiling-replay/VERIFY.json", + "research/historical-complex-ceiling-replay/verify.py"} + for card in FROZEN["cards"]: + required.update(card["starting_points"]) + required.add(card["first_step"]["command"][-1]) + for name in required: + path = root / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text("Inert reference for CLI validation only.\n") + for name in ("choose_research_task.py", "choose_current_research_task.py"): + shutil.copyfile(ROOT / "scripts" / name, root / "scripts" / name) + path = root / legacy["CATALOG"] + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(FROZEN_CATALOG)) + path = root / "certificates/selected-result.json" + path.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(ROOT / "certificates/selected-result.json", path) + yield root class CurrentResearchAssignmentTests(unittest.TestCase): - def test_every_frozen_card_and_other_fields_stay_exact(self): - before = copy.deepcopy(CATALOG) + def check_card_round_trips(self, catalog): + before = copy.deepcopy(catalog) resolved = 0 historical = 0 - for track in CATALOG["tracks"]: + for track in catalog["tracks"]: for task in track["tasks"]: - result = legacy["select"](CATALOG, "a1" * 16, task_id=task["id"]) + result = legacy["select"](catalog, "a1" * 16, task_id=task["id"]) original = copy.deepcopy(result) current.resolve_current_first_steps(result, ROOT) card = result["suggestions"][0] @@ -55,19 +94,25 @@ def test_every_frozen_card_and_other_fields_stay_exact(self): self.assertTrue(card.pop("first_step_resolution")) card["first_step"] = card.pop("catalog_first_step") self.assertEqual(result, original) - self.assertEqual(resolved, 16) - self.assertEqual(historical, 4) - self.assertEqual(CATALOG, before) + self.assertEqual(catalog, before) + return resolved, historical + + def test_frozen_routes_and_other_fields_stay_exact(self): + self.assertEqual(self.check_card_round_trips(FROZEN_CATALOG), (1, 1)) + + def test_every_live_card_and_other_fields_stay_exact(self): + self.assertTrue(CATALOG["tracks"]) + self.check_card_round_trips(CATALOG) def test_only_exact_generic_command_is_resolved(self): - result = copy.deepcopy(legacy["select"](CATALOG, "0" * 32, task_id="portable-replay")) + result = copy.deepcopy(legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay")) result["suggestions"][0]["first_step"]["command"].append("--historical-fixture") original = copy.deepcopy(result) self.assertEqual(current.resolve_current_first_steps(result, ROOT), []) self.assertEqual(result, original) def test_missing_current_helper_does_not_change_receipt(self): - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") original = copy.deepcopy(result) with tempfile.TemporaryDirectory() as directory: with self.assertRaisesRegex(ValueError, "missing current first-step script"): @@ -82,7 +127,7 @@ def test_nonexact_scientific_commands_are_not_reinterpreted(self): ): with self.subTest(command=command): result = copy.deepcopy(legacy["select"]( - CATALOG, "0" * 32, task_id="centre-path-sharing")) + FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing")) result["suggestions"][0]["first_step"]["command"] = command original = copy.deepcopy(result) self.assertEqual(current.resolve_current_first_steps(result, ROOT), []) @@ -102,34 +147,52 @@ def test_missing_historical_reference_leaves_all_cards_unchanged(self): path = root / name path.parent.mkdir(parents=True, exist_ok=True) path.write_text("fixture\n") - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") result["suggestions"] += legacy["select"]( - CATALOG, "0" * 32, task_id="centre-path-sharing")["suggestions"] + FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing")["suggestions"] original = copy.deepcopy(result) with self.assertRaises(ValueError) as raised: current.resolve_current_first_steps(result, root) self.assertIn(absent, str(raised.exception)) self.assertEqual(result, original) - def cli(self, script, args): - return subprocess.run([sys.executable, "-B", str(script), *args], cwd=ROOT, + def cli(self, script, args, root=ROOT): + return subprocess.run([sys.executable, "-B", str(root / "scripts" / Path(script).name), *args], cwd=root, capture_output=True, text=True, encoding="utf-8") def test_cli_preserves_legacy_output_and_emits_both_commands(self): - args = ["--seed", "0" * 32, "--task", "portable-replay"] - original = self.cli(LEGACY, args) - output = self.cli(ROOT / "scripts/choose_current_research_task.py", args) - self.assertEqual(original.returncode, 0) - self.assertEqual(output.returncode, 0) - old, new = json.loads(original.stdout), json.loads(output.stdout) - card = new["suggestions"][0] - self.assertEqual(card["first_step"]["command"], - ["python3", "-B", "scripts/research_selected_baseline.py"]) - self.assertEqual(card.pop("catalog_first_step"), old["suggestions"][0]["first_step"]) - self.assertTrue(card.pop("first_step_resolution")) - card["first_step"] = old["suggestions"][0]["first_step"] - self.assertEqual(new, old) - self.assertEqual(self.cli(LEGACY, args).stdout, original.stdout) + with frozen_cli_tree() as root: + args = ["--seed", "0" * 32, "--task", "portable-replay"] + original = self.cli(LEGACY, args, root) + output = self.cli(ROOT / "scripts/choose_current_research_task.py", args, root) + self.assertEqual(original.returncode, 0) + self.assertEqual(output.returncode, 0) + old, new = json.loads(original.stdout), json.loads(output.stdout) + card = new["suggestions"][0] + self.assertEqual(card["first_step"]["command"], + ["python3", "-B", "scripts/research_selected_baseline.py"]) + self.assertEqual(card.pop("catalog_first_step"), old["suggestions"][0]["first_step"]) + self.assertTrue(card.pop("first_step_resolution")) + card["first_step"] = old["suggestions"][0]["first_step"] + self.assertEqual(new, old) + self.assertEqual(self.cli(LEGACY, args, root).stdout, original.stdout) + + def test_live_cli_preserves_each_unmapped_command(self): + checked = {tuple(card["first_step"]["command"]) for card in FROZEN["cards"]} + for track in CATALOG["tracks"]: + for task in track["tasks"]: + command = tuple(task["first_step"]["command"]) + if command in checked: + continue + checked.add(command) + with self.subTest(task=task["id"]): + args = ["--seed", "0" * 32, "--task", task["id"]] + original = self.cli(LEGACY, args) + output = self.cli(ROOT / "scripts/choose_current_research_task.py", args) + self.assertEqual(original.returncode, 0, original.stderr) + self.assertEqual(output.returncode, 0, output.stderr) + self.assertEqual(json.loads(output.stdout), json.loads(original.stdout)) + self.assertEqual(self.cli(LEGACY, args).stdout, original.stdout) def test_help_and_error_preserve_child_status_and_output(self): for args, code in ((["--help"], 0), (["--unknown-option"], 2), (["--seed", "bad"], 2)): @@ -139,23 +202,24 @@ def test_help_and_error_preserve_child_status_and_output(self): self.assertEqual((output.stdout, output.stderr), (original.stdout, original.stderr)) def test_cli_distinguishes_current_orientation_from_historical_control(self): - args = ["--seed", "0" * 32, "--task", "complex-new-helper-inventory"] - original = self.cli(LEGACY, args) - output = self.cli(ROOT / "scripts/choose_current_research_task.py", args) - self.assertEqual(original.returncode, 0, original.stderr) - self.assertEqual(output.returncode, 0, output.stderr) - old, new = json.loads(original.stdout), json.loads(output.stdout) - card = new["suggestions"][0] - self.assertEqual(card["first_step"]["command"][2], "scripts/research_selected_baseline.py") - self.assertEqual(card["first_step"]["expected"], "PASS_RESEARCH_BASELINE_BINDINGS_ONLY") - follow_up, = card.pop("follow_up_steps") - self.assertEqual(follow_up["command"][-1], "research/historical-complex-ceiling-replay") - self.assertIn("historical", follow_up["scope"].lower()) - self.assertIn("cost law", follow_up["inspect"]) - self.assertTrue(card.pop("first_step_resolution")) - card["first_step"] = card.pop("catalog_first_step") - self.assertEqual(new, old) - self.assertEqual(self.cli(LEGACY, args).stdout, original.stdout) + with frozen_cli_tree() as root: + args = ["--seed", "0" * 32, "--task", "centre-path-sharing"] + original = self.cli(LEGACY, args, root) + output = self.cli(ROOT / "scripts/choose_current_research_task.py", args, root) + self.assertEqual(original.returncode, 0, original.stderr) + self.assertEqual(output.returncode, 0, output.stderr) + old, new = json.loads(original.stdout), json.loads(output.stdout) + card = new["suggestions"][0] + self.assertEqual(card["first_step"]["command"][2], "scripts/research_selected_baseline.py") + self.assertEqual(card["first_step"]["expected"], "PASS_RESEARCH_BASELINE_BINDINGS_ONLY") + follow_up, = card.pop("follow_up_steps") + self.assertEqual(follow_up["command"][-1], "research/historical-complex-ceiling-replay") + self.assertIn("historical", follow_up["scope"].lower()) + self.assertIn("cost law", follow_up["inspect"]) + self.assertTrue(card.pop("first_step_resolution")) + card["first_step"] = card.pop("catalog_first_step") + self.assertEqual(new, old) + self.assertEqual(self.cli(LEGACY, args, root).stdout, original.stdout) def test_sparse_historical_references_require_unchanged_head_entries(self): with tempfile.TemporaryDirectory() as directory: @@ -178,12 +242,12 @@ def git(*args): git("update-index", "--skip-worktree", *omitted) for name in omitted: (root / name).unlink() - result = legacy["select"](CATALOG, "0" * 32, task_id="coverage-law-change") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing") self.assertEqual(current.resolve_current_first_steps(result, root), sorted(omitted)) # Ordinary deletion must not acquire the deliberate-sparse exemption. changed = omitted[-1] git("update-index", "--no-skip-worktree", changed) - result = legacy["select"](CATALOG, "0" * 32, task_id="coverage-law-change") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing") original = copy.deepcopy(result) with self.assertRaises(ValueError): current.resolve_current_first_steps(result, root) @@ -208,9 +272,9 @@ def git(*args): git("-c", "user.name=Fixture", "-c", "user.email=fixture@example.invalid", "-c", "core.hooksPath=/dev/null", "commit", "-qm", "helper") git("update-index", "--skip-worktree", name); path.unlink() - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") self.assertEqual(current.resolve_current_first_steps(result, root), [name]) git("update-index", "--no-skip-worktree", name) - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") with self.assertRaisesRegex(ValueError, "missing current first-step script"): current.resolve_current_first_steps(result, root)