diff --git a/research/t74-native-fast/.gitattributes b/research/t74-native-fast/.gitattributes new file mode 100644 index 0000000000..e6d60b4a58 --- /dev/null +++ b/research/t74-native-fast/.gitattributes @@ -0,0 +1,3 @@ +# Source pins bind original bytes, including inherited CRLF line endings. +vendor/** -text -whitespace +fixtures/*.gz binary diff --git a/research/t74-native-fast/EXPECTED.json b/research/t74-native-fast/EXPECTED.json new file mode 100644 index 0000000000..24a65daada --- /dev/null +++ b/research/t74-native-fast/EXPECTED.json @@ -0,0 +1,84 @@ +{ + "base": { + "normalized_sha256": "72152474a7c1f65f8bddec3197a9661d035e2ef0edfd08751a19038c470f654f", + "recipe_bytes_sha256": "3fad1a9ae138ddb89442753cb2ef3c0666c58f40d5488d503fbf75f7f480d4d3", + "reference_files": { + "CANONICAL-WORD.json.gz": "dd1f277eafbde7fbc68c51fad396a64e8afe389a8529bbe61e187014a8a48215", + "CLIFFORD-RECIPES.json": "3fad1a9ae138ddb89442753cb2ef3c0666c58f40d5488d503fbf75f7f480d4d3", + "CLIFFORD-REVIEW.json": "255cf6f3d1105e9c60e2b589e3445a6b7e69af575abcfe4f6a0aba971fdb4195", + "FULL-WORD.json.gz": "ae8b6b4d62a9da29331062fae1bd68b0341edf83152f5a5ef50c5109ba578f9a", + "INDEPENDENT-LOCAL-REPLAY.json": "26adad9d1cd317e8e6c2f5db0f42e5f35ef4220e84280c80ac273aa2a329903a", + "LOCAL-CHECKS.json": "91d4117ece180666bcbda47204aad48c6b1d16f9d16bbc75f7b25493ae51674f", + "LOCAL-PROGRAMS.json.gz": "63e43ef535377b6e44cd264f126d8aded95441bd263e0d047eb168d6c46409bf", + "RESIDUAL-ADAPTERS.json": "6a807c59d857faed1140f9d7dd4dee863553f7a00a95ddd4601ef4dc8ea93b12", + "SCALAR-FRAME-AUDIT.json": "10347acf893d70592ca4af8ee1cdf58a06510a444992feffcddf5c03bdf63e42", + "WARP-RECIPE-CHECKS.json": "95bc1e29bae8210542423d7b0d6b4c07b29d3948a2c987507a97cf085f963252", + "WRAPPER-CHECKS.json": "508fe304ad6bd06c2c80b93b724cbd94368330f1f06f597f20fbcf2db9b4d771" + }, + "coverage": { + "status": "PASS_WARP_RECIPES_EXACT_ON_ALL_512_COLUMNS", + "canonical_word_sha256": "db6955899dffd8bab29e566e4cecc5a2ef51dba21aa64db1a9076a96fbed69f6", + "recipe_sha256": "3fad1a9ae138ddb89442753cb2ef3c0666c58f40d5488d503fbf75f7f480d4d3", + "warp_classes": 166, + "operators": 65, + "columns_each": 512, + "controls_rejected": [ + "recipe: wrong global phase", + "recipe: wrong translation", + "recipe: wrong linear phase", + "recipe: wrong quadratic form", + "recipe: wrong matrix", + "recipe: wrong G (still invertible)", + "recipe: non-invertible G", + "recipe: inverse warp recipe used for the forward warp", + "recipe: recipe of another warp class", + "recipe: swapped from/to frames", + "recipe: missing warp class", + "logical: wrong G", + "logical: wrong phase" + ] + }, + "reference": "Fresh PR2751 native run; receipts and file hashes bound by PR2751 REUSE-PINS.json." + }, + "extra": { + "normalized_sha256": "ae9e09a9a806c75f1ff444470e44e6543807e673c0292b6772a8b5dcdf5a4072", + "recipe_bytes_sha256": "a9641c6cbc4e05677e7559bf1764468f3dbcd9efe0ae710205590c381f6b5f08", + "reference_files": { + "CANONICAL-WORD.json.gz": "dacaaa72961e8bcfefa5f5125aa79b2bae33d4faead01a651bd44a8ea5ab2412", + "CLIFFORD-RECIPES.json": "a9641c6cbc4e05677e7559bf1764468f3dbcd9efe0ae710205590c381f6b5f08", + "CLIFFORD-REVIEW.json": "9622789fd43d2c3e14d98ae3df48765d1faeb8f5664136f48384dcd603e215fe", + "FULL-WORD.json.gz": "1bb44a73d5841afb954b49ae94dba2e0c536b1eea9436ae5d89de87d8a04e127", + "INDEPENDENT-LOCAL-REPLAY.json": "1ca177b1b78a0faaaaeeb05d44ccef50810d20d9f5607b3fa7dd493067f69ef1", + "LOCAL-CHECKS.json": "91d4117ece180666bcbda47204aad48c6b1d16f9d16bbc75f7b25493ae51674f", + "LOCAL-PROGRAMS.json.gz": "63e43ef535377b6e44cd264f126d8aded95441bd263e0d047eb168d6c46409bf", + "RESIDUAL-ADAPTERS.json": "c4dd3cf0ce67c9ef6ab86b051026c0d884c3548dfc6118f047d6f56bb7331352", + "SCALAR-FRAME-AUDIT.json": "abbfa5baf5228072679d6ac08b873115ef3a00c39e6632e110d1f94a5f7657da", + "WARP-RECIPE-CHECKS.json": "32c3480dd0f953237f567a5e1c66eb15de9cee5b57c219b571bcc9cb993042dd", + "WRAPPER-CHECKS.json": "508fe304ad6bd06c2c80b93b724cbd94368330f1f06f597f20fbcf2db9b4d771" + }, + "coverage": { + "status": "PASS_WARP_RECIPES_EXACT_ON_ALL_512_COLUMNS", + "canonical_word_sha256": "e20375d1bb82dc7fad688357e81e135c7386b2f46d85c7a2c393d30b72ea44df", + "recipe_sha256": "a9641c6cbc4e05677e7559bf1764468f3dbcd9efe0ae710205590c381f6b5f08", + "warp_classes": 166, + "operators": 65, + "columns_each": 512, + "controls_rejected": [ + "recipe: wrong global phase", + "recipe: wrong translation", + "recipe: wrong linear phase", + "recipe: wrong quadratic form", + "recipe: wrong matrix", + "recipe: wrong G (still invertible)", + "recipe: non-invertible G", + "recipe: inverse warp recipe used for the forward warp", + "recipe: recipe of another warp class", + "recipe: swapped from/to frames", + "recipe: missing warp class", + "logical: wrong G", + "logical: wrong phase" + ] + }, + "reference": "Fresh PR2751 native run; receipts and file hashes bound by PR2751 REUSE-PINS.json." + } +} diff --git a/research/t74-native-fast/FRESHNESS.json b/research/t74-native-fast/FRESHNESS.json new file mode 100644 index 0000000000..81a3a1dff3 --- /dev/null +++ b/research/t74-native-fast/FRESHNESS.json @@ -0,0 +1,124 @@ +{ + "checked_at": "2026-10-15T20:49:44.952707+00:00", + "scientific_base_commit": "2d3af1ba7e28b74248b47381768e5b116078ba1c", + "fetched_canonical_main": "936fac15b1b1b59dc5285c713a77f9f3c07b2906", + "priority_revision": 5, + "unchanged_since_base": [ + "AGENTS.md", + "CONTRIBUTING.md", + "autoresearch.md", + "docs/research/agent-task-catalog.json", + "certificates/selected-result.json", + "scripts/research_package.py", + "docs/research/research-family-status.md", + "all executed native and accelerator dependency sources" + ], + "reviewed_updates": "Ledger dispositions, P104/P112 mechanisms, generic recursive packets, exact Gaussian recovery and QQ16 contract navigation; no changed native/accelerator dependency or applicable scope restriction. Keep scientific pins unchanged.", + "overlap": { + "status": "POSSIBLE_OVERLAP_NOT_A_NOVELTY_CERTIFICATE", + "searched_at": "2026-10-15T20:47:33.782571+00:00", + "terms": [ + "bw_phases", + "zero_state", + "T74 native", + "sparse native" + ], + "coverage": { + "open_prs": { + "fetched_at": "2026-10-15T20:46:20.897437+00:00", + "complete_pagination": true, + "records": 710 + }, + "discussions": { + "fetched_at": "2026-10-15T20:28:04.284423+00:00", + "complete_pagination": true, + "records": 1389 + } + }, + "local_records": 38, + "warnings": [ + "discussions: refresh failed; using old data if available: Post \"https://api.github.com/graphql\": dial tcp 140.82.121.5:443: i/o timeout\n" + ], + "limits": "Remote PR scope is open PRs including drafts. Closed work is searched through local READMEs, TASK metadata and ledger only. No code diffs or arbitrary package files are searched. Recheck relevant heads before submission.", + "matches_total": 5, + "matches": [ + { + "kind": "pr", + "number": 2329, + "title": "Tooling: 3.15\u00d7 faster production Clifford zero_state via gate tables with identical receipts", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/2329", + "head": "68a7161a610f175dc8e7b22f95acd033191450d9", + "updated_at": "2026-10-15T20:35:01Z", + "draft": false, + "state": "open", + "matched_terms": [ + "zero_state" + ], + "score": 3, + "excerpt": "n/phase evaluation with identical cold617 helper-interface receipts. This PR wires that equivalent `zero_state` into the **production** multicold evaluator used by `scripts/verify_cold617_interface.py`.\n\nPath: `research/complex-multicold/vendor/pr558/vendor/pr552/complex-global/vendor531/vendor/clifford/clifford_exact.py`.\n\nNo certificate \u03ba pins change. Same-tip provenance hygiene:\n- `research/clifford-state-performance/` vendors pairwise-era bytes as `baseline.py` and demotes the live pairwise " + }, + { + "kind": "local-readme", + "title": "research/t74-native-fast/README.md", + "path": "research/t74-native-fast/README.md", + "sha256": "9dec97c3e9b79beeeb986e5bbbecb71fe29b4de4e0990eef9cee4d7563b8b5eb", + "matched_terms": [ + "zero_state", + "t74 native" + ], + "score": 2, + "excerpt": "# Complete T74 native replay with exact sparse state evaluation\n\n**Tooling improvement; no new \u03ba.** This opt-in runner applies the existing\nPR1029 sparse evaluator and PR662 exact gate tables to the current T74\nClifford wrappers and phase lowering. It runs the complete five-stage native\npipeline, including the unchanged independent warp-recipe checker. No previous\nnative result is reused. The benchmark compares the original and accelerated\nrunners on the same PR2751 base word; both provider word" + }, + { + "kind": "local-task", + "title": "research/t74-native-fast/TASK.json", + "path": "research/t74-native-fast/TASK.json", + "sha256": "12d011122b6f47589ee41101b6d73bcd50fdbebd2c837ac3c3509fb857c5d442", + "matched_terms": [ + "t74 native", + "sparse native" + ], + "score": 2, + "excerpt": "evaluation with PR662 gate tables into both Clifford-using stages of the complete warp-aware PR2751 T74 native replay. Benchmark complete five-stage runs against the unchanged driver.\",\n \"scope_change_reason\": \"The earlier U8 fast runners omit the present T74 independent warp-recipe stage. This scope keeps that stage and all other native controls.\",\n \"task_classification\": \"Explicit engineering override after comparing three narrow candidates; retained assignment seed2, no new random novelty c" + }, + { + "kind": "local-readme", + "title": "research/phase-recipes-parallel/README.md", + "path": "research/phase-recipes-parallel/README.md", + "sha256": "d74022ec200b13e600bbd4a60472d749efd712026f68d471905985275c34b6f4", + "matched_terms": [ + "zero_state" + ], + "score": 1, + "excerpt": "xact state evaluator\n(`research/clifford-state-performance/fast_state.py`, pinned by digest) as `Op.zero_state` in every\nprocess, the same substitution PR662's own `run.py` makes. The parallel layer composes with any\nper-edge evaluator.\n\n## Benchmark (same input, same machine)\n\n| Runner | Wall time | Speedup |\n|---|---:|---:|\n| pinned serial `phases_full.py` via `run_portable.py` | 92.2 s | 1\u00d7 |\n| `phases_parallel.py --jobs 4`, reference engine | 33.0 s (separate run) | 2.8\u00d7 |\n| `phases_parallel" + }, + { + "kind": "pr", + "number": 2398, + "title": "Research: extra factors do not lower the fixed P112 COPY-power optimum", + "url": "https://github.com/CrocSwap/integer-mult-bounds/pull/2398", + "head": "8051d99dfd91a788d25bfc92c3863a33c658a5a9", + "updated_at": "2026-10-15T13:21:06Z", + "draft": false, + "state": "open", + "matched_terms": [ + "t74 native" + ], + "score": 1, + "excerpt": "blem are different matrices/interfaces. The other active helper-inventory scope concerns PR #2339's T74 native compensation.\n- **Coordination:** [canonical claim in discussion #2006](https://github.com/CrocSwap/integer-mult-bounds/discussions/2006#discussioncomment-18942846). Final offline overlap queries used all terms `2321` + `terms`, and path `research/p112-overcomplete-factor-spaces/*`. Snapshot coverage: 587 open PRs including drafts at `2026-10-15T07:07:38.026722Z`, 1,116 Discussion recor" + } + ] + }, + "recent_discussion_fallback": { + "count": 40, + "full_pagination": false, + "updated_descending": true, + "comments_per_discussion": 5, + "snapshot_sha256": "8f77f8a598759e291ed37aae3412fff725dfd86c0919c99e55a40655f4354dd3", + "scope": "40 most recently updated discussions and last5 comments each. No new duplicate scope found; not all historical comments.", + "own_claim": 2755 + }, + "decision": "Continue the bounded integration; credit PR662/1029 and related PR1041/2329. Do not claim a novel evaluator, new kappa or changed selected frontier.", + "submission_parent_commit": "936fac15b1b1b59dc5285c713a77f9f3c07b2906", + "local_sync": "Isolated branch fast-forwarded to fetched canonical main. Package restored through sparse-checkout add; all source pins rechecked. Scientific provenance base remains2d3af1b." +} diff --git a/research/t74-native-fast/LICENSE b/research/t74-native-fast/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/research/t74-native-fast/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/research/t74-native-fast/NATIVE-LINEAGE-NOTICE b/research/t74-native-fast/NATIVE-LINEAGE-NOTICE new file mode 100644 index 0000000000..380e979f0e --- /dev/null +++ b/research/t74-native-fast/NATIVE-LINEAGE-NOTICE @@ -0,0 +1,14 @@ +Anticipatory dirty borrowing: PR2226 (Cinna Davis / 1337isnot1337, with substantial OpenAI Codex assistance) is credited first. Its alias rule, changed-reference K_G handoffs, initial compensation and exact free-operator replay (vendored under new/code/borrow/vendor, see new/code/borrow/NOTICE-PR2226.md) are applied here to the T74 pivot-566+554 words; the native lowering, window-exact owner fill and independent audit of the borrow words are new in this package. Bootstrap carried-cutoff repair: PR1956 (Josie Elliston); Lemma G label/adapter checks and X/Y/Z mutants: PR1964 (thakrarsagar), extended here with borrow warp/zero-buffer controls. + +New research prepared by Rohan Arun with substantial OpenAI Codex assistance. Apache-2.0. Parent words and build recipe method derive from Jeremy Kothe PR1274 and Rohan Arun PR1218, with lineage credited in README.md. All inherited mathematical qualifications are retained. +Additional pivot555 and567 composition by Rohan Arun with substantial OpenAI Codex assistance. + +T74 exact-fill owner construction by Rohan Arun with substantial OpenAI Codex assistance. + +PR1377 grid refinement credited to Jeremy Kothe. Outer witness refinement by Rohan Arun with OpenAI Codex assistance; construction unchanged. + +Pivot-566 kernel, words, edits, rebuild.py and rebind.py: PR1625 (mdumitrean). Endpoint/outer-witness stacking, fine_cache.py and oracle stage by jeremykothe2 with oh-my-pi assistance. + +The preceding paragraphs are inherited source notices, not attribution of this derivative. +This joint twelve-source construction, generator, independent replay, hosting composition and package: Tekalign (@tekuuu), with substantial OpenAI Codex assistance. No independent human review claimed. +Credits: Cinna Davis/PR2226 anticipatory dirty borrowing; Tekalign/PR2436 four lifted targets; Jeremy Kothe/PR2462,2588,2673 source pipeline, source-label swap and order/fill; zxv/PR2530 eight aliases; Mason Hale/PR2696 concentrated source-partner assignment and independent local interpreter; Philippe Van Velzen/PR2559,2679 evacuation, six pre-life hosts and refit/alias; themilkman216/PR2621 priority order; Marius-Paul Dumitrean/PR2733 independent concentrated/pre-life composition; Vlado Vojdanovski/PR2322 generator utilities. PR2720's fixed-old-path cut obstruction motivates the changed premise. The retained owner/native/bit/modern outer lineage and their notices remain in the pinned source. New work Apache-2.0. diff --git a/research/t74-native-fast/PINS.json b/research/t74-native-fast/PINS.json new file mode 100644 index 0000000000..7c83dc5432 --- /dev/null +++ b/research/t74-native-fast/PINS.json @@ -0,0 +1,22 @@ +{ + "vendor/accelerators/SPARSE-NOTICE.md": "3da80a5155c625bff907a42a82c65bfcf92854d2c960bcea4537c19c99efd4f2", + "vendor/accelerators/SPARSE-PROOF.md": "d73e4522602404caba8e7f247005a45c8a8cd26ffd2a70d65f4f9556a391d053", + "vendor/accelerators/sparse_state.py": "e91210ecd5085cf9add872f40bb434806838da488e12152c63c86e51fb5a7a37", + "vendor/accelerators/tables.py": "2fe087ba4558bd21ca49945dbedaa4047e4170e8fd4e2280701bb2f0481811b5", + "vendor/native/new/code/borrow/NOTICE-PR2226.md": "6b6730303818f6edc2a253eb4d05471eee58f28b5815fb250c32ae376f774c8a", + "vendor/native/new/code/borrow/bw_adapters.py": "c5907050a9a7fa36d4fcba3ad4fe440d1bec2063360c095013891785ba65c3ce", + "vendor/native/new/code/borrow/bw_audit_local.py": "08d5864d9b77902fc5ab5a062a8ea843fe1e572243b8c580abb0a421b2e46d07", + "vendor/native/new/code/borrow/bw_check_recipes.py": "d600b959a0ac462dc28deb8c0d5d8f9e0c76d7f7d7b6f92a296c5ef9e0a1de19", + "vendor/native/new/code/borrow/bw_emit.py": "99b59a6fa3feda86785e4225157dcb1a6169d256cec4f5e0acc9cea7a701df76", + "vendor/native/new/code/borrow/bw_gauss.py": "0884b14d6d77cde419a3c773ad9b21d0d18de1e6e20e6b6d5add458ed32ba4cb", + "vendor/native/new/code/borrow/bw_phases.py": "9d1a620e26715f4c42fd0347ecc14ef5a4a9031867869b64e8bae4d8526a821e", + "vendor/native/new/code/borrow/bw_tamper.py": "eab4b026965b9796eee92239660e1fb1fa629f6d9db44bc27b13911a018a6ee9", + "vendor/native/new/code/borrow/bw_transport.py": "9818e08b819310b40f1441b89be8c4369584a5b3fa5dfe9b86b1df9a7f5d6a76", + "vendor/native/new/code/borrow/vendor/PR2226-NOTICE.md": "f1d45d886926915531e3a59968abf0a4c974d7038f869848e71bd3a21b834422", + "vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py": "2982ead07721e83358dc67c6f49c2b4c16a236a6bebdfd72f58221be1f5d0962", + "vendor/native/new/code/borrow/vendor/pr2226_operators.py": "b37b67a04681c776dafcdc6c9af0e8a2dbfa9893b02e0fa2d77ccc9182a87988", + "vendor/native/new/code/borrow/vendor/pr2226_replay.py": "0f9a47cdaeed0e22938c63251c232d6f23aeee2b62b0b1223cd4473c5428bcf7", + "vendor/native/new/run_native_borrow.py": "8ec7db430f4f4771c06bdcfc31736193614f6ec209d57b63d4e2b75f17fb3ac8", + "fixtures/WORD-base.json.gz": "ae8b6b4d62a9da29331062fae1bd68b0341edf83152f5a5ef50c5109ba578f9a", + "fixtures/WORD-extra.json.gz": "1bb44a73d5841afb954b49ae94dba2e0c536b1eea9436ae5d89de87d8a04e127" +} diff --git a/research/t74-native-fast/README.md b/research/t74-native-fast/README.md new file mode 100644 index 0000000000..1ca40309bd --- /dev/null +++ b/research/t74-native-fast/README.md @@ -0,0 +1,161 @@ +# Complete T74 native replay with exact sparse state evaluation + +**Tooling improvement; no new κ.** This opt-in runner applies the existing +PR1029 sparse evaluator and PR662 exact gate tables to the current T74 +Clifford wrappers and phase lowering. It runs the complete five-stage native +pipeline, including the unchanged independent warp-recipe checker. No previous +native result is reused. The benchmark compares the original and accelerated +runners on the same PR2751 base word; both provider words are replayed in CI. + +The contribution is integration, coverage-preserving comparison and reproducible +complete-native benchmarking. The sparse evaluator and gate tables are copied +unchanged from their credited predecessors. Older U8 fast runners do not include +this T74 warp-aware pipeline. PR2329 concerns a different multicold production +checker; it is not a dependency of this package. + +## Result and scope + +Three alternating pairs measured **3.57× faster complete native replay**, +with median **306.7s → 85.9s** (72.0% less wall time). These are Python 3.12.14 / +numpy 2.2.6 measurements on this shared Linux host, specific to this fixture. + +| Stage | Original median (s) | Sparse median (s) | +|---|---:|---:| +| native | 1.20 | 1.19 | +| ledgers | 1.44 | 1.41 | +| local-replay | 38.21 | 37.70 | +| wrappers | 5.76 | 2.15 | +| phases | 259.39 | 43.40 | + +`phases` includes unchanged independent warp-recipe verification. Stage medians +do not necessarily sum to the median total. Every sample and stage is retained +in `evidence/BENCHMARK.json`. Every sample uses a fresh subprocess and +fresh output directory. There is no saved-result cache. In-process caches hold +only exact, immutable gate tables, with the predecessor's bounded cache sizes. + +The five stages are transport, ledgers, independent local replay, wrappers, and +phase lowering followed by independent warp-recipe verification. The last audit +checks 166 warp classes on all 512 columns, including global phase, and retains +all thirteen recipe mutations. All other original native checks remain enabled. +The full paid supplier, physical hosting and outer inequalities are **outside +this benchmark**. This is neither a whole-project speedup nor a faster integer +multiplication algorithm. The selected certificate remains unchanged. + +`compare.py` reads every field in all eleven native artifacts. It removes only +the two documented top-level elapsed-time fields. Before normalizing compressed +container hashes to decompressed hashes, it verifies the actual container +bindings. Recipe hashes remain hashes of the original serialized bytes. A changed +control list, a missing file, an invalid binding or a different recipe fails. +`EXPECTED.json` records the complete normalized reference digest and exact recipe +hash for each provider; original receipt hashes trace to PR2751's `REUSE-PINS.json`. + +`stage.py` substitutes only `Op.zero_state` inside a fresh process, then executes +the pinned wrappers or phase script unchanged. Tableaux, lowering, rank checks, +off-support checks, denominators and global-phase comparisons remain. The +independent numpy warp checker is a separate unchanged process. The retained +`SPARSE-PROOF.md` proves the predecessor's evaluator equivalence; its compiler +integration section describes PR1029, whereas this package uses the explicit +process-local substitution above. + +The current exact algebra's original dense evaluator is also compared with the +sparse evaluator for dimensions 1–5, twelve length-20 circuits per dimension, both +adjoints, and every input basis column (1,488 comparisons, deterministic seed 2). +This finite check supplements the predecessor's proof; it is not a formal proof +of the complete multiplication theorem. + +## Reproduce + +From repository root, in a Python 3.12 environment with `numpy==2.2.6`: + +```sh +python3.12 scripts/research_package.py --package research/t74-native-fast +``` + +Expected: `PASS_T74_NATIVE_FAST_REFERENCE_AND_CONTROLS base` and `extra`, then +`PASS_REGISTERED_RESEARCH_PACKAGE`. Each provider starts a fresh complete native +replay; the extra run uses a Git-free package copy in a path with spaces. +The base run also exercises 18 boundary controls: source digest/inventory/ +symlink changes, altered benchmark fixture, optimized Python, output reuse, singular warp and incorrect +paid profile in both engines, actual emitted recipe mutations, and changed +receipt coverage/bindings. Source drift is rejected before any vendored import. +A failed stage cannot produce the runner's success receipt. + +To use the runner on another word under the **same pinned native source version**: + +```sh +python3.12 -I -B research/t74-native-fast/run_native.py WORD.json.gz /tmp/t74-fresh +``` + +The output directory must not exist. Add `--engine reference` to invoke the +unchanged original driver. This standalone command needs no Git or network; +its sources are authenticated and copied into the output directory before use. +Logs, `COMMANDS.json`, the original native artifacts, and `RESULT.json` are kept. +It does not authenticate an arbitrary input as a known construction; it checks +that input through the native pipeline. The fixture verifier above additionally +requires exact fixture and reference-output pins. + +To repeat the controlled benchmark (several minutes per reference run): + +```sh +python3.12 -I -B research/t74-native-fast/benchmark.py --pairs 3 --provider base --work /tmp/t74-benchmark-fresh +``` + +Expected: `PASS_COMPLETE_T74_NATIVE_BENCHMARK` and three +`PASS_ALL_NATIVE_OUTPUTS_IDENTICAL` comparisons. Order alternates +reference/sparse, sparse/reference, reference/sparse. OS caches are not flushed; +this shared-host timing is descriptive, with no timing threshold in CI. + +## Sources and coverage boundary + +Scientific base: `2d3af1ba7e28b74248b47381768e5b116078ba1c`, priority revision 5. +Submission parent after canonical sync: `936fac15b1b1b59dc5285c713a77f9f3c07b2906`. +The relevant dependencies and selected record are unchanged; see `FRESHNESS.json`. +The exact source closure and fixture hashes are in `PINS.json`. File-by-file +origins, dependency heads and transformations are in `SOURCE-PROVENANCE.json`. +The native closure is PR2679 at `2e2cf56521df8a2b816b2689144765ee00b69a24` +with PR2751's published native-audit overlay at +`4cfbb0cc8314d7fb4e8e754545a49a42eb590a69`. Its bytes are unchanged here, +including the repaired incomplete-centre negative control. Existing frozen +packages and `upstream/` are untouched. + +The runner supports this specific closure, not arbitrary future native versions. +There is no result-cache invalidation problem: every invocation recomputes the +native evidence. Changing a vendored dependency requires an explicit source pin +update, new before/after comparison and review. Generic package CI reruns both +providers whenever this package changes. Main-line documentation pins are +historical provenance, not admission of pending PR2751. + +Inherited all-size/compiler, source-access, hosting, precision/tape, recovery and +analytic obligations remain with the original construction. Exact finite replay +does not discharge them. Source hashes protect against accidental drift; they +are not a security boundary against someone editing both code and its pins. + +## Open next questions + +The next measured bottlenecks are the independent local replay and all-column +warp matrices. Profile them before choosing an exact representation change; +preserve arbitrary-input, both-orientation and phase-sensitive coverage. +A separate maintainer decision could adopt this entry point for future T74 +construction work after independent replay and source-inventory review. This +package makes no automatic migration. Structured first steps and blockers are +in `TASK.json`. + +## Credit + +Prepared by Tekalign (@tekuuu), with substantial OpenAI Codex assistance in +profiling, integration, verification, review and documentation. No independent +human review is claimed. Apache-2.0; see `LICENSE` and retained notices. + +- Charles Bethin (@cbethin), PR662: exact bounded gate tables. +- Ali Romman (@aliromman), PR1029: exact sparse state propagation and its proof. +- Sagar Thakrar (@thakrarsagar), PR1041: prior complete U8 phase benchmarking + and parallel runner; the present runner does not use its parallelization. +- Victor Li (@VictorLiwentao), PR2329: related pending production integration + for the multicold helper checker, independently useful overlap. +- Cinna Davis (@1337isnot1337), PR2226: anticipatory dirty borrowing and exact + warp operators; Rohan Arun and the native lineage: T74 native realization. +- Philippe Van Velzen, PR2679: pre-life hosts, refit/alias and source snapshot; + PR2751 by Tekalign supplies the current two provider words and audit overlay. + Jeremy Kothe, zxv, Mason Hale, Marius-Paul Dumitrean, icekylinx, + DreamingOfClouds and the remaining predecessor contributions are retained in + `NATIVE-LINEAGE-NOTICE` and the native source notices. diff --git a/research/t74-native-fast/SOURCE-PROVENANCE.json b/research/t74-native-fast/SOURCE-PROVENANCE.json new file mode 100644 index 0000000000..07cd8a7880 --- /dev/null +++ b/research/t74-native-fast/SOURCE-PROVENANCE.json @@ -0,0 +1,214 @@ +{ + "schema_version": 1, + "base_commit": "2d3af1ba7e28b74248b47381768e5b116078ba1c", + "files": [ + { + "local": "vendor/accelerators/SPARSE-NOTICE.md", + "sha256": "3da80a5155c625bff907a42a82c65bfcf92854d2c960bcea4537c19c99efd4f2", + "origin": { + "commit": "2d3af1ba7e28b74248b47381768e5b116078ba1c", + "path": "research/selected-replay-fastpath/NOTICE.md" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/accelerators/SPARSE-PROOF.md", + "sha256": "d73e4522602404caba8e7f247005a45c8a8cd26ffd2a70d65f4f9556a391d053", + "origin": { + "commit": "2d3af1ba7e28b74248b47381768e5b116078ba1c", + "path": "research/selected-replay-fastpath/PROOF.md" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/accelerators/sparse_state.py", + "sha256": "e91210ecd5085cf9add872f40bb434806838da488e12152c63c86e51fb5a7a37", + "origin": { + "commit": "2d3af1ba7e28b74248b47381768e5b116078ba1c", + "path": "research/selected-replay-fastpath/sparse_state.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/accelerators/tables.py", + "sha256": "2fe087ba4558bd21ca49945dbedaa4047e4170e8fd4e2280701bb2f0481811b5", + "origin": { + "commit": "2d3af1ba7e28b74248b47381768e5b116078ba1c", + "path": "research/clifford-state-performance/fast_state.py" + }, + "transformation": "byte copy; tables.py filename only renamed" + }, + { + "local": "vendor/native/new/code/borrow/NOTICE-PR2226.md", + "sha256": "6b6730303818f6edc2a253eb4d05471eee58f28b5815fb250c32ae376f774c8a", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/NOTICE-PR2226.md" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/bw_adapters.py", + "sha256": "c5907050a9a7fa36d4fcba3ad4fe440d1bec2063360c095013891785ba65c3ce", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/bw_adapters.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/bw_audit_local.py", + "sha256": "08d5864d9b77902fc5ab5a062a8ea843fe1e572243b8c580abb0a421b2e46d07", + "origin": { + "commit": "4cfbb0cc8314d7fb4e8e754545a49a42eb590a69", + "path": "research/t74-joint-twelve/DERIVATIVE-OVERLAY.tar.gz", + "member": "new/code/borrow/bw_audit_local.py", + "archive_sha256": "16468f7428c6e01522fcb15a8e3040d13de6cb8856428e32dcfbce8dbe46b8ec" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/bw_check_recipes.py", + "sha256": "d600b959a0ac462dc28deb8c0d5d8f9e0c76d7f7d7b6f92a296c5ef9e0a1de19", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/bw_check_recipes.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/bw_emit.py", + "sha256": "99b59a6fa3feda86785e4225157dcb1a6169d256cec4f5e0acc9cea7a701df76", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/bw_emit.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/bw_gauss.py", + "sha256": "0884b14d6d77cde419a3c773ad9b21d0d18de1e6e20e6b6d5add458ed32ba4cb", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/bw_gauss.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/bw_phases.py", + "sha256": "9d1a620e26715f4c42fd0347ecc14ef5a4a9031867869b64e8bae4d8526a821e", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/bw_phases.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/bw_tamper.py", + "sha256": "eab4b026965b9796eee92239660e1fb1fa629f6d9db44bc27b13911a018a6ee9", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/bw_tamper.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/bw_transport.py", + "sha256": "9818e08b819310b40f1441b89be8c4369584a5b3fa5dfe9b86b1df9a7f5d6a76", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/bw_transport.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/vendor/PR2226-NOTICE.md", + "sha256": "f1d45d886926915531e3a59968abf0a4c974d7038f869848e71bd3a21b834422", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/vendor/PR2226-NOTICE.md" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py", + "sha256": "2982ead07721e83358dc67c6f49c2b4c16a236a6bebdfd72f58221be1f5d0962", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/vendor/clifford/clifford_exact.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/vendor/pr2226_operators.py", + "sha256": "b37b67a04681c776dafcdc6c9af0e8a2dbfa9893b02e0fa2d77ccc9182a87988", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/vendor/pr2226_operators.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/code/borrow/vendor/pr2226_replay.py", + "sha256": "0f9a47cdaeed0e22938c63251c232d6f23aeee2b62b0b1223cd4473c5428bcf7", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/code/borrow/vendor/pr2226_replay.py" + }, + "transformation": "byte copy" + }, + { + "local": "vendor/native/new/run_native_borrow.py", + "sha256": "8ec7db430f4f4771c06bdcfc31736193614f6ec209d57b63d4e2b75f17fb3ac8", + "origin": { + "repository": "philippeVV/integer-mult-bounds", + "commit": "2e2cf56521df8a2b816b2689144765ee00b69a24", + "path": "research/gmx-t74-borrow43-handoff/new/run_native_borrow.py" + }, + "transformation": "byte copy" + }, + { + "local": "fixtures/WORD-base.json.gz", + "sha256": "ae8b6b4d62a9da29331062fae1bd68b0341edf83152f5a5ef50c5109ba578f9a", + "origin": { + "commit": "4cfbb0cc8314d7fb4e8e754545a49a42eb590a69", + "path": "research/t74-joint-twelve/inputs/WORD-base.json.gz" + }, + "transformation": "byte copy" + }, + { + "local": "fixtures/WORD-extra.json.gz", + "sha256": "1bb44a73d5841afb954b49ae94dba2e0c536b1eea9436ae5d89de87d8a04e127", + "origin": { + "commit": "4cfbb0cc8314d7fb4e8e754545a49a42eb590a69", + "path": "research/t74-joint-twelve/inputs/WORD-extra.json.gz" + }, + "transformation": "byte copy" + } + ], + "predecessors": { + "PR662": "458744109003e0958798f27c1f04be78f03663ce", + "PR1029": "ff4d7b9ac97a584275fe0653f226f4ce2ffc6086", + "PR1041": "9576c644a4cafd2cfac309689a19342451702f81", + "PR2329": "68a7161a610f175dc8e7b22f95acd033191450d9", + "PR2751": "4cfbb0cc8314d7fb4e8e754545a49a42eb590a69" + }, + "reference_receipts": { + "commit": "4cfbb0cc8314d7fb4e8e754545a49a42eb590a69", + "path": "research/t74-joint-twelve/REUSE-PINS.json", + "sha256": "c33bf92fccb63f4d9a3ff6f7e025ac831ad012dd92d236b0f046bc4b1c6a29b2" + }, + "license": "Apache-2.0; retained notices accompany code." +} diff --git a/research/t74-native-fast/SOURCES.json b/research/t74-native-fast/SOURCES.json new file mode 100644 index 0000000000..aa25e09d27 --- /dev/null +++ b/research/t74-native-fast/SOURCES.json @@ -0,0 +1,56 @@ +{ + "schema_version": 1, + "base_commit": "2d3af1ba7e28b74248b47381768e5b116078ba1c", + "files": [ + { + "path": "AGENTS.md", + "usage": "provenance", + "git_blob": "00c96932e109c701310f4910057bae2d6cec0c0f", + "sha256": "2d47ee25f6900efa3bac76f66f59cc6d6e077ed1e7301497ab332668ad288d4c" + }, + { + "path": "CONTRIBUTING.md", + "usage": "provenance", + "git_blob": "e51435543687f1bd88ab22248082dc689ce8b853", + "sha256": "df5b5646602f42cb5da5844f04ac925182ddcd0f627b9de1c96a5095bb7a277a" + }, + { + "path": "autoresearch.md", + "usage": "provenance", + "git_blob": "0515a31cd888a18e5830987da12d4051f552c8cc", + "sha256": "e3e85885c27919c4f603954ef25339e9c1be4bd107f829921078b8134b366044" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "889b95d936746df124872133ae1e7cc339adcb92", + "sha256": "7d185cd8c2af35988d638d969748ad7b670f902606444dbfc748e4402c340df6" + }, + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "docs/research/current-status.md", + "usage": "provenance", + "git_blob": "d73b4ff9da41f044e793422db4318be17e234a6c", + "sha256": "adb54af005eb11edaf84d782fe729338680ff908f6d4fbf39ba1062d2e7d8a77" + }, + { + "path": "docs/research/pr-ledger.md", + "usage": "provenance", + "git_blob": "a8863ed429a4c0e7e701a2fadd96201cfc879920", + "sha256": "0147d16503fe779b32249ba66e23469cda9ecaa62e06c2c925e2fd4575109a56" + }, + { + "path": "docs/research/community-batch1099-review.md", + "usage": "provenance", + "git_blob": "6cb6ec061a071a06a2d18cd4dc3e9a2b05d28099", + "sha256": "7e76d2c38e5fce30587835b7251df1430488ae4dd372611ef69a3f03f476b6cb" + } + ], + "dependency_manifest": "SOURCE-PROVENANCE.json", + "scope": "Main selected result is provenance only. All executed dependencies are vendored, exact-pinned and separate from selected supplier admission." +} diff --git a/research/t74-native-fast/TASK.json b/research/t74-native-fast/TASK.json new file mode 100644 index 0000000000..6235ec0568 --- /dev/null +++ b/research/t74-native-fast/TASK.json @@ -0,0 +1,75 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "priority_revision": 5, + "base_commit": "2d3af1ba7e28b74248b47381768e5b116078ba1c", + "original_card": { + "id": "replay-runtime", + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the selected reproduction command and choose a single replay stage for profiling.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ] + }, + "scope_status": "refined", + "actual_scope": "Integrate PR1029 sparse exact state evaluation with PR662 gate tables into both Clifford-using stages of the complete warp-aware PR2751 T74 native replay. Benchmark complete five-stage runs against the unchanged driver.", + "scope_change_reason": "The earlier U8 fast runners omit the present T74 independent warp-recipe stage. This scope keeps that stage and all other native controls.", + "task_classification": "Explicit engineering override after comparing three narrow candidates; retained assignment seed2, no new random novelty claim.", + "assignment_seed": 2, + "candidate_tasks": [ + "Further source aliases: limited fixed-word headroom after PR2751.", + "Common-prefix mutation replay: higher coverage/invalidation risk.", + "Complete T74 sparse native integration: measured phase lowering bottleneck, chosen." + ], + "bottleneck_link": "Reducing the cost of fresh exact native admission lets changed-word candidates and independent reviewers iterate sooner.", + "budget_minutes": 60, + "stop_rule": "One source snapshot and two PR2751 provider words; three alternating paired base benchmarks, complete extra replay, output equivalence and boundary controls. No wider algorithmic search.", + "outcome": "completed", + "evidence": "Three alternating paired complete base native runs: median306.7496s reference versus85.8840s sparse (3.57167x). Every field of all11 native artifacts matches after only declared normalization; phase recipes byte-identical. Registered Python3.12/numpy2.2.6 replay passes both providers, Git-free relocation,1488 exact dense/sparse columns and18 boundary controls;84 inherited controls retained. See evidence/BENCHMARK.json, COVERAGE.json and VALIDATION.json.", + "author": "Tekalign (@tekuuu)", + "ai_assistance": "Substantial OpenAI Codex assistance in profiling, integration, verification, review and documentation. No independent human review claimed.", + "coordination": "https://github.com/CrocSwap/integer-mult-bounds/discussions/2755", + "open_questions": [ + { + "question": "Can the unchanged exact native local replay be accelerated next?", + "why_it_matters": "After exact state lowering is cheaper, independent local replay and warp matrices become a larger part of total time.", + "first_step": "Profile one complete fresh native run and price an exact representation change against the current all-column implementation.", + "blocked_by": "Must retain arbitrary-input, both-orientation and phase-sensitive checks; counting checks is not evidence of equivalent coverage." + }, + { + "question": "Should the opt-in runner become a maintained upstream native entry point?", + "why_it_matters": "Future construction authors could verify changed words faster without copying a full dependency tree.", + "first_step": "Independently replay this package and review its closed source inventory, output equivalence and failure controls.", + "blocked_by": "Maintainer approval and a migration plan for other native source versions. This snapshot does not auto-upgrade." + } + ] +} diff --git a/research/t74-native-fast/VERIFY.json b/research/t74-native-fast/VERIFY.json new file mode 100644 index 0000000000..17384abdd2 --- /dev/null +++ b/research/t74-native-fast/VERIFY.json @@ -0,0 +1,36 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [ + "numpy==2.2.6" + ], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py", + "--provider", + "base" + ], + "timeout_seconds": 600, + "checks": "Fresh complete five-stage base native replay, including independent all512-column warp recipes and all inherited controls; compare every native field to pinned reference. Also reject altered source, singular warp, paid profile, recipe, receipt, optimized execution and output reuse." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py", + "--provider", + "extra", + "--relocate" + ], + "timeout_seconds": 600, + "checks": "Fresh complete five-stage extra native replay, including independent all512-column warp recipes and all inherited controls; compare every native field to pinned reference. Execute from a Git-free relocated package in a path with spaces." + } + ] +} diff --git a/research/t74-native-fast/benchmark.py b/research/t74-native-fast/benchmark.py new file mode 100644 index 0000000000..93b2622759 --- /dev/null +++ b/research/t74-native-fast/benchmark.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Tekalign (@tekuuu), with substantial OpenAI Codex assistance. +"""Alternating fresh complete native runs; same fixture and no result caching.""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import platform +import statistics +import subprocess +import sys +import time +sys.path.insert(0,str(Path(__file__).resolve().parent)) +from common import HERE, need, source_bytes +from compare import compare + +def main(): + need(__debug__, 'assertions must remain enabled') + p=argparse.ArgumentParser(description=__doc__);p.add_argument('--pairs',type=int,default=3);p.add_argument('--provider',choices=('base','extra'),default='base');p.add_argument('--work',type=Path,required=True);a=p.parse_args() + need(a.pairs>=1 and not a.work.exists(),'positive pairs and fresh work required') + source_bytes(HERE/'vendor');word=HERE/f'fixtures/WORD-{a.provider}.json.gz' + pins=json.loads((HERE/'PINS.json').read_text()) + need(hashlib.sha256(word.read_bytes()).hexdigest()==pins[word.relative_to(HERE).as_posix()],'fixture digest') + a.work.mkdir(parents=True) + samples=[];comparisons=[];env=dict(os.environ,PYTHONDONTWRITEBYTECODE='1',PYTHONUTF8='1');env.pop('PYTHONOPTIMIZE',None) + for i in range(a.pairs): + paths={} + for engine in (('reference','sparse') if i%2==0 else ('sparse','reference')): + out=a.work/f'pair{i}-{engine}';cmd=[sys.executable,'-I','-B',str(HERE/'run_native.py'),str(word),str(out),'--engine',engine] + start=time.monotonic() + with (a.work/f'pair{i}-{engine}.log').open('w') as log:r=subprocess.run(cmd,env=env,stdout=log,stderr=subprocess.STDOUT,timeout=900) + elapsed=time.monotonic()-start;need(r.returncode==0,'native benchmark run failed '+str(out)) + receipt=json.loads((out/'RESULT.json').read_text());need(receipt['status']=='PASS_COMPLETE_T74_NATIVE_REPLAY','native receipt') + samples.append({'pair':i,'engine':engine,'wall_seconds':elapsed,'steps':receipt['steps']});paths[engine]=out/'native/local' + (a.work/'SAMPLES.json').write_text(json.dumps(samples,indent=2)+'\n');print('PASS sample',i,engine,round(elapsed,3),flush=True) + result=compare(paths['reference'],paths['sparse']);comparisons.append(result);print(result['status'],i,flush=True) + medians={e:statistics.median(s['wall_seconds'] for s in samples if s['engine']==e) for e in ('reference','sparse')} + result={'status':'PASS_COMPLETE_T74_NATIVE_BENCHMARK','provider':a.provider,'pairs':a.pairs,'samples':samples,'comparisons':comparisons,'median_wall_seconds':medians,'speedup':medians['reference']/medians['sparse'],'python':platform.python_version(),'platform':platform.platform(),'cpu_count':os.cpu_count(),'input_sha256':hashlib.sha256(word.read_bytes()).hexdigest(),'scope':'Fresh sequential subprocesses; all five stages and independent warp recipe check run each time. No cached result reuse. Shared host; OS caches not flushed. Timings descriptive, not a correctness threshold.'} + (a.work/'RESULT.json').write_text(json.dumps(result,indent=2)+'\n');print(result['status'],result['speedup'],flush=True) +if __name__=='__main__':main() diff --git a/research/t74-native-fast/common.py b/research/t74-native-fast/common.py new file mode 100644 index 0000000000..9ed8d88b97 --- /dev/null +++ b/research/t74-native-fast/common.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Tekalign (@tekuuu), with substantial OpenAI Codex assistance. +"""Authenticate the closed source snapshot before importing any vendored code.""" +import hashlib +import json +from pathlib import Path +HERE = Path(__file__).resolve().parent + +def need(condition, message): + if not condition: + raise ValueError(message) + +def sha(body): + return hashlib.sha256(body).hexdigest() + +def source_bytes(vendor): + pins = json.loads((HERE / 'PINS.json').read_text()) + expected = {p.removeprefix('vendor/'): h for p, h in pins.items() if p.startswith('vendor/')} + paths = list(vendor.rglob('*')) + need(not vendor.is_symlink() and all(not p.is_symlink() for p in paths), 'source symlink') + actual = {p.relative_to(vendor).as_posix(): p.read_bytes() for p in paths if p.is_file()} + need(set(actual) == set(expected), 'complete source path inventory') + for name, body in actual.items(): + need(sha(body) == expected[name], 'source digest: ' + name) + return actual diff --git a/research/t74-native-fast/compare.py b/research/t74-native-fast/compare.py new file mode 100644 index 0000000000..f3c60c6133 --- /dev/null +++ b/research/t74-native-fast/compare.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Tekalign (@tekuuu), with substantial OpenAI Codex assistance. +"""Compare all native mathematical outputs; only two elapsed fields are omitted. +Gzip container hashes are independently checked before semantic normalization. +""" +import gzip +import hashlib +import json +from pathlib import Path +import sys +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from common import need +FILES = { + 'CANONICAL-WORD.json.gz', 'FULL-WORD.json.gz', 'LOCAL-PROGRAMS.json.gz', + 'CLIFFORD-RECIPES.json', 'CLIFFORD-REVIEW.json', 'INDEPENDENT-LOCAL-REPLAY.json', + 'LOCAL-CHECKS.json', 'RESIDUAL-ADAPTERS.json', 'SCALAR-FRAME-AUDIT.json', + 'WARP-RECIPE-CHECKS.json', 'WRAPPER-CHECKS.json', +} +def sha(data): + return hashlib.sha256(data).hexdigest() +def canonical(value): + return json.dumps(value,sort_keys=True,separators=(',',':')).encode() +def normalized(directory): + need({p.name for p in directory.iterdir()}==FILES, 'complete native output inventory') + raw={n:(directory/n).read_bytes() for n in FILES} + data={n:gzip.decompress(b) if n.endswith('.gz') else b for n,b in raw.items()} + values={n:json.loads(b) for n,b in data.items()} + # Preserve and validate every hash's binding. Only container-dependent hashes + # are replaced by the digest of the actual decompressed artifact for comparison. + for n in ('INDEPENDENT-LOCAL-REPLAY.json','CLIFFORD-REVIEW.json','WARP-RECIPE-CHECKS.json'): + need(values[n]['canonical_word_sha256']==sha(raw['CANONICAL-WORD.json.gz']), 'canonical container binding '+n) + values[n]['canonical_word_sha256']=sha(data['CANONICAL-WORD.json.gz']) + for n in ('CLIFFORD-REVIEW.json','WARP-RECIPE-CHECKS.json'): + need(values[n]['recipe_sha256']==sha(raw['CLIFFORD-RECIPES.json']), 'recipe byte binding '+n) + need(values['INDEPENDENT-LOCAL-REPLAY.json']['local_programs_sha256']==sha(raw['LOCAL-PROGRAMS.json.gz']), 'program container binding') + values['INDEPENDENT-LOCAL-REPLAY.json']['local_programs_sha256']=sha(data['LOCAL-PROGRAMS.json.gz']) + audit=values['SCALAR-FRAME-AUDIT.json'] + need(audit['input_content_sha256']==sha(data['FULL-WORD.json.gz']), 'full word binding') + need(audit['canonical_content_sha256']==sha(data['CANONICAL-WORD.json.gz']), 'canonical content binding') + for n in ('SCALAR-FRAME-AUDIT.json','CLIFFORD-REVIEW.json'): + seconds=values[n].pop('seconds') + need(type(seconds) in (float,int) and seconds>=0, 'valid elapsed field '+n) + return values + +def compare(first,second): + a,b=normalized(first),normalized(second) + need(a==b,'native outputs differ: '+str([n for n in FILES if a[n]!=b[n]])) + return {'status':'PASS_ALL_NATIVE_OUTPUTS_IDENTICAL','files':len(FILES), + 'normalized_sha256':sha(canonical(a)), + 'recipe_bytes_sha256':sha((first/'CLIFFORD-RECIPES.json').read_bytes())} + +if __name__=='__main__': + print(json.dumps(compare(Path(sys.argv[1]),Path(sys.argv[2])),indent=2)) diff --git a/research/t74-native-fast/controls.py b/research/t74-native-fast/controls.py new file mode 100644 index 0000000000..5877dead77 --- /dev/null +++ b/research/t74-native-fast/controls.py @@ -0,0 +1,192 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Tekalign (@tekuuu), with substantial OpenAI Codex assistance. +"""Rejection controls at source, word, emitted recipe and receipt boundaries.""" +import copy +import gzip +import json +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import random + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from common import HERE, need, source_bytes +from compare import compare + + +def evaluator_check(): + """Finite differential check against this snapshot's original dense algebra. + + Seed2, dimensions1..5, twelve length20 circuits per dimension, every input + basis column. Covers all five gate kinds, both C signs and adjoints. This + supplements the predecessor proof; it is not a full formal proof. + """ + from stage import module + source_bytes(HERE / 'vendor') + algebra = module('clifford_exact', HERE / 'vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py') + tables = module('test_exact_tables', HERE / 'vendor/accelerators/tables.py') + sparse = module('test_exact_sparse', HERE / 'vendor/accelerators/sparse_state.py') + rng = random.Random(2) + columns = 0 + for n in range(1, 6): + for _ in range(12): + op = algebra.ident(n) + for j in range(20): + if j % 5 == 0: + rows = [1 << i for i in range(n)] + if n > 1: + for _ in range(2 * n): + a, b = rng.sample(range(n), 2) + rows[a] ^= rows[b] + gate = algebra.perm(n, rows) + elif j % 5 == 1: + rows = [0] * n + for a in range(n): + for b in range(a, n): + if rng.randrange(2): + rows[a] |= 1 << b + rows[b] |= 1 << a + alpha = [((rows[i] >> i) & 1) + 2 * rng.randrange(2) for i in range(n)] + gate = algebra.diag(n, rows, alpha) + elif j % 5 == 2: + gate = algebra.cgate(n, rng.randrange(1 << n), rng.choice((-1, 1))) + elif j % 5 == 3: + gate = algebra.xgate(n, rng.randrange(1 << n)) + else: + gate = algebra.ident(n) + gate.circuit.append(('phase', rng.randrange(4))) + op = op.then(gate) + for candidate in (op, op.adjoint()): + for basis in range(1 << n): + need(candidate.zero_state(basis) == sparse.zero_state(candidate, tables, basis), + 'dense/sparse exact state mismatch') + columns += 1 + print('PASS_T74_EXACT_STATE_DIFFERENTIAL', columns, 'columns') + + +def reject(argv, message): + result = subprocess.run([sys.executable, '-I', '-B', *map(str, argv)], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=45) + text = result.stdout.decode(errors='replace') + need(result.returncode != 0 and message in text, 'expected rejection: ' + message + '\n' + text[-2000:]) + + +def check(local): + evaluator_check() + controls = [] + with tempfile.TemporaryDirectory(prefix='t74-negative-') as temporary: + root = Path(temporary) + # Authenticate before loading even the first vendored import. A sentinel + # would be created if tampered code were executed before rejection. + for mutation in ('digest', 'extra', 'missing', 'symlink'): + vendor = root / mutation + shutil.copytree(HERE / 'vendor', vendor) + target = vendor / 'accelerators/tables.py' + if mutation == 'digest': + sentinel = root / 'EXECUTED' + target.write_text('from pathlib import Path\nPath(' + repr(str(sentinel)) + ').touch()\n') + message = 'source digest' + elif mutation == 'extra': + (vendor / 'unlisted.py').write_text('raise RuntimeError("unlisted")\n') + message = 'complete source path inventory' + elif mutation == 'missing': + target.unlink() + message = 'complete source path inventory' + else: + target.unlink() + target.symlink_to(HERE / 'vendor/accelerators/tables.py') + message = 'source symlink' + reject([HERE / 'stage.py', '--vendor', vendor, '--script', 'bw_phases.py', root / 'unused'], message) + controls.append('source:' + mutation) + need(not (root / 'EXECUTED').exists(), 'tampered source executed') + package = root / 'changed fixture package' + shutil.copytree(HERE, package, ignore=shutil.ignore_patterns('__pycache__')) + fixture = package / 'fixtures/WORD-base.json.gz' + fixture.write_bytes(fixture.read_bytes() + b'changed') + unused = root / 'benchmark-must-not-start' + reject([package / 'benchmark.py', '--pairs', 1, '--work', unused], 'fixture digest') + need(not unused.exists(), 'invalid benchmark fixture created outputs') + controls.append('benchmark-fixture') + for script in ('run_native.py', 'stage.py', 'verify.py'): + reject(['-O', HERE / script], 'assertions must remain enabled') + controls.append('optimized:' + script) + existing = root / 'existing' + existing.mkdir() + (existing / 'preserve').write_text('do not overwrite') + reject([HERE / 'run_native.py', HERE / 'fixtures/WORD-base.json.gz', existing], 'fresh work directory required') + need(list(existing.iterdir()) == [existing / 'preserve'] and + (existing / 'preserve').read_text() == 'do not overwrite', 'existing output changed') + controls.append('existing-output') + + word = json.loads(gzip.decompress((HERE / 'fixtures/WORD-base.json.gz').read_bytes())) + for mutation in ('singular-warp', 'paid-profile'): + bad = copy.deepcopy(word) + if mutation == 'singular-warp': + bad['warps'][0][2][1] = bad['warps'][0][2][0] + message = 'non-invertible G' + else: + key = next(iter(bad['report']['local_profile'])) + bad['report']['local_profile'][key] += 1 + message = 'paid profile differs' + path = root / (mutation + '.json') + path.write_text(json.dumps(bad)) + for engine in ('reference', 'sparse'): + out = root / (mutation + '-' + engine) + reject([HERE / 'run_native.py', path, out, '--engine', engine], 'stage failed') + log = out / ('reference-driver.log' if engine == 'reference' else 'native-bw_transport.py.log') + need(message in log.read_text(), 'wrong rejection reason for ' + str(out)) + need(not (out / 'RESULT.json').exists(), 'failed native run wrote success') + controls.append('word:' + mutation + ':' + engine) + + # Exercise the independent checker on mutated FILES, in addition to its + # thirteen retained internal matrix-mutation controls in every full run. + for mutation in ('phase', 'missing-class'): + out = root / ('recipe-' + mutation) + shutil.copytree(local, out) + path = out / 'CLIFFORD-RECIPES.json' + recipes = json.loads(path.read_text()) + if mutation == 'phase': + left = recipes['warps'][0]['left'] + left['phase'] = (left['phase'] + 1) % 4 + message = 'warp recipe is not the exact column product' + else: + recipes['warps'].pop() + message = 'recipe classes differ' + path.write_text(json.dumps(recipes)) + reject([HERE / 'vendor/native/new/code/borrow/bw_check_recipes.py', out], message) + controls.append('recipe-file:' + mutation) + + for mutation in ('coverage', 'missing-file', 'container-binding'): + out = root / ('receipt-' + mutation) + shutil.copytree(local, out) + if mutation == 'missing-file': + (out / 'LOCAL-CHECKS.json').unlink() + message = 'complete native output inventory' + else: + path = out / 'WARP-RECIPE-CHECKS.json' + receipt = json.loads(path.read_text()) + if mutation == 'coverage': + receipt['controls_rejected'].pop() + message = 'native outputs differ' + else: + receipt['canonical_word_sha256'] = '0' * 64 + message = 'canonical container binding' + path.write_text(json.dumps(receipt)) + try: + compare(local, out) + except ValueError as error: + need(message in str(error), 'wrong comparison failure') + else: + raise AssertionError('altered native outputs accepted: ' + mutation) + controls.append('comparison:' + mutation) + print('PASS_T74_NATIVE_FAST_BOUNDARY_CONTROLS', len(controls), json.dumps(controls)) + return controls + + +if __name__ == '__main__': + need(__debug__, 'assertions must remain enabled') + source_bytes(HERE / 'vendor') + check(Path(sys.argv[1])) diff --git a/research/t74-native-fast/evidence/BENCHMARK.json b/research/t74-native-fast/evidence/BENCHMARK.json new file mode 100644 index 0000000000..53c0d77ab3 --- /dev/null +++ b/research/t74-native-fast/evidence/BENCHMARK.json @@ -0,0 +1,249 @@ +{ + "status": "PASS_COMPLETE_T74_NATIVE_BENCHMARK", + "provider": "base", + "pairs": 3, + "samples": [ + { + "pair": 0, + "engine": "reference", + "wall_seconds": 304.12705635900784, + "steps": [ + { + "step": "native", + "exit_code": 0, + "seconds": 1.2277613850019407 + }, + { + "step": "ledgers", + "exit_code": 0, + "seconds": 1.4153370510030072 + }, + { + "step": "local-replay", + "exit_code": 0, + "seconds": 38.20502878499974 + }, + { + "step": "wrappers", + "exit_code": 0, + "seconds": 5.7440066569979535 + }, + { + "step": "phases", + "exit_code": 0, + "seconds": 257.3918046769977 + } + ] + }, + { + "pair": 0, + "engine": "sparse", + "wall_seconds": 85.88402091899479, + "steps": [ + { + "step": "native", + "exit_code": 0, + "seconds": 1.189789870986715 + }, + { + "step": "ledgers", + "exit_code": 0, + "seconds": 1.4454092910018517 + }, + { + "step": "local-replay", + "exit_code": 0, + "seconds": 37.58784284500871 + }, + { + "step": "wrappers", + "exit_code": 0, + "seconds": 2.166318774994579 + }, + { + "step": "phases", + "exit_code": 0, + "seconds": 43.39858223599731 + } + ] + }, + { + "pair": 1, + "engine": "sparse", + "wall_seconds": 85.56597218499519, + "steps": [ + { + "step": "native", + "exit_code": 0, + "seconds": 1.1618483210040722 + }, + { + "step": "ledgers", + "exit_code": 0, + "seconds": 1.4005460170010338 + }, + { + "step": "local-replay", + "exit_code": 0, + "seconds": 37.7024452869955 + }, + { + "step": "wrappers", + "exit_code": 0, + "seconds": 2.0632049500127323 + }, + { + "step": "phases", + "exit_code": 0, + "seconds": 43.14079914300237 + } + ] + }, + { + "pair": 1, + "engine": "reference", + "wall_seconds": 308.15912566099723, + "steps": [ + { + "step": "native", + "exit_code": 0, + "seconds": 1.1598684070049785 + }, + { + "step": "ledgers", + "exit_code": 0, + "seconds": 1.4444775400043 + }, + { + "step": "local-replay", + "exit_code": 0, + "seconds": 37.1472855930042 + }, + { + "step": "wrappers", + "exit_code": 0, + "seconds": 5.759292622999055 + }, + { + "step": "phases", + "exit_code": 0, + "seconds": 262.5130987189914 + } + ] + }, + { + "pair": 2, + "engine": "reference", + "wall_seconds": 306.74960786000884, + "steps": [ + { + "step": "native", + "exit_code": 0, + "seconds": 1.204015570008778 + }, + { + "step": "ledgers", + "exit_code": 0, + "seconds": 1.4606356029980816 + }, + { + "step": "local-replay", + "exit_code": 0, + "seconds": 38.59787878699717 + }, + { + "step": "wrappers", + "exit_code": 0, + "seconds": 5.9340596520050894 + }, + { + "step": "phases", + "exit_code": 0, + "seconds": 259.39262297499226 + } + ] + }, + { + "pair": 2, + "engine": "sparse", + "wall_seconds": 87.2939048440021, + "steps": [ + { + "step": "native", + "exit_code": 0, + "seconds": 1.208094222994987 + }, + { + "step": "ledgers", + "exit_code": 0, + "seconds": 1.4107751400006237 + }, + { + "step": "local-replay", + "exit_code": 0, + "seconds": 38.536898468999425 + }, + { + "step": "wrappers", + "exit_code": 0, + "seconds": 2.150425133993849 + }, + { + "step": "phases", + "exit_code": 0, + "seconds": 43.88330491501256 + } + ] + } + ], + "comparisons": [ + { + "status": "PASS_ALL_NATIVE_OUTPUTS_IDENTICAL", + "files": 11, + "normalized_sha256": "72152474a7c1f65f8bddec3197a9661d035e2ef0edfd08751a19038c470f654f", + "recipe_bytes_sha256": "3fad1a9ae138ddb89442753cb2ef3c0666c58f40d5488d503fbf75f7f480d4d3" + }, + { + "status": "PASS_ALL_NATIVE_OUTPUTS_IDENTICAL", + "files": 11, + "normalized_sha256": "72152474a7c1f65f8bddec3197a9661d035e2ef0edfd08751a19038c470f654f", + "recipe_bytes_sha256": "3fad1a9ae138ddb89442753cb2ef3c0666c58f40d5488d503fbf75f7f480d4d3" + }, + { + "status": "PASS_ALL_NATIVE_OUTPUTS_IDENTICAL", + "files": 11, + "normalized_sha256": "72152474a7c1f65f8bddec3197a9661d035e2ef0edfd08751a19038c470f654f", + "recipe_bytes_sha256": "3fad1a9ae138ddb89442753cb2ef3c0666c58f40d5488d503fbf75f7f480d4d3" + } + ], + "median_wall_seconds": { + "reference": 306.74960786000884, + "sparse": 85.88402091899479 + }, + "speedup": 3.5716726415188793, + "python": "3.12.14", + "platform": "Linux-7.2.8-200.fc44.x86_64-x86_64-with-glibc2.43", + "cpu_count": 16, + "input_sha256": "ae8b6b4d62a9da29331062fae1bd68b0341edf83152f5a5ef50c5109ba578f9a", + "scope": "Fresh sequential subprocesses; all five stages and independent warp recipe check run each time. No cached result reuse. Shared host; OS caches not flushed. Timings descriptive, not a correctness threshold.", + "numpy_version": "2.2.6", + "stage_median_seconds": { + "reference": { + "native": 1.204015570008778, + "ledgers": 1.4444775400043, + "local-replay": 38.20502878499974, + "wrappers": 5.759292622999055, + "phases": 259.39262297499226 + }, + "sparse": { + "native": 1.189789870986715, + "ledgers": 1.4107751400006237, + "local-replay": 37.7024452869955, + "wrappers": 2.150425133993849, + "phases": 43.39858223599731 + } + }, + "whole_native_time_reduction_percent": 72.00191337874843, + "launch_command": "python3.12 -I -B research/t74-native-fast/benchmark.py --pairs 3 --provider base --work FRESH_DIRECTORY", + "source_pin_manifest_sha256": "f619e8e1c163078fb70c6fc3b98a498a671b8c02927b91d6cc253af2a775b6c9" +} diff --git a/research/t74-native-fast/evidence/COVERAGE.json b/research/t74-native-fast/evidence/COVERAGE.json new file mode 100644 index 0000000000..6ccc53ea51 --- /dev/null +++ b/research/t74-native-fast/evidence/COVERAGE.json @@ -0,0 +1,106 @@ +{ + "scope": "Coverage summary extracted from the complete original base replay. All eleven complete native outputs are compared separately, not merely this summary.", + "arbitrary_live_columns_each_orientation": 639, + "warp_replay": { + "status": "PASS_EXACT_MONOMIAL_WARP_COLUMNS_ALL_512_BOTH_ORIENTATIONS", + "warps": 65, + "event_classes_checked_on_all_512_columns": 202, + "zero_buffers": 72 + }, + "local_controls": [ + "wrong_scale", + "missing_center", + "wrong_common_frame", + "wrong_child_rank", + "missing_pre_wrapper", + "missing_post_wrapper", + "wrapper_with_wrong_frame", + "wrapper_in_wrong_phase", + "wrapper_on_a_data_register", + "wrapper_on_a_target_register", + "wrapper_on_a_centre_register", + "centre_step_not_nested", + "centre_descent_incomplete", + "hpe_pre_wrapper_resolved_to_full_recipe", + "hpe_post_wrapper_without_terminal_frame", + "hpe_post_wrapper_wrong_terminal_frame", + "hpe_tail_gate_at_full_frame", + "hpe_tail_climb_dropped", + "hpe_helper_exit_adapter_to_full", + "hpe_tail_gate_moved_into_full_cleanup", + "cold_hpe_pre_wrapper_replaced_by_identity_entry_adapter", + "cold_hpe_pre_wrapper_dropped", + "cold_hpe_post_wrapper_replaced_by_exit_adapter", + "cold_hpe_pre_wrapper_resolved_to_cold_full_convention", + "cold_hpe_wrapper_with_nonzero_entrance", + "cold_hpe_post_wrapper_wrong_terminal_frame", + "cold_hpe_premix_gate_before_pre_wrapper", + "warp_missing_inverse_at_full_cleanup", + "warp_missing_forward", + "warp_frame_mismatch", + "warp_to_frame_not_carried_by_G", + "warp_wrong_sign", + "warp_wrong_operator", + "warp_inverse_moved_before_use", + "warp_inverse_wrong_frame", + "warp_rank_changing", + "warp_phase_B_dropped_gate_after_warp", + "zero_buffer_not_freed", + "zero_buffer_gate_outside_cleanup", + "zero_buffer_garbage_left", + "zero_buffer_replaced_by_restored_register_at_full", + "warp_wrong_G_invertible_not_carrying_frame", + "warp_noninvertible_G", + "warp_zero_column_G", + "warp_operator_dropped_from_table", + "warp_wrong_quadratic_phase_of_K" + ], + "wrapper_controls": [ + "wrong global phase", + "wrong translation", + "wrong quadratic form", + "sides swapped", + "wrong width", + "hpe: U-wrapper decoded against a FULL ending", + "hpe: width misreported as 9 - dim E", + "hpe: wrong terminal hyperplane", + "hpe: pre wrapper resolved to the FULL recipe R_{E,FULL}", + "hpe: wrong global phase", + "cold hpe: identity pre wrapper instead of R_{0,U}", + "cold hpe: identity post wrapper instead of L_{0,U}", + "cold hpe: no wrappers (cold FULL convention L = R = I)", + "cold hpe: U-wrapper decoded against a FULL ending", + "cold hpe: width misreported as 9", + "cold hpe: wrong terminal hyperplane", + "cold hpe: wrong global phase", + "warp: wrong global phase", + "warp: wrong translation", + "warp: wrong linear phase", + "warp: wrong quadratic form", + "warp: recipe of another operator", + "warp: inverse recipe used as the warp", + "warp: wrong G (frame-changed column)", + "warp: non-invertible G" + ], + "recipe_controls": [ + "recipe: wrong global phase", + "recipe: wrong translation", + "recipe: wrong linear phase", + "recipe: wrong quadratic form", + "recipe: wrong matrix", + "recipe: wrong G (still invertible)", + "recipe: non-invertible G", + "recipe: inverse warp recipe used for the forward warp", + "recipe: recipe of another warp class", + "recipe: swapped from/to frames", + "recipe: missing warp class", + "logical: wrong G", + "logical: wrong phase" + ], + "recipe_warp_classes": 166, + "recipe_columns_each": 512, + "phase_frames": 1076, + "directed_edges": 2940, + "endpoint_adapters": 224, + "all_child_equalities_include_global_phase": true +} diff --git a/research/t74-native-fast/evidence/REGISTERED.log b/research/t74-native-fast/evidence/REGISTERED.log new file mode 100644 index 0000000000..dd419f7dee --- /dev/null +++ b/research/t74-native-fast/evidence/REGISTERED.log @@ -0,0 +1,20 @@ +CHECK Fresh complete five-stage base native replay, including independent all512-column warp recipes and all inherited controls; compare every native field to pinned reference. Also reject altered source, singular warp, paid profile, recipe, receipt, optimized execution and output reuse. +PASS native +PASS ledgers +PASS local-replay +PASS wrappers +PASS phases +PASS_COMPLETE_T74_NATIVE_REPLAY sparse 86.818 +PASS_T74_EXACT_STATE_DIFFERENTIAL 1488 columns +PASS_T74_NATIVE_FAST_BOUNDARY_CONTROLS 18 ["source:digest", "source:extra", "source:missing", "source:symlink", "benchmark-fixture", "optimized:run_native.py", "optimized:stage.py", "optimized:verify.py", "existing-output", "word:singular-warp:reference", "word:singular-warp:sparse", "word:paid-profile:reference", "word:paid-profile:sparse", "recipe-file:phase", "recipe-file:missing-class", "comparison:coverage", "comparison:missing-file", "comparison:container-binding"] +PASS_T74_NATIVE_FAST_REFERENCE_AND_CONTROLS base +CHECK Fresh complete five-stage extra native replay, including independent all512-column warp recipes and all inherited controls; compare every native field to pinned reference. Execute from a Git-free relocated package in a path with spaces. +PASS native +PASS ledgers +PASS local-replay +PASS wrappers +PASS phases +PASS_COMPLETE_T74_NATIVE_REPLAY sparse 87.385 +PASS_T74_NATIVE_FAST_REFERENCE_AND_CONTROLS extra +PASS_T74_NATIVE_FAST_GIT_FREE_RELOCATION extra +PASS_REGISTERED_RESEARCH_PACKAGE research/t74-native-fast outcome=partial diff --git a/research/t74-native-fast/evidence/VALIDATION.json b/research/t74-native-fast/evidence/VALIDATION.json new file mode 100644 index 0000000000..9848bae05c --- /dev/null +++ b/research/t74-native-fast/evidence/VALIDATION.json @@ -0,0 +1,44 @@ +{ + "status": "PASS_COMPLETE_T74_NATIVE_FAST_VALIDATION", + "checked_at": "2026-10-15T20:57:23.935468+00:00", + "command": "python3.12 scripts/research_package.py --package research/t74-native-fast", + "python": "3.12.14", + "numpy": "2.2.6", + "registered_exit_code": 0, + "providers": [ + "base", + "extra" + ], + "extra_git_free_relocation": true, + "dense_sparse_columns": 1488, + "boundary_controls_rejected": 18, + "inherited_controls_per_provider": { + "local": 46, + "wrappers": 25, + "recipes": 13 + }, + "benchmark_pairs": 3, + "outputs_compared_per_pair": 11, + "registered_log_sha256": "78a49def69d0465f4318b9e24613246ba5fb6de19441e54b88fb50dfe823f149", + "code_sha256": { + "benchmark.py": "3e544453c89310281d745a37e861cbd79065b1740d90f1ec883fc200b189a557", + "common.py": "8f04e08b99a370fa82115fc46fbb3af4ab44f4facd47de07b01e1a2499a94914", + "compare.py": "ebf877a6f47ef1fd2b797fd6077bd45d132d8cb56ab7553044bae3d86e238e45", + "controls.py": "03131f4dc6a1830f10e35fb837ada456f060ca510994d250c5c2666a6342c23a", + "run_native.py": "a7bfe110fe5098f6ef8bde3c43ecf15e8d1e06149abf7321a4c945383dcc2627", + "stage.py": "3cce27dd5a359ebc4dc70d4aab994aee52bc0a12e59db7da3f902257f876cffe", + "verify.py": "6dbdc56ca6cfde987869e12990a495d7eded78dd1887fb3fdf2d196060220fcc" + }, + "pin_manifest_sha256": "f619e8e1c163078fb70c6fc3b98a498a671b8c02927b91d6cc253af2a775b6c9", + "notes": [ + "The registered log reports outcome=partial because metadata was finalized only after both provider checks succeeded; the complete outcome is recorded now.", + "After timing, benchmark.py gained a fixture-digest guard before any timed subprocess. Its corruption control passes. Timed run_native.py, stage.py, common.py and vendored execution sources are unchanged.", + "Initial sparse-checkout metadata failures were resolved by materializing package paths before the successful full replay. They were not mathematical failures." + ], + "not_claimed": [ + "new kappa", + "complete supplier or outer replay in this round", + "whole-project speedup", + "formal verification of the multiplication theorem" + ] +} diff --git a/research/t74-native-fast/fixtures/WORD-base.json.gz b/research/t74-native-fast/fixtures/WORD-base.json.gz new file mode 100644 index 0000000000..f1fc67a6ea Binary files /dev/null and b/research/t74-native-fast/fixtures/WORD-base.json.gz differ diff --git a/research/t74-native-fast/fixtures/WORD-extra.json.gz b/research/t74-native-fast/fixtures/WORD-extra.json.gz new file mode 100644 index 0000000000..f06e80c4dd Binary files /dev/null and b/research/t74-native-fast/fixtures/WORD-extra.json.gz differ diff --git a/research/t74-native-fast/requirements.txt b/research/t74-native-fast/requirements.txt new file mode 100644 index 0000000000..aaa34fa3b2 --- /dev/null +++ b/research/t74-native-fast/requirements.txt @@ -0,0 +1 @@ +numpy==2.2.6 diff --git a/research/t74-native-fast/run_native.py b/research/t74-native-fast/run_native.py new file mode 100644 index 0000000000..64ef0eb83f --- /dev/null +++ b/research/t74-native-fast/run_native.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Tekalign (@tekuuu), with substantial OpenAI Codex assistance. +"""Complete T74 native replay; fresh source snapshot, no result cache. + +Uses the unchanged T74 transport, emitter, local audit, adapters, phase lowering +and independent warp-recipe audit. Only Op.zero_state in the two Clifford-using +stages changes to the previously published exact sparse evaluator. +""" +import argparse +import json +import os +from pathlib import Path +import platform +import subprocess +import sys +import time +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from common import HERE, need, sha, source_bytes + +STEPS = ('native', 'ledgers', 'local-replay', 'wrappers', 'phases') + +def main(): + need(__debug__, 'assertions must remain enabled') + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('word', type=Path) + parser.add_argument('work', type=Path) + parser.add_argument('--engine', choices=('reference', 'sparse'), default='sparse') + args = parser.parse_args() + started = time.monotonic() + blobs = source_bytes(HERE / 'vendor') + original = args.word.resolve() + need(original.is_file(), 'input word missing') + body = original.read_bytes() + work = args.work.resolve() + need(not work.exists(), 'fresh work directory required') + work.mkdir(parents=True) + vendor = work / 'source' + for name, contents in blobs.items(): + target = vendor / name + target.parent.mkdir(parents=True, exist_ok=True) + target.write_bytes(contents) + word = work / ('INPUT.json.gz' if original.suffix == '.gz' else 'INPUT.json') + word.write_bytes(body) + native = vendor / 'native/new/code/borrow' + output = work / 'native' + env = dict(os.environ, PYTHONDONTWRITEBYTECODE='1', PYTHONUTF8='1', PYTHONINTMAXSTRDIGITS='0') + env.pop('PYTHONOPTIMIZE', None) + commands = [] + def run(name, command, cwd): + before = time.monotonic() + with (work / (name + '.log')).open('w') as log: + result = subprocess.run(command, cwd=cwd, env=env, stdin=subprocess.DEVNULL, + stdout=log, stderr=subprocess.STDOUT) + entry = {'step': name, 'exit_code': result.returncode, + 'seconds': time.monotonic()-before, 'command': command} + commands.append(entry) + (work / 'COMMANDS.json').write_text(json.dumps(commands, indent=2)+'\n') + need(result.returncode == 0, 'stage failed: '+name+'; see '+str(work/(name+'.log'))) + return entry + if args.engine == 'reference': + run('reference-driver', [sys.executable, '-I', '-B', str(vendor/'native/new/run_native_borrow.py'), str(word), str(output)], native) + steps = json.loads((output/'STEPS.json').read_text()) + else: + output.mkdir() + local = output/'local' + plan = [ + ('native', [('bw_transport.py', [word, local])]), + ('ledgers', [('bw_emit.py', [local])]), + ('local-replay', [('bw_audit_local.py', [local])]), + ('wrappers', [('bw_adapters.py', [local/'CANONICAL-WORD.json.gz', local/'RESIDUAL-ADAPTERS.json', local/'WRAPPER-CHECKS.json'])]), + ('phases', [('bw_phases.py', [local]), ('bw_check_recipes.py', [local])]), + ] + steps = [] + for label, scripts in plan: + before = time.monotonic() + for script, arguments in scripts: + if script in ('bw_adapters.py', 'bw_phases.py'): + command = [sys.executable, '-I', '-B', str(HERE/'stage.py'), '--vendor', str(vendor), '--script', script] + else: + command = [sys.executable, '-I', '-B', str(native/script)] + run(label+'-'+script, command + list(map(str, arguments)), native) + steps.append({'step':label,'exit_code':0,'seconds':time.monotonic()-before}) + (output/'STEPS.json').write_text(json.dumps(steps,indent=2)+'\n') + print('PASS', label, flush=True) + need([s['step'] for s in steps] == list(STEPS) and all(s['exit_code']==0 for s in steps), 'complete native stage coverage') + need(source_bytes(vendor) == blobs and word.read_bytes() == body, 'source or input modified') + result = {'status':'PASS_COMPLETE_T74_NATIVE_REPLAY', 'engine':args.engine, + 'word_sha256':sha(body), 'source_sha256':{k:sha(v) for k,v in sorted(blobs.items())}, + 'steps':steps, 'seconds':time.monotonic()-started, 'python':platform.python_version(), + 'scope':'Full five-stage native replay including independent all-column warp recipes and original rejection controls; supplier/outer admission separate.'} + (work/'RESULT.json').write_text(json.dumps(result,indent=2)+'\n') + print(result['status'], args.engine, round(result['seconds'],3), flush=True) + +if __name__ == '__main__': + main() diff --git a/research/t74-native-fast/stage.py b/research/t74-native-fast/stage.py new file mode 100644 index 0000000000..9ecc54bca4 --- /dev/null +++ b/research/t74-native-fast/stage.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Tekalign (@tekuuu), with substantial OpenAI Codex assistance. +"""Run an unchanged pinned T74 script with PR1029/PR662 exact state evaluation.""" +import argparse +import importlib.util +from pathlib import Path +import runpy +import sys +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from common import need, source_bytes + +def module(name, path): + spec = importlib.util.spec_from_file_location(name, path) + result = importlib.util.module_from_spec(spec) + sys.modules[name] = result + spec.loader.exec_module(result) + return result + +def main(): + need(__debug__, 'assertions must remain enabled') + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--vendor', type=Path, required=True) + parser.add_argument('--script', choices=('bw_adapters.py', 'bw_phases.py'), required=True) + parser.add_argument('arguments', nargs='+') + args = parser.parse_args() + vendor = args.vendor.resolve() + source_bytes(vendor) + native = vendor / 'native/new/code/borrow' + algebra = module('clifford_exact', native / 'vendor/clifford/clifford_exact.py') + tables = module('t74_exact_tables', vendor / 'accelerators/tables.py') + sparse = module('t74_exact_sparse', vendor / 'accelerators/sparse_state.py') + tables.clear_caches() + algebra.Op.zero_state = lambda self, basis=0: sparse.zero_state(self, tables, basis) + script = native / args.script + sys.argv = [str(script), *args.arguments] + runpy.run_path(str(script), run_name='__main__') + +if __name__ == '__main__': + main() diff --git a/research/t74-native-fast/vendor/accelerators/SPARSE-NOTICE.md b/research/t74-native-fast/vendor/accelerators/SPARSE-NOTICE.md new file mode 100644 index 0000000000..a3b31e157f --- /dev/null +++ b/research/t74-native-fast/vendor/accelerators/SPARSE-NOTICE.md @@ -0,0 +1,33 @@ +# Attribution + +Prepared for Ali Romman (@aliromman) with substantial OpenAI Codex assistance. +New code, tests and documentation use the repository's Apache-2.0 license. +No independent human review is claimed. + +- Charles Bethin (@cbethin), PR662, supplied the exact permutation and phase + tables. This package imports those tables unchanged and compares against + his complete dense evaluator. PR662 head: + `458744109003e0958798f27c1f04be78f03663ce`. +- The Gaussian-dyadic algebra and lowering come from the retained + `clifford_exact.py`. `lowering.py` adapts its `monomial` and `lower_child` + routines to take an evaluator argument. `run.py` adapts `phases_full.py`. + The latter credits icekylinx and the PR425 ancestry, with Codex assistance. + The PR531 license and notice remain at + `research/complex-k492-owner-repair/vendor/multicold/vendor/pr558/vendor/pr552/complex-global/vendor531/`. + Those files retain the upstream contributor and AI-assistance notices. +- Jonathan Capalbo's PR942 supplies the retained U8 replay archive used by + the benchmark. Its head is + `1960cfa919a0945d0ca4cb14ea96237000037903`. + The U8 word comes from the PR869/870 lineage, which credits NewBArch's + triangle-hybrid construction and ColdWitness/icekylinx's driver, on Jeremy + Kothe's PR799 X4 work. Chafik Boukhalfa's PR741/890 work and Hao Yan's + PR858 work remain credited in the retained package notices. + +The new contribution is the sparse state update, its explicit compiler +entry point, and the complete U8 comparison with corruption controls and +time/memory measurements. Sparse state propagation is an established general +technique; this package makes no priority claim for that technique. + +The package does not change frozen source files, accepted certificates, +`upstream/`, or the default selected replay. All inherited compiler, +realization, hosting, precision, tape and analytic obligations remain. diff --git a/research/t74-native-fast/vendor/accelerators/SPARSE-PROOF.md b/research/t74-native-fast/vendor/accelerators/SPARSE-PROOF.md new file mode 100644 index 0000000000..bbd5990439 --- /dev/null +++ b/research/t74-native-fast/vendor/accelerators/SPARSE-PROOF.md @@ -0,0 +1,81 @@ +# Exact support updates + +This argument applies to the valid gates from the pinned `clifford_exact.py`. +The input is a basis index `0 <= basis < 2^n`. Each state has Gaussian integer +numerators and a common denominator `2^den`. A missing dictionary key has +numerator zero. The output contains all `2^n` numerators, including zeros. + +## Induction over the circuit + +The initial dictionary has the one entry `basis -> (1, 0)`. It is the same +state as the retained dense evaluator. + +For `P`, the validated binary matrix is invertible. Its index map is a +permutation. Thus no two nonzero entries collide, and omitted zero entries +contribute no value. For `X`, translation by XOR is also a permutation. + +For `D` and `phase`, each amplitude is multiplied by a power of `i`. The +four rotations of `(a, b)` are `(a, b)`, `(-b, a)`, `(-a, -b)`, and `(b, -a)`. +Zero remains zero. The `D` phases and `P` index maps use the unchanged PR662 +tables. Those tables depend on the dimension and all gate coefficients. +They do not depend on a state or on a previous check result. The source pins +retain their exact formulas and bounded caches. + +For `C`, put `y = x xor q` and let `s` be the sign. If the numerators at +`x` and `y` are `(a, b)` and `(c, d)`, the new numerators are + +```text +x: (a - s*b + c + s*d, b + s*a + d - s*c) +y: (c - s*d + a + s*b, d + s*c + b - s*a). +``` + +The denominator exponent increases by one. These are the two rows of the +retained dense update. XOR partitions the index set into pairs when `q != 0`. +The loop visits a pair once if either entry is nonzero. If both entries are +present, it skips the larger index. If only one entry is present, its partner +has value zero. A pair with two zero entries contributes two zeros and need +not be visited. Exact cancellation removes a zero output entry. When `q = 0`, +both formulas give `(2*a, 2*b)` at the same index; the update is the identity +after division by two. + +The common-factor test after `C` gives the same answer on the dictionary as +on the dense vector: omitted entries are zero and are divisible by two. +The other gates only permute entries or rotate their Gaussian coordinates. +They cannot change the common power of two. Thus those gates need no further +normalization. This proves equality of both the complete vector and `den` +after every gate. It also covers circuits whose support shrinks after a +`C` gate. A valid Clifford circuit cannot map a nonzero input to the zero +state, because each gate is invertible. + +## The compiler checks + +`lowering.py` retains the algebra and checks of the pinned lowering routine. +It passes a state evaluator through ordinary function arguments. It changes +no retained module, method or global value. The reference mode calls the +original lowering routine. The dense and sparse modes use the same explicit +lowering code with their respective evaluators. + +Every tableau equality, off-support zero check, denominator check, and global +phase check remains. The final comparison still checks the complete compiled +state against the complete input state. No phase is inferred from a tableau. + +`run.py` retains the frame-span, frame-rank, edge-rank and endpoint-rank checks +of `phases_full.py`. It visits every frame, every directed edge including +center transitions, and every source and target adapter. Its public entry +point rejects optimized Python before it loads the retained assertion-based +algebra. It also rejects source drift and an existing output directory. + +## Work and storage + +Let `s` be the current number of nonzero amplitudes and `N = 2^n`. A state +update now visits `s` entries, or at most `s` XOR pairs, in place of all `N` +entries. Dictionary operations have their usual expected constant lookup +cost. Integer arithmetic remains exact. A first use of a PR662 gate table +still takes `O(N)` work, and the final full output also takes `O(N)` work. +Each of the two retained table caches has at most 64 entries. + +This is a support-sensitive improvement. It is not a polynomial-size +stabilizer representation: the support can be all `N` indices. The benchmark +measures the complete selected dimension-nine phase command, including table +construction, source admission, parsing, lowering, checks and output writing. +It makes no claim about multiplication runtime or the full cold replay. diff --git a/research/t74-native-fast/vendor/accelerators/sparse_state.py b/research/t74-native-fast/vendor/accelerators/sparse_state.py new file mode 100644 index 0000000000..ca39f73494 --- /dev/null +++ b/research/t74-native-fast/vendor/accelerators/sparse_state.py @@ -0,0 +1,65 @@ +"""Evaluate exact Clifford states on their nonzero support. + +Gate tables are from Charles Bethin's PR662. The support update is new. +Prepared for Ali Romman with substantial OpenAI Codex assistance. +Apache-2.0. +""" + + +def zero_state(op, tables, basis=0): + """Return every Gaussian numerator and the power-of-two denominator.""" + size = 1 << op.n + if not 0 <= basis < size: + raise IndexError(basis) + state = {basis: (1, 0)} + den = 0 + for gate in op.circuit: + kind = gate[0] + if kind == 'P': + mapping = tables.permutation_table(op.n, tuple(gate[1])) + state = {mapping[x]: value for x, value in state.items()} + elif kind == 'X': + state = {x ^ gate[1]: value for x, value in state.items()} + elif kind in ('D', 'phase'): + phases = (tables.phase_table(op.n, tuple(gate[1]), tuple(gate[2])) + if kind == 'D' else None) + out = {} + for x, (a, b) in state.items(): + phase = phases[x] if phases is not None else gate[1] % 4 + if phase == 0: + out[x] = (a, b) + elif phase == 1: + out[x] = (-b, a) + elif phase == 2: + out[x] = (-a, -b) + else: + out[x] = (b, -a) + state = out + elif kind == 'C': + q, sign = gate[1:] + out = {} + for x, (a, b) in state.items(): + y = x ^ q + if y < x and y in state: + continue + c, d = state.get(y, (0, 0)) + first = (a - sign*b + c + sign*d, + b + sign*a + d - sign*c) + second = (c - sign*d + a + sign*b, + d + sign*c + b - sign*a) + if first != (0, 0): + out[x] = first + if second != (0, 0): + out[y] = second + state = out + den += 1 + while den and all((a & 1) == (b & 1) == 0 + for a, b in state.values()): + state = {x: (a // 2, b // 2) for x, (a, b) in state.items()} + den -= 1 + else: + raise AssertionError(gate) + vec = [(0, 0)] * size + for x, value in state.items(): + vec[x] = value + return vec, den diff --git a/research/t74-native-fast/vendor/accelerators/tables.py b/research/t74-native-fast/vendor/accelerators/tables.py new file mode 100644 index 0000000000..5d546d8a05 --- /dev/null +++ b/research/t74-native-fast/vendor/accelerators/tables.py @@ -0,0 +1,82 @@ +"""Exact Gaussian-dyadic state evaluation with bounded, state-free gate tables. + +Charles Bethin, with substantial OpenAI Codex assistance. Apache-2.0. +The gate semantics and normalization follow the pinned clifford_exact.py. +""" +from functools import lru_cache + + +@lru_cache(maxsize=64) +def permutation_table(n, rows): + """Compute Gx from G(x xor lowbit(x)) xor G(lowbit(x)).""" + columns = [sum(((row >> j) & 1) << i for i, row in enumerate(rows)) + for j in range(n)] + table = [0] * (1 << n) + for x in range(1, len(table)): + bit = x & -x + table[x] = table[x ^ bit] ^ columns[bit.bit_length() - 1] + return tuple(table) + + +@lru_cache(maxsize=64) +def phase_table(n, rows, linear): + """Remove the lowest bit; all remaining quadratic partners have larger indices.""" + table = [0] * (1 << n) + for x in range(1, len(table)): + bit = x & -x + i, rest = bit.bit_length() - 1, x ^ bit + table[x] = (table[rest] + linear[i] + + 2 * ((rows[i] & rest).bit_count() & 1)) % 4 + return tuple(table) + + +def clear_caches(): + permutation_table.cache_clear() + phase_table.cache_clear() + + +def zero_state(self, basis=0): + """Drop-in evaluator for valid pinned Op circuits; return the full exact state.""" + size = 1 << self.n + vec = [(0, 0)] * size + vec[basis] = (1, 0) + den = 0 + for gate in self.circuit: + kind = gate[0] + if kind == 'P': + mapping = permutation_table(self.n, tuple(gate[1])) + out = [(0, 0)] * size + for x, value in enumerate(vec): + out[mapping[x]] = value + vec = out + elif kind == 'X': + vec = [vec[x ^ gate[1]] for x in range(size)] + elif kind in ('D', 'phase'): + phases = (phase_table(self.n, tuple(gate[1]), tuple(gate[2])) + if kind == 'D' else [gate[1] % 4] * size) + out = [] + for (a, b), phase in zip(vec, phases): + if phase == 0: + out.append((a, b)) + elif phase == 1: + out.append((-b, a)) + elif phase == 2: + out.append((-a, -b)) + else: + out.append((b, -a)) + vec = out + elif kind == 'C': + q, sign = gate[1:] + out = [] + for x, (a, b) in enumerate(vec): + c, d = vec[x ^ q] + out.append((a - sign*b + c + sign*d, + b + sign*a + d - sign*c)) + vec = out + den += 1 + else: + raise AssertionError(gate) + while den and all((a & 1) == (b & 1) == 0 for a, b in vec): + vec = [(a // 2, b // 2) for a, b in vec] + den -= 1 + return vec, den diff --git a/research/t74-native-fast/vendor/native/new/code/borrow/NOTICE-PR2226.md b/research/t74-native-fast/vendor/native/new/code/borrow/NOTICE-PR2226.md new file mode 100644 index 0000000000..a14b299ef5 --- /dev/null +++ b/research/t74-native-fast/vendor/native/new/code/borrow/NOTICE-PR2226.md @@ -0,0 +1,21 @@ +# Credit: anticipatory dirty borrowing (PR2226) + +The construction realised by this native chain is **PR2226, "anticipatory dirty borrowing"**, by Cinna Davis +(@1337isnot1337), prepared with substantial OpenAI Codex assistance (Apache-2.0): the logical reference change +K_G of a lender register (a monomial Clifford: a permutation of the 512 columns with phase mod 4), the initial +compensation terms c K_G z, the early cold tail, the exact cold restoration and the private zero buffers of the +FULL-frame cleanup. `vendor/pr2226_operators.py`, `vendor/pr2226_replay.py` and `vendor/PR2226-NOTICE.md` are byte copies +of PR2226's `operators.py`, `replay.py` and `NOTICE.md`. `bw_gauss.py` is a port of `operators.py` (change, monomial, +apply_mono, coord, frame, check) and adds a decoder from a serialized `clifford_exact` monomial to its exact 512 x 512 +Gaussian matrix. + +What this chain adds (the P3 native realisation, with the borrowing work's explicit chronological BORROW-WORD as input): +warp events and zero buffers in `LOCAL-PROGRAMS`, warp recipes in `CLIFFORD-RECIPES.json` (lowered with the unchanged +`lower_child`, rank zero, then compared with the exact numpy column product), logical K_G recipes in +`RESIDUAL-ADAPTERS.json`, an independent local replay in both orientations that checks every warp product on all 512 +columns, and the negative controls listed in `INDEPENDENT-LOCAL-REPLAY.json`, `WRAPPER-CHECKS.json`, `WARP-RECIPE-CHECKS.json` +and `bw_tamper.py`. + +Lineage retained: icekylinx (PR425/433/514, scalar and wrapper machinery), DreamingOfClouds (PR458/484/593 hyperplane/cold-HPE +extensions), the clifford_exact compiler (vendor531), and the owners named in the package README. `vendor/clifford/clifford_exact.py` +is a byte copy. diff --git a/research/t74-native-fast/vendor/native/new/code/borrow/bw_adapters.py b/research/t74-native-fast/vendor/native/new/code/borrow/bw_adapters.py new file mode 100644 index 0000000000..82beaa9c1d --- /dev/null +++ b/research/t74-native-fast/vendor/native/new/code/borrow/bw_adapters.py @@ -0,0 +1,165 @@ +"""Paid residual wrappers for entering helpers (Lemma A): generation and independent decoding. Apache-2.0. +Prepared by DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. The wrapper construction follows PR #458 +(chafreaky): a helper that starts at frame E and ends at FULL has the physical residual S_E = T_FULL T_E^-1 (apply T_E^-1 first); +S_E = L_E (C_[w] x I) R_E with R_E applied first; the wrappers R_E^-1 before the whole local invocation and L_E^-1 after its +full-frame cleanup turn the residual into the coordinate factor C_[w] x I and restore the other 9 - w coordinates identically. +usage: adapters_gk.py CANONICAL-WORD.json.gz RESIDUAL-ADAPTERS.json OUT-LEMMA-A.json +Writes the recipes (generation uses clifford_exact.lower_child) and then DECODES the serialized monomials with the primitive +constructors of clifford_exact (not lower_child) and checks, for every entrance frame, that L_E^-1 S_E R_E^-1 has exactly the +tableau and zero-state vector (global phase included) of fourier(9, range(w)); mutated recipes (wrong phase, swapped sides, wrong +translation, wrong width) must be rejected.""" +if not __debug__: + raise RuntimeError('assertions must remain enabled') # every check of this stage is an assert +import copy, gzip, json, sys +from pathlib import Path +# Package-path adaptation only; the exact wrapper mathematics is unchanged. +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE / 'vendor/clifford')) # BW: the pinned vendor531 clifford_exact (byte copy) +sys.path.insert(0, str(HERE)) +from clifford_exact import canonical_frame, lower_child, fourier, diag, perm, xgate, Op, identity, transpose, inv, parity, monomial as mono_of, mv +import bw_gauss +n = 9; FULL = tuple(1 << i for i in range(n)) +def monomial_op(rec): + """decode a serialized monomial (matrix rows, quadratic rows, Z4 linear part, translation, phase)""" + out = diag(n, tuple(rec['quadratic_rows']), tuple(rec['linear_Z4'])).then(perm(n, tuple(rec['matrix_rows']))).then(xgate(n, rec['offset'])) + return out.then(Op(n, identity(n), [('phase', rec['phase'])])) +def S_of(U, END=FULL): + # HPE: a helper that starts at E=U and ends at END has residual T_END T_E^-1 (END = FULL is the inherited case) + return canonical_frame(n, tuple(U)).adjoint().then(canonical_frame(n, tuple(END))) +def wrapped_ok(U, rec, END=FULL): + """exactly: L^-1 S R^-1 = C_[w] x I (apply order: R^-1, S, L^-1), w = dim END - dim E""" + w = len(END) - len(U); S = S_of(U, END); Rm = monomial_op(rec['right']); Lm = monomial_op(rec['left']) + net = Rm.adjoint().then(S).then(Lm.adjoint()); target = fourier(n, range(w)) + return rec['rank'] == w and net.tab == target.tab and net.zero_state() == target.zero_state() +def _contains(a, b): + a = list(a) + for x in b: + for y in sorted(a, reverse=True): + if x >> (y.bit_length() - 1) & 1: x ^= y + if x: return False + return True +def Kop(G_cols): + """BW: K_G = perm(G) then diag(Q), Q = I + G^-T G^-1: PR2226's monomial() and the conjugator inside clifford_exact.canonical_frame.""" + G = transpose(tuple(G_cols), n); gi = inv(G, n) + Q = tuple((1 << i) ^ sum(parity(gi_i & gi_j) << j for j, gi_j in enumerate(transpose(gi, n))) for i, gi_i in enumerate(transpose(gi, n))) + return perm(n, G).then(diag(n, Q)) +def numeric_K(G_cols): + import numpy as np + pv, ph = bw_gauss.monomial(list(G_cols), n) + N = 1 << n; re = np.zeros((N, N), dtype=np.int64); im = np.zeros((N, N), dtype=np.int64) + unit = [(1, 0), (0, 1), (-1, 0), (0, -1)] + for x in range(N): re[pv[x], x], im[pv[x], x] = unit[ph[x]] + return re, im, 0 +def warp_ok(G_cols, rec): + """BW: the serialized monomial equals PR2226's exact numpy K_G on all 512 columns (indep. decode) and its op decodes to K_G exactly.""" + m = bw_gauss.recipe_matrix(rec, n) + if not bw_gauss.equal_scaled(numeric_K(G_cols), m): return False + dec = monomial_op(rec); ref = Kop(G_cols) + return dec.tab == ref.tab and dec.zero_state() == ref.zero_state() + +def main(): + c = json.load(gzip.open(sys.argv[1])); frames = c['frames']; v = c['v'] + starts = sorted({c['start'][r] for r in range(2 * v, len(c['start'])) if c['start'][r] != 0 and c['final'][r] == 1}) + # HPE: (entrance, terminal) pairs of helpers ending at a proper subspace; key 'E:U'. Inherited words have none. + ends = sorted({(c['start'][r], c['final'][r]) for r in range(2 * v, len(c['start'])) if c['final'][r] != 1}) + # COLD-HPE: e == 0 (a cold helper, entrance = bottom, T_0 = I) is allowed: the (0, U) recipe is keyed '0:U' + assert all(len(frames[u]) < n and _contains(frames[u], frames[e]) for e, u in ends) + cold_ends = [(e, u) for e, u in ends if e == 0] + recipes = {} + for f in starts: + U = frames[f]; rec, compiled = lower_child(S_of(U)) + recipes[str(f)] = dict(frame=f, vectors=list(U), entrance_rank=len(U), rank=rec['rank'], left=rec['left'], right=rec['right']) + for e, u in ends: + E, U = frames[e], frames[u]; rec, compiled = lower_child(S_of(E, U)) + recipes['%d:%d' % (e, u)] = dict(frame=e, terminal=u, vectors=list(E), terminal_vectors=list(U), entrance_rank=len(E), + terminal_rank=len(U), rank=rec['rank'], left=rec['left'], right=rec['right']) + # BW: monomial recipes of the warps K_G (anticipatory dirty borrowing, PR2226): one per operator, serialized like a wrapper monomial + warp_recipes = {} + for w in c.get('warps', []): + _, rec_k = mono_of(Kop(w['G_columns'])) + warp_recipes[str(w['op'])] = dict(op=w['op'], from_frame=w['from_frame'], to_frame=w['to_frame'], G_columns=list(w['G_columns']), K=rec_k) + Path(sys.argv[2]).write_text(json.dumps(dict(status='RESIDUAL_ADAPTER_RECIPES', recipes=recipes, warps=warp_recipes), sort_keys=True, separators=(',', ':')) + '\n') + # ---- independent decode of the serialized file + data_all = json.loads(Path(sys.argv[2]).read_text()); data = data_all['recipes'] + dot = lambda a, b: bin(a & b).count('1') & 1 + detail = [] + for f in starts: + rec = data[str(f)]; U = frames[f] + assert wrapped_ok(U, rec), ('wrapper product is not C_[w] x I', f) + detail.append(dict(frame=f, entrance_rank=len(U), residual_width=n - len(U), vectors=list(U), all_even_weight=all(bin(x).count('1') % 2 == 0 for x in U), + totally_isotropic=all(dot(a, b) == 0 for a in U for b in U))) + hdetail = [] + for e, u in ends: # HPE: independent decode, residual width = dim U - dim E + rec = data['%d:%d' % (e, u)]; E, U = frames[e], frames[u] + assert wrapped_ok(E, rec, U), ('HPE wrapper product is not C_[w] x I', e, u) + hdetail.append(dict(frame=e, terminal=u, entrance_rank=len(E), terminal_rank=len(U), residual_width=len(U) - len(E))) + controls = [] + def reject(name, fn): + f = starts[0]; rec = copy.deepcopy(data[str(f)]); fn(rec) + if wrapped_ok(frames[f], rec): raise AssertionError('mutated wrapper accepted: ' + name) + controls.append(name) + reject('wrong global phase', lambda r: r['right'].__setitem__('phase', (r['right']['phase'] + 1) % 4)) + reject('wrong translation', lambda r: r['left'].__setitem__('offset', r['left']['offset'] ^ 1)) + reject('wrong quadratic form', lambda r: r['right'].__setitem__('quadratic_rows', [x ^ 2 if i == 0 else x for i, x in enumerate(r['right']['quadratic_rows'])]) if False else r['right']['linear_Z4'].__setitem__(0, (r['right']['linear_Z4'][0] + 2) % 4)) + reject('sides swapped', lambda r: (r.__setitem__('left', r['right']), r.__setitem__('right', r['left']))) + reject('wrong width', lambda r: r.__setitem__('rank', r['rank'] + 1)) + if ends: # HPE controls on the first (E, U) pair + e, u = next((p for p in ends if p[0] != 0), ends[0]); rec0 = data['%d:%d' % (e, u)] # COLD-HPE: an entering pair if any (= ends[0] without cold ends) + def hreject(name, ok): + if ok: raise AssertionError('HPE mutation accepted: ' + name) + controls.append(name) + hreject('hpe: U-wrapper decoded against a FULL ending', wrapped_ok(frames[e], rec0)) + hreject('hpe: width misreported as 9 - dim E', wrapped_ok(frames[e], dict(rec0, rank=n - len(frames[e])), frames[u])) + other = next(f for f in range(len(frames)) if f != u and len(frames[f]) == len(frames[u]) and _contains(frames[f], frames[e])) + hreject('hpe: wrong terminal hyperplane', wrapped_ok(frames[e], rec0, frames[other])) + fe = next(((e2, u2) for e2, u2 in ends if str(e2) in data), None) + if fe: # an entrance shared with FULL-ended helpers: R_{E,FULL} must not serve as R_{E,U} + r2 = data['%d:%d' % fe] + hreject('hpe: pre wrapper resolved to the FULL recipe R_{E,FULL}', wrapped_ok(frames[fe[0]], dict(r2, right=data[str(fe[0])]['right']), frames[fe[1]])) + hreject('hpe: wrong global phase', wrapped_ok(frames[e], dict(rec0, left=dict(rec0['left'], phase=(rec0['left']['phase'] + 1) % 4)), frames[u])) + if cold_ends: # COLD-HPE controls on the first cold pair (0, U): factor_iff_pre says only R_{0,U} itself may precede + e, u = cold_ends[0]; recc = data['%d:%d' % (e, u)]; E, U = frames[e], frames[u] + ID = dict(matrix_rows=[1 << i for i in range(n)], offset=0, quadratic_rows=[0] * n, linear_Z4=[0] * n, phase=0) + assert monomial_op(ID).tab == identity(n) # the control's wrapper really is the identity + def creject(name, ok): + if ok: raise AssertionError('cold HPE mutation accepted: ' + name) + controls.append(name) + creject('cold hpe: identity pre wrapper instead of R_{0,U}', wrapped_ok(E, dict(recc, right=ID), U)) + creject('cold hpe: identity post wrapper instead of L_{0,U}', wrapped_ok(E, dict(recc, left=ID), U)) + creject('cold hpe: no wrappers (cold FULL convention L = R = I)', wrapped_ok(E, dict(recc, left=ID, right=ID), U)) + creject('cold hpe: U-wrapper decoded against a FULL ending', wrapped_ok(E, recc)) + creject('cold hpe: width misreported as 9', wrapped_ok(E, dict(recc, rank=n), U)) + other = next(f for f in range(len(frames)) if f != u and len(frames[f]) == len(frames[u])) + creject('cold hpe: wrong terminal hyperplane', wrapped_ok(E, recc, frames[other])) + creject('cold hpe: wrong global phase', wrapped_ok(E, dict(recc, right=dict(recc['right'], phase=(recc['right']['phase'] + 1) % 4)), U)) + ent = next((p for p in ends if p[0] != 0 and p[1] == u), None) + same = lambda x, y: monomial_op(x).tab == monomial_op(y).tab and monomial_op(x).zero_state() == monomial_op(y).zero_state() + if ent and not same(data['%d:%d' % ent]['right'], recc['right']): # an entering helper ending at the same U: its R_{E,U} must not serve as R_{0,U} + creject('cold hpe: pre wrapper resolved to an entering recipe R_{E,U}', wrapped_ok(E, dict(recc, right=data['%d:%d' % ent]['right']), U)) + wdetail = [] + for w in c.get('warps', []): # BW: independent decode of every warp recipe, then mutation controls on the first warp + rec = data_all['warps'][str(w['op'])] + assert rec['G_columns'] == w['G_columns'] + assert warp_ok(w['G_columns'], rec['K']), ('warp recipe differs from the exact monomial K_G', w['op']) + wdetail.append(dict(op=w['op'], from_frame=w['from_frame'], to_frame=w['to_frame'], columns_checked=1 << n)) + if c.get('warps'): + w0 = c['warps'][0]; k0 = data_all['warps'][str(w0['op'])]['K'] + def wreject(name, ok): + if ok: raise AssertionError('warp mutation accepted: ' + name) + controls.append(name) + wreject('warp: wrong global phase', warp_ok(w0['G_columns'], dict(k0, phase=(k0['phase'] + 1) % 4))) + wreject('warp: wrong translation', warp_ok(w0['G_columns'], dict(k0, offset=k0['offset'] ^ 1))) + wreject('warp: wrong linear phase', warp_ok(w0['G_columns'], dict(k0, linear_Z4=[(k0['linear_Z4'][0] + 2) % 4] + k0['linear_Z4'][1:]))) + wreject('warp: wrong quadratic form', warp_ok(w0['G_columns'], dict(k0, quadratic_rows=[k0['quadratic_rows'][0] ^ 2, k0['quadratic_rows'][1] ^ 1] + k0['quadratic_rows'][2:]))) + wreject('warp: recipe of another operator', warp_ok(w0['G_columns'], data_all['warps'][str(c['warps'][1]['op'])]['K'])) + wreject('warp: inverse recipe used as the warp', warp_ok(w0['G_columns'], mono_of(Kop(w0['G_columns']).adjoint())[1])) + G2 = list(w0['G_columns']); G2[0] ^= G2[1] + wreject('warp: wrong G (frame-changed column)', warp_ok(G2, k0)) + sing = list(w0['G_columns']); sing[1] = sing[0] + try: Kop(sing); raise SystemExit('non-invertible G accepted') + except (AssertionError, StopIteration, ValueError): controls.append('warp: non-invertible G') + res = dict(status='PASS_RESIDUAL_WRAPPERS_ARE_EXACT', frames=len(detail), **({'hyperplane_end_pairs': hdetail} if ends else {}), **({'cold_hyperplane_end_pairs': len(cold_ends)} if cold_ends else {}), wrappers_reject=controls, all_even_weight=all(d['all_even_weight'] for d in detail), **({'warp_recipes_exact_on_all_512_columns': wdetail} if wdetail else {}), + all_totally_isotropic=all(d['totally_isotropic'] for d in detail), detail=detail) + Path(sys.argv[3]).write_text(json.dumps(res, indent=1) + '\n') + print('Lemma A (exact): L^-1 S_E R^-1 = C_[w] x I for', len(detail), 'entrance frames, global phase included;', len(controls), 'wrapper mutations rejected; all-even-weight:', res['all_even_weight']) +if __name__ == '__main__': main() diff --git a/research/t74-native-fast/vendor/native/new/code/borrow/bw_audit_local.py b/research/t74-native-fast/vendor/native/new/code/borrow/bw_audit_local.py new file mode 100644 index 0000000000..912a0c447c --- /dev/null +++ b/research/t74-native-fast/vendor/native/new/code/borrow/bw_audit_local.py @@ -0,0 +1,289 @@ +# Local independent replay of the attributed PR514 / PR433 checker (icekylinx with OpenAI Codex assistance), extended (BW) with +# monomial warps and private zero buffers for anticipatory dirty borrowing (PR2226, Cinna Davis @1337isnot1337, with OpenAI +# Codex assistance, Apache-2.0). The exact Gaussian column products below are a port of PR2226's operators.py (change / +# monomial / apply_mono / coord / frame / check); they use only numpy and share no code with the emitter or with the +# clifford_exact phase compiler. Every edit is marked "BW:". The complete inherited checker and its controls are retained. +if not __debug__: + raise RuntimeError('assertions must remain enabled') # every check of this stage is an assert +import copy,gzip,hashlib,json,sys,time +from collections import Counter +from fractions import Fraction as Q +from pathlib import Path +import numpy as np +sys.path.insert(0,str(Path(__file__).resolve().parent)) +OUT=Path(sys.argv[1]) +c=json.load(gzip.open(OUT/'CANONICAL-WORD.json.gz')) +ir={'local_programs':json.load(gzip.open(OUT/'LOCAL-PROGRAMS.json.gz'))} +v,R,h=c['v'],c['R'],c['h'];n=2*v+R;frames=c['frames'] +levels={int(t):f for t,f in c.get('target_levels',{}).items()} +entering=[r for r,f in enumerate(c['start']) if r>=2*v and f!=0] +plain={r for r in range(n) if r not in set(entering)} + +def contains(a,b): + for x in a: + for y in b: + if x>>(y.bit_length()-1)&1:x^=y + if x:return False + return True +hpe={r for r in range(2*v,n) if c['final'][r]!=1} +assert all(len(frames[c['final'][r]])0:assert sorted(lin(G,x) for x in span(U))==sorted(span(E)),'G does not carry the from frame onto the to frame' + else:assert sorted(lin(G,x) for x in span(E))==sorted(span(U)),'G^-1 does not carry the from frame onto the to frame' + z=warp_product(G,U,E,op,h,qmut) + fwd=check_mono(z) + bre,bim,bexp=z # inverse-transpose of a (scaled) unitary monomial is its entrywise conjugate + bwd=check_mono((bre,-bim,bexp)) + WARPCACHE[key]=(fwd,bwd);return WARPCACHE[key] +# --------------------------------------------------------------------------------------------------------------------------- +def add_row(row,src,q): + for j,x in src.items(): + z=row.get(j,Q(0))+q*x + if z:row[j]=z + else:row.pop(j,None) +def warp_row(row,op): + out={} + for (var,word),x in row.items(): + word=word[1:] if word and word[0]==-op else (op,)+word + out[var,word]=x + return out + +def local(events,back,table=None,qmut=None): + table=c['warps'] if table is None else table + G_of={w['op']:w['G_columns'] for w in table} + rows={('L',r):{(r,()):Q(1)} for r in range(n)} + norm={('L',r):Q(1) for r in range(n)};prefix=Q(1);cur=c['start'].copy();private={} + hist=Counter();phases=[];entry=[];exit=[];centers=[];chain={};wrappers=[] + wset=set(wrapped);pre_seen=set();post_seen=set();zlive=set();warp_hashes=[];nwarp=0 + allowed=['zero_frame_precondition','entry_adapters','A','centers','B']+(['cleanup_tail'] if c.get('tail') else [])+['final','exit_adapters','full_frame_cleanup','done'] + for event in events: + tag=event[0] + if tag=='phase': + phases.append(event[1]);assert phases==allowed[:len(phases)] + if event[1]=='A':assert entry==[(r,f) for r,f in enumerate(c['start']) if r in plain] and sorted(r for k_,r,f_ in wrappers if k_=='pre')==wrapped + if event[1]=='centers':assert all(cur[r]==levels.get(r-v,0) for r in range(v,2*v)) + if event[1]=='full_frame_cleanup':assert cur==c['final'] and exit==[(r,f) for r,f in enumerate(c['final']) if r not in hpe] + assert not private + elif tag=='residual_adapter': + _,kind,r,f,*end=event;assert r in wrapped and f==c['start'][r] and kind in ('pre','post') + assert end==([c['final'][r]] if r in hpe else []) + if end and kind=='post':assert cur[r]==end[0] + assert (kind=='pre' and phases[-1]=='entry_adapters') or (kind=='post' and phases[-1]=='full_frame_cleanup') + assert (kind,r) not in {(k,x) for k,x,_ in wrappers};wrappers.append((kind,r,f)) + (pre_seen if kind=='pre' else post_seen).add(r) + elif tag=='adapter': + assert event[3]==(c['start'] if event[1]=='old_to_new' else c['final'])[event[2]] + (entry if event[1]=='old_to_new' else exit).append((event[2],event[3])) + elif tag=='climb': + _,part,r,a,b,rank=event + assert not private and phases[-1]==part and cur[r]==a + assert contains(frames[a],frames[b]) and rank==len(frames[b])-len(frames[a])>0 + hist[rank]+=1;cur[r]=b + elif tag=='zero_buffer': # BW: private FULL-frame zero buffers of the cleanup; allocated empty, returned empty + _,kind,z=event;assert phases[-1]=='full_frame_cleanup' and z in zb + if kind=='alloc': + assert z not in zlive and ('Z',z) not in rows;zlive.add(z);rows['Z',z]={};norm['Z',z]=Q(0) + else: + assert kind=='free' and z in zlive and not rows['Z',z];zlive.remove(z) + elif tag=='warp': # BW: monomial logical reference change, rank zero, exact on all 512 columns + _,r,op,f0,f1=event;nwarp+=1 + assert op and abs(op) in G_of and phases[-1] in ('zero_frame_precondition','A','B','cleanup_tail','full_frame_cleanup') + assert not private + if r[0]=='L': + assert cur[r[1]]==f0,('warp frame mismatch',r,cur[r[1]],f0) + assert r[1] not in wset or (r[1] in pre_seen and r[1] not in post_seen),('warp wrapper order',r) + else: + assert r[0]=='Z' and r[1] in zlive and f0==f1==1 + assert len(frames[f0])==len(frames[f1]),'a warp is rank zero: equal dimensions' + warp_hashes.append(warp_columns(op,f0,f1,G_of[abs(op)],qmut)) + rows[tuple(r)]=warp_row(rows[tuple(r)],op) + if r[0]=='L':cur[r[1]]=f1 + elif tag=='center': + _,k,a,b,rank=event + assert phases[-1]=='centers' and private=={('C',k):a} + cf=c['center_frames'][k];cr=len(frames[cf]) + assert contains(frames[a],frames[b]) if back else contains(frames[b],frames[a]) + assert rank==abs(len(frames[a])-len(frames[b]))>0 + chain.setdefault(k,[]).append((a,b)) + private['C',k]=b;hist[rank]+=1;centers.append(k) + elif tag=='scalar': + _,e,f=event;op=e[0];target=tuple(e[1]);source=tuple(e[2]) if op in ('copy','add') else None + if target[0]=='C' and op=='clear': + assert private.get(target,f)==f + private.pop(target,None) + else: + for r in (target,source): + if r is None:continue + if r[0]=='L':assert cur[r[1]]==f and (r[1] not in wset or (r[1] in pre_seen and r[1] not in post_seen)),('common frame / wrapper order',r,cur[r[1]],f) + elif r[0]=='Z': # BW: a zero buffer lives only inside the FULL-frame cleanup, at FULL + assert r[1] in zlive and f==1 and phases[-1]=='full_frame_cleanup',('zero buffer misuse',r) + else: + if r==target and r not in private:private[r]=f + assert private[r]==f + if op=='clear':rows[target]={};norm[target]=Q(0) + elif op=='copy':rows[target]=dict(rows[source]);norm[target]=norm[source] + elif op=='scale': + q=Q(e[2],e[3]);a,b=abs(q.numerator),q.denominator + assert a&(a-1)==0 and b&(b-1)==0 + rows[target]={j:q*x for j,x in rows[target].items()};norm[target]*=abs(q) + else: + q=Q(e[3],e[4]);a,b=abs(q.numerator),q.denominator + assert source!=target and b&(b-1)==0 + w=0 + for bit in bin(a)[2:]:w=2*w+int(bit) + assert Q(w,b)*(1 if q>0 else -1)==q + prefix=max(prefix,Q(a)*norm[source]) + norm[target]=norm.get(target,Q(0))+abs(q)*norm[source] + row=rows.setdefault(target,{}) + add_row(row,rows[source],q) + prefix=max(prefix,norm[target]) + else:raise AssertionError(tag) + assert phases==allowed and set(centers)==set(range(len(c['centers']))) and not private and not zlive + assert sorted(r for k,r,_ in wrappers if k=='pre')==wrapped and sorted(r for k,r,_ in wrappers if k=='post')==wrapped + for k,st in chain.items(): + cf=c['center_frames'][k] + if back:assert st[-1][1]==cf and all(st[i][1]==st[i+1][0] for i in range(len(st)-1)) + else:assert st[0][0]==cf and all(st[i][1]==st[i+1][0] for i in range(len(st)-1)) + assert all(not row for reg,row in rows.items() if reg[0] in 'CZ') + assert cur==c['final'] + for r in range(n): + expected={(r,()):Q(1)} + if back and r0)==(sign>0),start) +def cleanup_warp(es):return first_warp(es,-1,phase_at(es,'full_frame_cleanup')) +def incomplete_centre_descent(es): + # Split paths lose an intermediate step. An unsplit path is truncated at + # an actual nested rank-one frame, with its child rank repriced correctly. + # Thus the control cannot fail merely because a split no longer exists. + indices=[i for i,e in enumerate(es) if e[0]=='center' and e[3]!=0] + if indices: + es.pop(indices[0]);return + e=next(e for e in es if e[0]=='center') + stop=next(f for f in range(len(frames)) if len(frames[f])==1 and contains(frames[f],frames[e[2]])) + e[3]=stop;e[4]=len(frames[e[2]])-1 + +mutations=[ + ('wrong_scale',lambda es:next(e for e in es if e[0]=='scalar' and e[1][0]=='scale')[1].__setitem__(2,3)), + ('missing_center',lambda es:es.pop(next(i for i,e in enumerate(es) if e[0]=='center'))), + ('wrong_common_frame',lambda es:next(e for e in es if e[0]=='scalar' and e[2]!=0).__setitem__(2,0)), + ('wrong_child_rank',lambda es:next(e for e in es if e[0]=='climb').__setitem__(5,99)), +]+([ + ('missing_pre_wrapper',lambda es:es.pop(next(i for i,e in enumerate(es) if e[0]=='residual_adapter' and e[1]=='pre'))), + ('missing_post_wrapper',lambda es:es.pop(next(i for i,e in enumerate(es) if e[0]=='residual_adapter' and e[1]=='post'))), + ('wrapper_with_wrong_frame',lambda es:next(e for e in es if e[0]=='residual_adapter' and e[2] in entering).__setitem__(3,0)), + ('wrapper_in_wrong_phase',lambda es:es.insert(es.index(['phase','A']),es.pop(next(i for i,e in enumerate(es) if e[0]=='residual_adapter' and e[1]=='post')))), + ('wrapper_on_a_data_register',lambda es:next(e for e in es if e[0]=='residual_adapter').__setitem__(2,3)), + ('wrapper_on_a_target_register',lambda es:next(e for e in es if e[0]=='residual_adapter').__setitem__(2,v+3)), + ('wrapper_on_a_centre_register',lambda es:next(e for e in es if e[0]=='residual_adapter').__setitem__(2,['C',0])), +] if entering else [])+([ + ('centre_step_not_nested',lambda es:next(e for e in es if e[0]=='center').__setitem__(3,next(f for f in range(len(frames)) if not contains(frames[f],frames[next(e for e in es if e[0]=='center')[2]]) and not contains(frames[next(e for e in es if e[0]=='center')[2]],frames[f])))), + ('centre_descent_incomplete',incomplete_centre_descent), +] if levels else [])+([ + ('hpe_pre_wrapper_resolved_to_full_recipe',lambda es:next(e for e in es if e[0]=='residual_adapter' and e[1]=='pre' and len(e)==5).pop()), + ('hpe_post_wrapper_without_terminal_frame',lambda es:next(e for e in es if e[0]=='residual_adapter' and len(e)==5).pop()), + ('hpe_post_wrapper_wrong_terminal_frame',lambda es:next(e for e in es if e[0]=='residual_adapter' and len(e)==5).__setitem__(4,1)), + ('hpe_tail_gate_at_full_frame',lambda es:next(e for e in es[es.index(['phase','cleanup_tail']):] if e[0]=='scalar').__setitem__(2,1)), + ('hpe_tail_climb_dropped',lambda es:es.pop(next(i for i in range(es.index(['phase','cleanup_tail']),len(es)) if es[i][0]=='climb'))), + ('hpe_helper_exit_adapter_to_full',lambda es:es.insert(es.index(['phase','full_frame_cleanup']),['adapter','new_to_old',min(hpe),1])), + ('hpe_tail_gate_moved_into_full_cleanup',lambda es:(lambda x:(x.__setitem__(2,1),es.insert(es.index(['phase','full_frame_cleanup'])+1,x)))(es.pop(next(i for i in range(es.index(['phase','cleanup_tail']),len(es)) if es[i][0]=='scalar')))), +] if hpe else [])+([ + ('cold_hpe_pre_wrapper_replaced_by_identity_entry_adapter',lambda es:(lambda i:es.__setitem__(i,['adapter','old_to_new',cold[0],0]))(next(i for i,e in enumerate(es) if e[0]=='residual_adapter' and e[1]=='pre' and e[2]==cold[0]))), + ('cold_hpe_pre_wrapper_dropped',lambda es:es.pop(next(i for i,e in enumerate(es) if e[0]=='residual_adapter' and e[1]=='pre' and e[2]==cold[0]))), + ('cold_hpe_post_wrapper_replaced_by_exit_adapter',lambda es:(lambda i:es.__setitem__(i,['adapter','new_to_old',cold[0],c['final'][cold[0]]]))(next(i for i,e in enumerate(es) if e[0]=='residual_adapter' and e[1]=='post' and e[2]==cold[0]))), + ('cold_hpe_pre_wrapper_resolved_to_cold_full_convention',lambda es:next(e for e in es if e[0]=='residual_adapter' and e[1]=='pre' and e[2]==cold[0]).pop()), + ('cold_hpe_wrapper_with_nonzero_entrance',lambda es:next(e for e in es if e[0]=='residual_adapter' and e[1]=='pre' and e[2]==cold[0]).__setitem__(3,1)), + ('cold_hpe_post_wrapper_wrong_terminal_frame',lambda es:next(e for e in es if e[0]=='residual_adapter' and e[1]=='post' and e[2]==cold[0]).__setitem__(4,1)), + ('cold_hpe_premix_gate_before_pre_wrapper',lambda es:(lambda ev:es.insert(next(i for i,e in enumerate(es) if e[0]=='residual_adapter' and e[1]=='pre' and e[2]==cold[0]),ev))(es.pop(next(i for i,e in enumerate(es) if e[0]=='scalar' and (('L',cold[0]) in [tuple(e[1][1])]+([tuple(e[1][2])] if e[1][0] in ('add','copy') else []))))) ), +] if cold else []) +# BW: mutations of the warp / zero-buffer events (each must be rejected by the literal replay) +if c.get('warps'): + def other_frame(es,i): # a frame of the same dimension that is not the event's own to-frame + e=es[i];return next(f for f in range(len(frames)) if f not in (e[3],e[4]) and len(frames[f])==len(frames[e[4]]) and f!=0) + mutations+=[ + ('warp_missing_inverse_at_full_cleanup',lambda es:es.pop(cleanup_warp(es))), + ('warp_missing_forward',lambda es:es.pop(first_warp(es,1,phase_at(es,'B')))), + ('warp_frame_mismatch',lambda es:(lambda i:es[i].__setitem__(3,other_frame(es,i)))(first_warp(es,1,phase_at(es,'B')))), + ('warp_to_frame_not_carried_by_G',lambda es:(lambda i:es[i].__setitem__(4,other_frame(es,i)))(first_warp(es,1,phase_at(es,'B')))), + ('warp_wrong_sign',lambda es:(lambda i:es[i].__setitem__(2,-es[i][2]))(first_warp(es,1,phase_at(es,'B')))), + ('warp_wrong_operator',lambda es:(lambda i:es[i].__setitem__(2,es[i][2]%len(c['warps'])+1))(first_warp(es,1,phase_at(es,'B')))), + ('warp_inverse_moved_before_use',lambda es:es.insert(first_warp(es,1,phase_at(es,'B')),es.pop(cleanup_warp(es)))), + ('warp_inverse_wrong_frame',lambda es:es[cleanup_warp(es)].__setitem__(3,0)), + ('warp_rank_changing',lambda es:(lambda i:es[i].__setitem__(4,0))(first_warp(es,1,phase_at(es,'B')))), + ('warp_phase_B_dropped_gate_after_warp',lambda es:es.pop(ev_index(es,lambda e:e[0]=='scalar',first_warp(es,1,phase_at(es,'B'))))), + ] +if zb: + mutations+=[ + ('zero_buffer_not_freed',lambda es:es.pop(ev_index(es,lambda e:e[0]=='zero_buffer' and e[1]=='free'))), + ('zero_buffer_gate_outside_cleanup',lambda es:es.insert(phase_at(es,'full_frame_cleanup')-1,['scalar',['add',['Z',zb[0]],['L',0],1,1],1])), + ('zero_buffer_garbage_left',lambda es:es.pop(ev_index(es,lambda e:e[0]=='scalar' and e[1][0]=='add' and e[1][1]==['Z',zb[0]] ,phase_at(es,'full_frame_cleanup')))), + ] +def mutate_gate_to_L(es): + i=ev_index(es,lambda e:e[0]=='scalar' and ['Z',zb[0]] in [e[1][1]]+([e[1][2]] if e[1][0]=='add' else []),phase_at(es,'full_frame_cleanup')) + g=es[i][1];es[i][1]=[g[0]]+[(['L',zb[0]] if x==['Z',zb[0]] else x) for x in g[1:3]]+list(g[3:]) +if zb: + mutations.append(('zero_buffer_replaced_by_restored_register_at_full',mutate_gate_to_L)) +for name,mut in mutations: + es=copy.deepcopy(ir['local_programs']['forward']);mut(es) # a mutation that cannot be built is an error, not a rejection + try:local(es,False) + except (AssertionError,KeyError) as exc:controls.append(name);reasons[name]=repr(exc.args)[:160] + else:raise AssertionError('mutation accepted: '+name) +# BW: table / operator tampering of the warps themselves +def tampered(name,table_fn,qmut=None): + t=copy.deepcopy(c['warps']);table_fn(t) + try:local(ir['local_programs']['forward'],False,table=t,qmut=qmut) + except (AssertionError,KeyError) as exc:controls.append(name);reasons[name]=repr(exc.args)[:160] + else:raise AssertionError('tampered warp operator accepted: '+name) +if c.get('warps'): + def wrongG(t): + U=frames[t[0]['from_frame']];E=frames[t[0]['to_frame']] + G=list(t[0]['G_columns']);outside=next(x for x in range(1,1<0 else -1,abs(e[2]),e[3],e[4])) +assert used==set(map(tuple,c.get('warp_edges',[]))),'emitted warp classes differ from the word' +by={(w['sign'],w['op'],w['old'],w['new']):w for w in rec_all.get('warps',[])} +assert set(by)==used,('recipe classes differ from the emitted warp classes',len(set(by)^used)) +def numeric_K(G): + pv,ph=g.monomial(list(G),h);N=1<0 and k[2]!=k[3]);w=by[key];sign,op,f0,f1=key;left=w['left'];Gx=G_of[op] + reject('recipe: wrong global phase',product_ok(*key,dict(left,phase=(left['phase']+1)%4))) + reject('recipe: wrong translation',product_ok(*key,dict(left,offset=left['offset']^1))) + reject('recipe: wrong linear phase',product_ok(*key,dict(left,linear_Z4=[(left['linear_Z4'][0]+2)%4]+left['linear_Z4'][1:]))) + reject('recipe: wrong quadratic form',product_ok(*key,dict(left,quadratic_rows=[left['quadratic_rows'][0]^2,left['quadratic_rows'][1]^1]+left['quadratic_rows'][2:]))) + reject('recipe: wrong matrix',product_ok(*key,dict(left,matrix_rows=[left['matrix_rows'][1],left['matrix_rows'][0]]+left['matrix_rows'][2:]))) + G2=list(Gx);G2[0]^=G2[1] + reject('recipe: wrong G (still invertible)',product_ok(*key,left,G=G2)) + sing=list(Gx);sing[1]=sing[0] + reject('recipe: non-invertible G',product_ok(*key,left,G=sing)) + reject('recipe: inverse warp recipe used for the forward warp',product_ok(sign,op,f0,f1,next(x for k,x in by.items() if k[0]==-sign and k[1]==op)['left']) if any(k[0]==-sign and k[1]==op for k in by) else False) + # frame mismatch: the recipe of this class used for a class with another frame + other=next((k for k in by if k!=key and k[0]==sign and k[1]!=op),None) + reject('recipe: recipe of another warp class',product_ok(*key,by[other]['left']) if other else False) + reject('recipe: swapped from/to frames',product_ok(sign,op,f1,f0,left)) + # a class missing from the recipe file + try: + miss=copy.copy(by);miss.pop(key);assert set(miss)==used + except AssertionError:controls.append('recipe: missing warp class') + else:raise AssertionError('missing class accepted') + reject('logical: wrong G',logical_ok(op,res_all['warps'][str(op)]['K'],G=G2)) + reject('logical: wrong phase',logical_ok(op,dict(res_all['warps'][str(op)]['K'],phase=(res_all['warps'][str(op)]['K']['phase']+1)%4))) +out=dict(status='PASS_WARP_RECIPES_EXACT_ON_ALL_512_COLUMNS',canonical_word_sha256=hashlib.sha256((OUT/'CANONICAL-WORD.json.gz').read_bytes()).hexdigest(), + recipe_sha256=hashlib.sha256((OUT/'CLIFFORD-RECIPES.json').read_bytes()).hexdigest(),warp_classes=len(by),operators=len(c.get('warps',[])), + columns_each=1< 0, G^-1(f0) = f1 for op < 0). The same event stream serves both orientations: +the inverse-transpose of a monomial K_G is the monomial conj(K_G) (same permutation, conjugated phases), a different +formal symbol of the free operator algebra, and the exact column check of the physical product is run for both. +""" +if not __debug__: + raise RuntimeError('assertions must remain enabled') # every check of this stage is an assert +import sys as _sys, os as _os; _sys.path.insert(0, _os.path.dirname(_os.path.abspath(__file__))) +import gzip,hashlib,json +from collections import Counter +from fractions import Fraction as Q +from pathlib import Path + +OUT=Path(_sys.argv[1]);cp=OUT/'CANONICAL-WORD.json.gz' +c=json.load(gzip.open(cp)) +frames=c['frames'];v,R,h=c['v'],c['R'],c['h'];n=2*v+R +def digest(x):return hashlib.sha256(json.dumps(x,sort_keys=True,separators=(',',':')).encode()).hexdigest() +def basis(vs): + b={} + for x in vs: + for p in sorted(b,reverse=True): + if x>>p&1:x^=b[p] + if x: + p=x.bit_length()-1 + for q in b: + if b[q]>>p&1:b[q]^=x + b[p]=x + return tuple(b[p] for p in sorted(b,reverse=True)) +def reg(x):return list(x) if isinstance(x,list) else ['L',x] # BW: ['Z', c] is a private zero buffer +def dual(e): + e=list(e) + if e[0]=='add':e[1],e[2]=e[2],e[1];e[3]*=-1 + else:e[2],e[3]=e[3],e[2] + return e +def scalar(e,back): + e=dual(e) if back else list(e) + if e[0]=='add':return ['add',reg(e[1]),reg(e[2]),e[3],e[4]] + return ['scale',reg(e[1]),e[2],e[3]] +def primitive_bound(e): + if e[0] in ('clear','copy'):return 1 + q=Q(e[3],e[4]) if e[0]=='add' else Q(e[2],e[3]) + a,b=abs(q.numerator),q.denominator + assert b&(b-1)==0 + if e[0]=='scale': + assert a&(a-1)==0 + return abs(a.bit_length()-b.bit_length())+int(q<0) + return 3+(a.bit_length()-1)+a.bit_count()+(b.bit_length()-1) +def lregs(e):return [r for r in ([e[1]]+([e[2]] if e[0]=='add' else [])) if not isinstance(r,list)] + +def expand(e): + """BW: a twisted addition t += c*W(s) at frame zero: warp s by W, add, unwarp (all rank zero at frame 0).""" + if e[0]!='tadd':return [e] + _,t,s,word,a,b,f=e + return [['warp',s,op,0,0] for op in reversed(word)]+[['add',t,s,a,b,0]]+[['warp',s,-op,0,0] for op in word] + +def emit(back): + out=[];cur=c['start'].copy() + def event(e):out.append(e) + def scal(e,f):event(['scalar',e,f]) + def warp(e): + _,r,op,f0,f1=e + if isinstance(r,list):assert r[0]=='Z' and f0==f1==1 + else: + assert cur[r]==f0,('warp frame mismatch',r,cur[r],f0);cur[r]=f1 + event(['warp',reg(r),op,f0,f1]) + event(['phase','zero_frame_precondition']) + for e0 in c['precondition']+c['compensation']: + for e in expand(e0): + if e[0]=='warp':warp(e);continue + regs=lregs(e) + assert all(c['start'][r]==0 for r in regs) + scal(scalar(e,back),0) + event(['phase','entry_adapters']) + entering=[r for r,f in enumerate(c['start']) if r>=2*v and f!=0] + hpe={r for r in range(2*v,n) if c['final'][r]!=1} + wrapped=sorted(set(entering)|hpe) + for r,f in enumerate(c['start']): + if r in wrapped:event(['residual_adapter','pre',r,f]+([c['final'][r]] if c['final'][r]!=1 else [])) + else:event(['adapter','old_to_new',r,f]) + def climb(r,f,part): + old=cur[r] + if old==f:return + assert basis(frames[old]+frames[f])==tuple(frames[f]) + rank=len(frames[f])-len(frames[old]);assert rank>0 + event(['climb',part,r,old,f,rank]);cur[r]=f + for part in ('A','centers','B')+(('cleanup_tail',) if c.get('tail') else ())+('final',): + event(['phase',part]) + if part in ('A','B','cleanup_tail'): + for e in (c['tail'] if part=='cleanup_tail' else c[part]): + if e[0]=='warp':warp(e);continue # BW: monomial reference change, no climb + for r in lregs(e):climb(r,e[-1],part) + scal(scalar(e,back),e[-1]) + elif part=='centers': + lv=lambda r:c.get('target_levels',{}).get(str(r-v),0) + assert all(cur[r]==lv(r) for r in range(v,2*v)) + for k,r in enumerate(c['centers']): + cf=c['center_frames'][k];assert cur[r]==cf + terms=[e for e in c['cut'] if e[2]==r] + path=[cf]+sorted({lv(e[1]) for e in terms}-{cf},key=lambda x:-len(frames[x])) + C=['C',k] + if not back: + scal(['clear',C],cf);scal(['copy',C,['L',r]],cf) + for a in range(len(path)): + if a>0:event(['center',k,path[a-1],path[a],len(frames[path[a-1]])-len(frames[path[a]])]) + for e in terms: + if lv(e[1])==path[a]:scal(['add',['L',e[1]],C,e[3],e[4]],path[a]) + scal(['clear',C],path[-1]) + else: + scal(['clear',C],path[-1]) + for a in range(len(path)-1,-1,-1): + for e in terms: + if lv(e[1])==path[a]:scal(['add',C,['L',e[1]],e[3],e[4]],path[a]) + if a>0:event(['center',k,path[a],path[a-1],len(frames[path[a-1]])-len(frames[path[a]])]) + scal(['add',['L',r],C,-1,1],cf);scal(['clear',C],cf) + else: + for r,f in enumerate(c['final']):climb(r,f,part) + event(['phase','exit_adapters']) + for r,f in enumerate(c['final']): + if r not in hpe:event(['adapter','new_to_old',r,f]) + event(['phase','full_frame_cleanup']) + zb=c.get('zero_buffers',[]) + for z in zb:event(['zero_buffer','alloc',z]) # BW: private FULL-frame zero buffers stand in for the restored (hyperplane-ended) helpers + for e in c['cleanup']: + if e[0]=='warp':warp(e);continue + regs=lregs(e) + assert all(c['final'][r]==1 for r in regs) + assert all(r[0]=='Z' and r[1] in zb for r in [e[1]]+([e[2]] if e[0]=='add' else []) if isinstance(r,list)) + scal(scalar(e,back),1) + for z in zb:event(['zero_buffer','free',z]) + for r in wrapped:event(['residual_adapter','post',r,c['start'][r]]+([c['final'][r]] if r in hpe else [])) + event(['phase','done']) + return out + +def add_row(dst,src,q): + for j,x in src.items(): + z=dst.get(j,Q(0))+q*x + if z:dst[j]=z + else:dst.pop(j,None) +def warp_row(row,op): + out={} + for (var,word),x in row.items(): + word=word[1:] if word and word[0]==-op else (op,)+word + out[var,word]=x + return out + +def check_local(events,back): + # BW: literal scalar replay of the emitted stream in the free warp algebra (rows over (register, warp word)), centres and zero buffers. + state={('L',r):{(r,()):Q(1)} for r in range(n)};live=[];paid=Counter();prims=0;macros=0;zlive=set();nwarp=0 + for e in events: + if e[0]=='climb':assert not live;paid[e[5]]+=1 + elif e[0]=='center':assert live==[e[1]];paid[e[4]]+=1 + elif e[0]=='zero_buffer': + z=e[2] + if e[1]=='alloc':assert z not in zlive;zlive.add(z);state['Z',z]={} + else:assert not state['Z',z] and z in zlive;zlive.remove(z) + elif e[0]=='warp': + t=tuple(e[1]);nwarp+=1;state[t]=warp_row(state[t],e[2]) + elif e[0]=='scalar': + op=e[1];tag=op[0];t=tuple(op[1]);macros+=1;prims+=2*primitive_bound(op) + if tag=='clear': + state[t]={} + if t[0]=='C' and t[1] in live:live.remove(t[1]) + elif tag=='copy':state[t]={(var,w):x for (var,w),x in state.get(tuple(op[2]),{}).items()};live.append(t[1]) + elif tag=='scale':state[t]={j:Q(op[2],op[3])*x for j,x in state[t].items()} + else: + s=tuple(op[2]);q=Q(op[3],op[4]);row=state.setdefault(t,{}) + if t[0]=='C' and t[1] not in live:live.append(t[1]) + add_row(row,state.get(s,{}),q) + assert not live and not zlive and all(not row for r,row in state.items() if r[0] in 'CZ') + for r in range(n): + expected={(r,()):Q(1)} + if back and r>i&1:out^=col + return out +def f2rank(xs): + b={} + for x in xs: + while x: + i=x.bit_length() + if i not in b:b[i]=x;break + x^=b[i] + return len(b) +def extend(xs,hh): + out=list(xs) + for i in range(hh): + if f2rank(out+[1<len(out):out.append(1<>i)&1)<>i&1)==(M[i]>>j&1) for i in range(hh) for j in range(hh)) + permv=np.array([lin(cols,x) for x in range(1<>i)&1)*(x>>i&1) for i in range(hh))+ + 2*sum(((M[j]>>i)&1)*(x>>i&1)*(x>>j&1) for i in range(hh) for j in range(i+1,hh)) + for x in permv],dtype=np.int64)%4 + return permv,phase +def apply_mono(z,recipe,sign=1): + re,im,exp=z;perm,phase=recipe;rr=np.empty_like(re);ii=np.empty_like(im) + if sign==1: + for p in range(4): + mask=phase==p;r=re[mask];i=im[mask] + if p==0:a,b=r,i + elif p==1:a,b=-i,r + elif p==2:a,b=-r,-i + else:a,b=i,-r + rr[perm[mask]]=a;ii[perm[mask]]=b + else: + r=re[perm];i=im[perm] + for p in range(4): + mask=phase==p + if p==0:a,b=r[mask],i[mask] + elif p==1:a,b=i[mask],-r[mask] + elif p==2:a,b=-r[mask],-i[mask] + else:a,b=-i[mask],r[mask] + rr[mask]=a;ii[mask]=b + return rr,ii,exp +def coord(z,axes,sign=1): + re,im,exp=z + for j in axes: + p=np.array([x for x in range(len(re)) if not(x>>j&1)]);q=p^(1<0 else -1);return frame(z,E,hh,1) +def recipe_matrix(rec,hh): + """Dense exact matrix (re, im, exp=0) of a serialized clifford_exact monomial (matrix_rows, quadratic_rows, linear_Z4, offset, phase): + |x> -> i^(qvalue(x)+phase) |G x ^ offset>, qvalue = sum alpha_i x_i + 2 sum_{i in x} parity((Q_i >> (i+1)) & (x >> (i+1))).""" + N=1<>i&1)+2*sum(((Q[i]>>(i+1))&(x>>(i+1))).bit_count()&1 for i in range(hh) if x>>i&1)+ph)%4 + re[y,x],im[y,x]=unit[q] + return re,im,0 +def equal_scaled(z,m): + """z (scaled by 2^exp) equals m (exp 0) entrywise exactly""" + re,im,exp=z;return bool(np.array_equal(re,m[0]<0 else K.adjoint() + op=ops[f0].adjoint().then(Ks).then(ops[f1]);rec,compiled=lower_child(op) + assert rec['rank']==0 and rec['right'] is None,('warp is not a monomial Clifford',sign,op_id,f0,f1) + Z=bw_gauss.warp_product(G,frames[f0],frames[f1],sign*op_id,n) + assert bw_gauss.equal_scaled(Z,bw_gauss.recipe_matrix(rec['left'],n)),('recipe differs from the exact column product',sign,op_id,f0,f1) + hist['warp']+=1;warps.append({'sign':sign,'op':op_id,'old':f0,'new':f1,'G_columns':G,**rec}) +raw=json.dumps({'children':recipes,'endpoint_adapters':adapters,'warps':warps},sort_keys=True,separators=(',',':')).encode() +(OUT/'CLIFFORD-RECIPES.json').write_bytes(raw) +result={'status':'PASS_NEW_WORD_EXACT_LOCAL_PHASE_RECIPES', + 'canonical_word_sha256':hashlib.sha256(P.read_bytes()).hexdigest(), + 'frames':len(frames),'directed_edges':len(edges),'ranks':{str(k):x for k,x in hist.items()}, + 'endpoint_adapters':len(adapters),'warp_recipes':len(warps),'warp_recipes_rank_zero':all(w['rank']==0 for w in warps), + 'warp_recipes_equal_exact_512_column_product':True, + 'all_child_equalities_include_global_phase':True, + 'recipe_sha256':hashlib.sha256(raw).hexdigest(),'seconds':time.monotonic()-start, + 'scope':'Every local frame, centre transition and warp. Expanded scalar-interface integration and global emitted program are separate obligations.'} +(OUT/'CLIFFORD-REVIEW.json').write_text(json.dumps(result,indent=2)+'\n') +print('PASS exact local phases',result['seconds'],'seconds',flush=True) diff --git a/research/t74-native-fast/vendor/native/new/code/borrow/bw_tamper.py b/research/t74-native-fast/vendor/native/new/code/borrow/bw_tamper.py new file mode 100644 index 0000000000..a519863fd8 --- /dev/null +++ b/research/t74-native-fast/vendor/native/new/code/borrow/bw_tamper.py @@ -0,0 +1,58 @@ +"""Tamper controls of the native borrow chain. Every tampered BORROW-WORD / emitted artifact must be REJECTED by the chain. +usage: bw_tamper.py BORROW-WORD.json.gz NATIVE_LOCAL_DIR WORK_DIR [--files] (--files also reruns the heavier file-level stages)""" +import copy,gzip,json,os,shutil,subprocess,sys,time +from pathlib import Path +HERE=Path(__file__).resolve().parent +word_path=Path(sys.argv[1]).resolve();local=Path(sys.argv[2]).resolve();work=Path(sys.argv[3]).resolve();work.mkdir(parents=True,exist_ok=True) +flags=(0x00000040|0x08000000) if os.name=='nt' and os.environ.get('BW_IDLE','1')=='1' else 0 +def run(script,*args): + p=subprocess.run([sys.executable,'-B',str(HERE/script),*map(str,args)],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,cwd=HERE,creationflags=flags) + return p.returncode,p.stdout.decode(errors='replace') +W=json.loads(gzip.decompress(word_path.read_bytes())) +results=[];t0=time.monotonic() +def word_tamper(name,fn,expect): + w=copy.deepcopy(W);fn(w);p=work/(name+'.json.gz');p.write_bytes(gzip.compress(json.dumps(w).encode())) + out=work/('out-'+name) + if out.exists():shutil.rmtree(out) + rc,log=run('bw_transport.py',p,out) + ok=rc!=0 and expect in log + results.append(dict(name=name,rejected=rc!=0,expected_reason=expect,reason_matches=expect in log,last_line=log.strip().splitlines()[-1][:200] if log.strip() else '')) + assert ok,(name,rc,log[-600:]) +def sw(g,i,j):g[i],g[j]=g[j],g[i] +first_cleanup_warp=lambda w:next(i for i,e in enumerate(w['cleanup']) if e[0]=='warp') +word_tamper('wrong_G_not_carrying_frame',lambda w:w['warps'][0].__setitem__(2,[w['warps'][0][2][0]^w['warps'][0][2][1]]+w['warps'][0][2][1:]),'G does not map the from frame onto the to frame') +word_tamper('non_invertible_G',lambda w:w['warps'][0][2].__setitem__(1,w['warps'][0][2][0]),'non-invertible G') +word_tamper('missing_inverse_warp_in_cleanup',lambda w:w['cleanup'].pop(first_cleanup_warp(w)),'arbitrary-input endpoint') +word_tamper('missing_forward_warp',lambda w:w['warps'].pop(0),'') +word_tamper('frame_mismatch_from_basis',lambda w:w['warps'][0].__setitem__(3,next(x[3] for x in w['warps'] if sorted(x[3])!=sorted(w['warps'][0][3]) and len(x[3])==len(w['warps'][0][3]))),'') +word_tamper('inverse_warp_sign_flipped',lambda w:w['cleanup'].__setitem__(first_cleanup_warp(w),['warp',w['cleanup'][first_cleanup_warp(w)][1],abs(w['cleanup'][first_cleanup_warp(w)][2]),w['cleanup'][first_cleanup_warp(w)][3]]),'arbitrary-input endpoint') +word_tamper('inverse_warp_wrong_operator',lambda w:w['cleanup'].__setitem__(first_cleanup_warp(w),['warp',w['cleanup'][first_cleanup_warp(w)][1],-(abs(w['cleanup'][first_cleanup_warp(w)][2])%len(w['warps'])+1),w['cleanup'][first_cleanup_warp(w)][3]]),'arbitrary-input endpoint') +word_tamper('inverse_warp_on_wrong_register',lambda w:w['cleanup'].__setitem__(first_cleanup_warp(w),['warp',(w['cleanup'][first_cleanup_warp(w)][1]+1)%(w['report']['v']*2),w['cleanup'][first_cleanup_warp(w)][2],w['cleanup'][first_cleanup_warp(w)][3]]),'arbitrary-input endpoint') +word_tamper('warp_moved_after_its_first_use',lambda w:w['warps'][0].__setitem__(0,w['warps'][0][0]+5),'') +if W['initial_corrections']: + word_tamper('initial_correction_sign_flipped',lambda w:w['initial_corrections'][0].__setitem__('coefficient',str(-__import__('fractions').Fraction(w['initial_corrections'][0]['coefficient']))),'arbitrary-input endpoint') + word_tamper('initial_correction_dropped',lambda w:w['initial_corrections'].pop(0),'arbitrary-input endpoint') + word_tamper('initial_correction_wrong_operator',lambda w:w['initial_corrections'][0].__setitem__('operator_word',[w['initial_corrections'][0]['operator_word'][0]%len(w['warps'])+1]),'arbitrary-input endpoint') +word_tamper('zero_buffer_gate_dropped',lambda w:w['cleanup'].pop(next(i for i,e in enumerate(w['cleanup']) if e[0]=='add' and e[1]>=2*w['report']['v']+w['report']['R'])),'arbitrary-input endpoint') +if '--files' in sys.argv: + def file_tamper(name,script,files,mutate,expect_fail=True): + d=work/('files-'+name) + if d.exists():shutil.rmtree(d) + shutil.copytree(local,d);mutate(d) + rc,log=run(script,d,*[]) if script!='bw_adapters.py' else run(script,d/'CANONICAL-WORD.json.gz',d/'RESIDUAL-ADAPTERS.json',d/'WRAPPER-CHECKS.json') + results.append(dict(name=name,rejected=rc!=0,last_line=log.strip().splitlines()[-1][:200] if log.strip() else ''));assert rc!=0,(name,log[-400:]) + def edit_json(path,fn,gz=False): + d=json.loads(gzip.decompress(path.read_bytes()) if gz else path.read_text());fn(d) + path.write_bytes(gzip.compress(json.dumps(d,sort_keys=True,separators=(',',':')).encode(),mtime=0) if gz else json.dumps(d,sort_keys=True,separators=(',',':')).encode()) + def recipe_phase(d):edit_json(d/'CLIFFORD-RECIPES.json',lambda r:next(x for x in r['warps'] if x['sign']>0 and x['old']!=x['new'])['left'].__setitem__('phase',(next(x for x in r['warps'] if x['sign']>0 and x['old']!=x['new'])['left']['phase']+1)%4)) + def recipe_drop_inverse(d):edit_json(d/'CLIFFORD-RECIPES.json',lambda r:r['warps'].pop(next(i for i,x in enumerate(r['warps']) if x['sign']<0))) + def recipe_swap_G(d):edit_json(d/'CLIFFORD-RECIPES.json',lambda r:next(x for x in r['warps'] if x['sign']>0).__setitem__('G_columns',next(x for x in r['warps'] if x['sign']>0)['G_columns'][::-1])) + def prog_drop_warp(d):edit_json(d/'LOCAL-PROGRAMS.json.gz',lambda p:p['forward'].pop(next(i for i,e in enumerate(p['forward']) if e[0]=='warp' and e[2]<0 and i>len(p['forward'])//2)),gz=True) + def prog_wrong_G(d):edit_json(d/'CANONICAL-WORD.json.gz',lambda c:c['warps'][0].__setitem__('G_columns',c['warps'][0]['G_columns'][::-1]),gz=True) + file_tamper('recipe_phase_tampered','bw_check_recipes.py',None,recipe_phase) + file_tamper('recipe_inverse_missing','bw_check_recipes.py',None,recipe_drop_inverse) + file_tamper('recipe_G_tampered','bw_check_recipes.py',None,recipe_swap_G) + file_tamper('program_missing_inverse_warp','bw_audit_local.py',None,prog_drop_warp) + file_tamper('word_G_reversed','bw_audit_local.py',None,prog_wrong_G) +(work/'TAMPER-RESULTS.json').write_text(json.dumps(dict(status='PASS_ALL_TAMPERS_REJECTED',tampers=results,seconds=time.monotonic()-t0),indent=1)+'\n') +print('PASS all',len(results),'tampers rejected in',round(time.monotonic()-t0,1),'s') diff --git a/research/t74-native-fast/vendor/native/new/code/borrow/bw_transport.py b/research/t74-native-fast/vendor/native/new/code/borrow/bw_transport.py new file mode 100644 index 0000000000..08248542b1 --- /dev/null +++ b/research/t74-native-fast/vendor/native/new/code/borrow/bw_transport.py @@ -0,0 +1,416 @@ +"""Transport an explicit BORROW-WORD to the native canonical frame-id form, with warps, and replay it exactly. + +Anticipatory dirty borrowing is the construction of PR2226 (Cinna Davis, @1337isnot1337, with OpenAI Codex +assistance; Apache-2.0): a retiring helper's register is lent to a later helper through a monomial Clifford +logical reference change K_G ("warp"), the retired field's value being replaced by K_G z. The explicit +chronological BORROW-WORD (canonical coordinates, literal frames, warps, cold restoration, inverse cleanup +with private zero buffers) is the builder output of the borrowing work (P1/P2). This script is the +transport stage of the native chain (the analogue of hpe_audit_and_transport.py): it never trusts the builder. +It replays the program in the free operator algebra generated by the warps over every arbitrary input, +in BOTH orientations (forward and inverse-transpose), checks every frame chain and the paid profile, compacts +the helper registers to R' = R - k, and writes the native CANONICAL-WORD. + +usage: bw_transport.py BORROW-WORD.json[.gz] OUT_DIR +""" +if not __debug__: + raise RuntimeError('assertions must remain enabled') # every check of this stage is an assert +import argparse +import copy +import gzip +import hashlib +import json +import sys +import time +from collections import Counter +from fractions import Fraction as Q +from pathlib import Path + + +def read(path): + data = path.read_bytes() + return json.loads(gzip.decompress(data) if path.suffix == '.gz' else data) + + +def basis(vs): + pivots = {} + for x in vs: + for k in sorted(pivots, reverse=True): + if x >> k & 1: + x ^= pivots[k] + if x: + k = x.bit_length() - 1 + for j in pivots: + if pivots[j] >> k & 1: + pivots[j] ^= x + pivots[k] = x + return tuple(pivots[k] for k in sorted(pivots, reverse=True)) + + +def span(b): + s = {0} + for x in b: + s |= {t ^ x for t in s} + return frozenset(s) + + +def rank_of(vs): + return len(basis(vs)) + + +def solve_G(cols, h): + """G given as images of e_i; returns (invertible?, image-of-subspace function).""" + def lin(x): + out = 0 + for i, c in enumerate(cols): + if x >> i & 1: + out ^= c + return out + return lin, rank_of(cols) == h + + +# ---- free operator algebra over the warps ------------------------------------------------------------------ +def add_row(dst, src, c): + for key, value in list(src.items()): + z = dst.get(key, Q(0)) + c * value + if z: + dst[key] = z + elif key in dst: + del dst[key] + + +def warp_row(row, op): + out = {} + for (var, word), value in row.items(): + word = word[1:] if word and word[0] == -op else (op,) + word + out[var, word] = value + return out + + +def is_dyadic(q): + return q.denominator & (q.denominator - 1) == 0 + + +def gate_regs(e): + if e[0] == 'add': + return [e[1], e[2]] + if e[0] == 'scale': + return [e[1]] + raise AssertionError(e[0]) + + +def dual(e): + e = list(e) + if e[0] == 'add': + e[1], e[2] = e[2], e[1] + e[3] = -e[3] + elif e[0] == 'scale': + e[2], e[3] = e[3], e[2] + return e + + +def apply_gate(e, rows, back): + if back: + e = dual(e) + if e[0] == 'scale': + q = Q(e[2], e[3]) + assert q + rows[e[1]] = {j: q * x for j, x in rows[e[1]].items()} + else: + assert e[1] != e[2] + add_row(rows[e[1]], rows[e[2]], Q(e[3], e[4])) + + +def run(word_path, out): + t0 = time.monotonic() + word = read(word_path) + assert word['kind'] == 'BORROW-WORD' + v, h, R0 = word['report']['v'], word['report']['h'], word['report']['R'] + assert h == 9 and v == 112 + n0 = 2 * v + R0 + removed = sorted(word['removed']) + assert all(2 * v <= r < n0 for r in removed) and len(set(removed)) == len(removed) + k = len(removed) + kept = [r for r in range(n0) if r not in set(removed)] + newid = {r: i for i, r in enumerate(kept)} + n = len(kept) + R = R0 - k + assert n == 2 * v + R + Zbase = n0 # builder convention: zero buffer of restored c is register n0 + c + ports = word['ports'] + assert len(set(ports)) == v + full = tuple(1 << i for i in range(h - 1, -1, -1)) + frames, frame_ids = [(), full], {(): 0, full: 1} + + def fid(vectors): + frame = basis(vectors) + if frame not in frame_ids: + frame_ids[frame] = len(frames) + frames.append(frame) + return frame_ids[frame] + + def R_(r): # register -> new register (int) or ['Z', c] + if isinstance(r, list): + return r + if r >= Zbase: + return ['Z', newid[r - Zbase]] + return newid[r] + + start = [fid([p]) for p in ports] + [0] * (v + R) + for r, frame in word['start_extra'].items(): + assert 2 * v <= int(r) < n0 and int(r) not in set(removed) + start[newid[int(r)]] = fid(frame) + final = [1] * v + [fid(x for x in range(1, 1 << h) if (x & p).bit_count() % 2 == 0) for p in ports] + [1] * R + helper_final = {} + for r, frame in word['helper_final'].items(): + assert 2 * v <= int(r) < n0 and int(r) not in set(removed) + helper_final[newid[int(r)]] = fid(frame) + final[newid[int(r)]] = helper_final[newid[int(r)]] + zero_buffers = sorted(helper_final) # every restored (hyperplane-ended) helper is replaced by a private zero buffer in the FULL cleanup + + def gate(e): + e = copy.deepcopy(e) + # Four-low lifted-target port (PR2436 mechanism): literal A-phase warp after the entry adapters. + if e[0] == 'warp': + assert len(e) == 5 + return ['warp', R_(e[1]), e[2], fid(e[3]), fid(e[4])] + if e[0] == 'add': + e[1], e[2] = R_(e[1]), R_(e[2]) + else: + e[1] = R_(e[1]) + e[-1] = None if e[-1] is None else fid(e[-1]) + return e + + # warps: operator table; op id = position + 1; G given by images of the basis vectors + warps = [] + for i, (pos, lender, G, frm, to) in enumerate(word['warps']): + warps.append({'op': i + 1, 'B_pos': pos, 'lender': newid[lender], 'G_columns': list(G), + 'from_frame': fid(frm), 'to_frame': fid(to)}) + byp = {} + for w_ in warps: + byp.setdefault(w_['B_pos'], []).append(w_) + + def warp_event(r, op, f0, f1): + return ['warp', r, op, f0, f1] + + # compensation (zero frame): initial corrections first, as twisted additions t += c * W(s) + pre = [] + for term in word['initial_corrections']: + q = Q(term['coefficient']) + pre.append(['tadd', newid[term['target']], newid[term['source']], list(term['operator_word']), + q.numerator, q.denominator, 0]) + precondition = pre + [gate(e) for e in word['precondition']] # the formal initial corrections come first (PR2226 order) + compensation = [gate(e) for e in word['compensation']] + A = [gate(e) for e in word['A']] + cut = [gate(e) for e in word['cut']] + B = [] + for p in range(len(word['B']) + 1): + for w_ in sorted(byp.get(p, []), key=lambda x: x['op']): + B.append(warp_event(w_['lender'], w_['op'], w_['from_frame'], w_['to_frame'])) + if p < len(word['B']): + B.append(gate(word['B'][p])) + assert sum(1 for e in B if e[0] == 'warp') == len(warps) + tail = [gate(e) for e in word['restore']] + cleanup = [] + for e in word['cleanup']: + if e[0] == 'warp': + cleanup.append(warp_event(R_(e[1]), e[2], 1, 1)) + assert basis(e[3]) == full + else: + cleanup.append(gate(e)) + centers = [newid[r] for r in word['centers']] + center_frames = [fid(f) for f in word['center_frames']] + levels = {str(t): fid(f) for t, f in word['target_levels'].items()} + + canonical = dict(h=h, v=v, R=R, ports=ports, frames=frames, start=start, final=final, + precondition=precondition, compensation=compensation, A=A, cut=cut, B=B, tail=tail, + cleanup=cleanup, centers=centers, center_frames=center_frames, target_levels=levels, + warps=warps, zero_buffers=zero_buffers, removed=removed, helper_origin=kept[2 * v:], + borrow=dict(k=k, base=word.get('base'), original_helpers=R0)) + # ---- exact scalar replay in the free algebra over the warps (both orientations) ----------------------------------- + nz = len(zero_buffers) + + def regkey(r): + return tuple(r) if isinstance(r, list) else ('L', r) + + def expand_tadd(e): + _, t, s, wordops, a, b, f = e + ev = [warp_event(s, op, 0, 0) for op in reversed(wordops)] + ev.append(['add', t, s, a, b, 0]) + ev += [warp_event(s, -op, 0, 0) for op in wordops] + return ev + + def program(): + yield 'pre', [x for e in precondition + compensation for x in (expand_tadd(e) if e[0] == 'tadd' else [e])] + yield 'A', A + yield 'A', cut + yield 'B', B + yield 'tail', tail + yield 'cleanup', cleanup + + def fullprog(): + return [(part, e) for part, es in program() for e in es] + prog = fullprog() + for back in (False, True): + rows = {regkey(r): {(r, ()): Q(1)} for r in range(n)} + for c in zero_buffers: + rows[('Z', c)] = {} + for part, e in prog: + if e[0] == 'warp': + key = ('L', e[1]) if not isinstance(e[1], list) else tuple(e[1]) + rows[key] = warp_row(rows[key], e[2]) + else: + if e[0] == 'add': + src, dst = regkey(e[2]), regkey(e[1]) + a, b = e[3], e[4] + if back: + src, dst, a = dst, src, -a + assert src != dst + add_row(rows[dst], rows[src], Q(a, b)) + else: + key = regkey(e[1]) + a, b = (e[3], e[2]) if back else (e[2], e[3]) + q = Q(a, b) + assert q + rows[key] = {j: q * x for j, x in rows[key].items()} + expected = {regkey(r): {(r, ()): Q(1)} for r in range(n)} + for t in range(v): + if back: + expected[('L', t)][(v + t, ())] = Q(-1) + else: + expected[('L', v + t)][(t, ())] = Q(1) + for c in zero_buffers: + expected[('Z', c)] = {} + bad = [key for key in expected if rows[key] != expected[key]] + assert not bad, ('arbitrary-input endpoint (free warp algebra)', back, bad[:8]) + # dyadic primitives + for part, e in prog: + if e[0] == 'add': + assert is_dyadic(Q(e[3], e[4])) + elif e[0] == 'scale': + q = Q(e[2], e[3]) + a = abs(q.numerator) + assert is_dyadic(q) and a and a & (a - 1) == 0 + + wrapped_regs = {r for r in range(2 * v, n) if start[r] != 0 or final[r] != 1} # entering or hyperplane-ended helpers carry wrappers + # ---- frame chains, paid profile, edges, warps ------------------------------------------------------------------- + contains = lambda a, b: basis(frames[a] + frames[b]) == tuple(frames[b]) + cur = start.copy() + paid, edges = Counter(), set() + wsum = {w_['op']: w_ for w_ in warps} + G_of = {} + for w_ in warps: + lin, inv_ = solve_G(w_['G_columns'], h) + assert inv_, ('non-invertible G', w_['op']) + img = basis([lin(x) for x in frames[w_['from_frame']]]) + assert img == tuple(frames[w_['to_frame']]), ('G does not map the from frame onto the to frame', w_['op']) + assert len(frames[w_['from_frame']]) == len(frames[w_['to_frame']]) + G_of[w_['op']] = lin + warp_edges = set() + + def regs_of(e): + return [r for r in gate_regs(e) if not isinstance(r, list)] + + def climb(r, f): + old = cur[r] + assert contains(old, f), ('nonmonotone', r, old, f) + if old != f: + degree = len(frames[f]) - len(frames[old]) + paid[degree] += 1 + edges.add((old, f)) + cur[r] = f + + def do_warp(e): + _, r, op, f0, f1 = e + if isinstance(r, list): + assert r[0] == 'Z' + assert f0 == f1 == 1 + return + assert cur[r] == f0, ('warp frame mismatch', r, op, cur[r], f0) + a = abs(op) + lin = G_of[a] + if op > 0: + ok = basis([lin(x) for x in frames[f0]]) == tuple(frames[f1]) + else: + ok = basis([lin(x) for x in frames[f1]]) == tuple(frames[f0]) + assert ok, ('warp G does not carry the frame', op, f0, f1) + cur[r] = f1 + warp_edges.add((1 if op > 0 else -1, a, f0, f1)) + + # zero-frame phase + for e in precondition + compensation: + if e[0] == 'tadd': + assert start[e[2]] == 0 and start[e[1]] == 0 and e[-1] == 0 and e[2] not in set(wrapped_regs) and all(op != 0 for op in e[3]) + for ev in expand_tadd(e): + if ev[0] == 'warp': + do_warp(ev) # frame 0 -> 0: K_G itself is the physical operator + continue + for r in regs_of(e): + assert start[r] == 0 and e[-1] == 0, ('zero-frame precondition on a nonzero entrance', e) + for part in ('A', 'B'): + if part == 'B': + assert all(cur[r] == f for r, f in zip(centers, center_frames)) + assert all(cur[v + t] == levels.get(str(t), 0) for t in range(v)) + for r, frame in zip(centers, center_frames): + served = {levels.get(str(e[1] - v), 0) for e in cut if e[2] == r} + old = frame + for f in sorted(served, key=lambda f: -len(frames[f])): + assert contains(f, old) + if old != f: + paid[len(frames[old]) - len(frames[f])] += 1 + edges.add((old, f)) + edges.add((f, old)) + old = f + for e in (A if part == 'A' else B): + if e[0] == 'warp': + do_warp(e) + else: + for r in regs_of(e): + climb(r, e[-1]) + for e in tail: + for r in regs_of(e): + climb(r, e[-1]) + for r, f in enumerate(final): + climb(r, f) + for e in cleanup: + if e[0] == 'warp': + do_warp(e) + continue + for r in gate_regs(e): + if isinstance(r, list): + assert r[0] == 'Z' and r[1] in set(zero_buffers) and e[-1] == 1 + else: + assert final[r] == 1 and e[-1] == 1, ('cleanup on a non-FULL end', e) + assert all(len(frames[final[r]]) < h for r in zero_buffers) + assert set(zero_buffers) == set(helper_final) + rep = word['report'] + assert dict(paid) == {int(r): c for r, c in rep['local_profile'].items()}, ('paid profile differs', dict(paid), rep['local_profile']) + canonical['local_profile'] = dict(sorted(paid.items())) + canonical['edges'] = sorted(edges) + canonical['warp_edges'] = sorted(warp_edges) + out.mkdir(parents=True, exist_ok=False) + payload = json.dumps(canonical, sort_keys=True, separators=(',', ':')).encode() + (out / 'CANONICAL-WORD.json.gz').write_bytes(gzip.compress(payload, mtime=0)) + raw = word_path.read_bytes() + (out / 'FULL-WORD.json.gz').write_bytes(gzip.compress(gzip.decompress(raw) if word_path.suffix == '.gz' else raw, mtime=0)) + receipt = dict(status='PASS_BORROW_WORD_FREE_ALGEBRA_ALL_COLUMNS_AND_NATIVE_FRAMES', + input_content_sha256=hashlib.sha256(gzip.decompress(raw) if word_path.suffix == '.gz' else raw).hexdigest(), + canonical_content_sha256=hashlib.sha256(payload).hexdigest(), + live_columns_each_orientation=n, helpers=R, original_helpers=R0, removed_helpers=k, + zero_buffers=nz, warps=len(warps), warp_events=sum(e[0] == 'warp' for part, e in prog), + initial_corrections=len(word['initial_corrections']), + scalar_operations=len([1 for p, e in prog if e[0] != 'warp']), + local_profile=dict(sorted(paid.items())), local_rank_mass=sum(r * z for r, z in paid.items()), + widths=[len(frames[final[r]]) - len(frames[start[r]]) for r in range(2 * v, n)], + frames=len(frames), directed_edges=len(edges), warp_edge_classes=len(warp_edges), + seconds=time.monotonic() - t0, + scope='Fresh exact forward and inverse-transpose replay over a free noncommutative warp algebra on every arbitrary input, native frame chains, dyadic primitives, zero buffers returned to zero. Physical Clifford exactness of every warp is checked by the local replay and the phase recipes.') + (out / 'SCALAR-FRAME-AUDIT.json').write_text(json.dumps(receipt, indent=2) + '\n') + print(json.dumps({k_: x for k_, x in receipt.items() if k_ != 'widths'}, indent=2), flush=True) + + +if __name__ == '__main__': + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument('word', type=Path) + ap.add_argument('out', type=Path) + a = ap.parse_args() + run(a.word, a.out) diff --git a/research/t74-native-fast/vendor/native/new/code/borrow/vendor/PR2226-NOTICE.md b/research/t74-native-fast/vendor/native/new/code/borrow/vendor/PR2226-NOTICE.md new file mode 100644 index 0000000000..5ea70357a0 --- /dev/null +++ b/research/t74-native-fast/vendor/native/new/code/borrow/vendor/PR2226-NOTICE.md @@ -0,0 +1,22 @@ +# Attribution and license + +New construction, proof text and checkers: Cinna Davis (@1337isnot1337), with +substantial OpenAI Codex assistance, Apache-2.0. + +The selected complex canonical word is the PR1042 ancestry retained in PR1094. +Jeremy Kothe, Rohan Arun, Hao Yan, Chafik Boukhalfa, icekylinx, Jonathan Capalbo +and the source package's full provider/frame/controller lineage retain credit. +Ali Romman supplied the source-bound fixed-block theorem and certificate; +Thomas DiFiore supplied the earlier block discovery. The borrowing construction +does not attribute its changed interface to those predecessor results. + +`price_engine.py` is an unchanged copy of the incorporated +`research/complex-local-word-ceiling/ceiling.py`: Douglas Colkitt, with Claude +(Anthropic) assistance; original SPDX/license context and docstring retained. +General Clifford frame and exact Gaussian normal forms are inherited from +`notes/general-clifford-frames.tex` and the repository's credited phase/compiler +lineage. The package independently checks its actual local Gaussian products. + +Source hashes, base commits and the copied engine's Git blob are in SOURCES.json. +No full native supplier, all-size compiler, precision theorem or new kappa is +claimed. No independent human review is claimed. diff --git a/research/t74-native-fast/vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py b/research/t74-native-fast/vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py new file mode 100644 index 0000000000..166841a037 --- /dev/null +++ b/research/t74-native-fast/vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py @@ -0,0 +1,149 @@ +"""Small exact Gaussian-dyadic Clifford compiler, independent of gx internals. +Paulis use i^p X^x Z^z. State vectors use integer Gaussian numerators / 2^d. +The tableau is supplemented by a literal circuit, so global phases are kept. +""" +from dataclasses import dataclass + +def parity(x):return x.bit_count()&1 +def rank(rows): + p={} + for x in rows: + while x: + b=x.bit_length()-1 + if b not in p:p[b]=x;break + x^=p[b] + return len(p) +def transpose(rows,n):return tuple(sum(((rows[j]>>i)&1)<>j&1);a[j],a[k]=a[k],a[j] + for i in range(n): + if i!=j and a[i]>>j&1:a[i]^=a[j] + assert [r&((1<>n for r in a) +def basis_extend(cols,n): + out=[] + for x in list(cols)+[1<len(out):out.append(x) + assert len(out)==n + return tuple(out) +def nullspace(rows,n): + a=list(rows);p=[];k=0 + for j in range(n): + t=next((i for i in range(k,len(a)) if a[i]>>j&1),None) + if t is None:continue + a[t],a[k]=a[k],a[t] + for i in range(len(a)): + if i!=k and a[i]>>j&1:a[i]^=a[k] + p.append(j);k+=1 + return tuple((1<>j)&1)<>i&1:out=pmul(out,T[i]) + for i in range(n): + if z>>i&1:out=pmul(out,T[n+i]) + return out +def compose(A,B):return tuple(apply(A,p) for p in B) +def inverse(T): + n=len(T)//2;cols=[x|(z<>n;u,v,p=apply(T,(x,z,0));assert (u,v)==identity(n)[j][:2];out.append((x,z,(-p)%4)) + return tuple(out) +def qvalue(Q,alpha,x,n): + return (sum(alpha[i] for i in range(n) if x>>i&1)+2*sum(parity((Q[i]>>(i+1))&(x>>(i+1))) for i in range(n) if x>>i&1))%4 +def mul_i(a,p): + x,y=a;p%=4 + return [(x,y),(-y,x),(-x,-y),(y,-x)][p] +@dataclass +class Op: + n:int + tab:tuple + circuit:list + def then(self,b): + assert self.n==b.n + return Op(self.n,compose(b.tab,self.tab),self.circuit+b.circuit) + def adjoint(self): + circ=[] + for e in reversed(self.circuit): + if e[0]=='P':circ.append(('P',inv(e[1],self.n))) + elif e[0]=='D':circ.append(('D',e[1],tuple((-x)%4 for x in e[2]))) + elif e[0]=='C':circ.append(('C',e[1],-e[2])) + elif e[0]=='phase':circ.append(('phase',(-e[1])%4)) + else:circ.append(e) + return Op(self.n,inverse(self.tab),circ) + def zero_state(self,basis=0): + N=1<>i)&1 for i in range(n)) + assert all(alpha[i]%2==(Q[i]>>i)&1 for i in range(n)) + return Op(n,tuple([(1<>i&1 else 0,1<>i&1 else 0) for i in range(n)]),[('C',q,sgn)]) +def xgate(n,b):return Op(n,tuple([(1<>i)&1)) for i in range(n)]),[('X',b)]) +def fourier(n,axes=None): + out=ident(n) + for i in range(n) if axes is None else axes:out=out.then(cgate(n,1<len(selected):picks.append(j);selected.append(x) + assert len(picks)==r and all(x>>r==0 for x in Bcols) + Br=transpose(selected,r);Bi=inv(Br,r);Dr=transpose([Dcols[j]&((1<>i&1:out^=c + return out + + +def rank(xs): + b={} + for x in xs: + while x: + i=x.bit_length() + if i not in b:b[i]=x;break + x^=b[i] + return len(b) + + +def extend(xs,h): + out=list(xs) + for i in range(h): + if rank(out+[1<len(out):out.append(1<>i)&1)<>i&1)==(M[i]>>j&1) for i in range(h) for j in range(h)) + perm=np.array([linear(cols,x) for x in range(1<>i)&1)*(x>>i&1) for i in range(h))+ + 2*sum(((M[j]>>i)&1)*(x>>i&1)*(x>>j&1) for i in range(h) for j in range(i+1,h)) + for x in perm],dtype=np.int64)%4 + return perm,phase + + +def apply_mono(z,recipe,sign=1): + re,im,exp=z;perm,phase=recipe;rr=np.empty_like(re);ii=np.empty_like(im) + if sign==1: + for p in range(4): + mask=phase==p;r=re[mask];i=im[mask] + if p==0:a,b=r,i + elif p==1:a,b=-i,r + elif p==2:a,b=-r,-i + else:a,b=i,-r + rr[perm[mask]]=a;ii[perm[mask]]=b + else: + r=re[perm];i=im[perm] + for p in range(4): + mask=phase==p + if p==0:a,b=r[mask],i[mask] + elif p==1:a,b=i[mask],-r[mask] + elif p==2:a,b=-r[mask],-i[mask] + else:a,b=-i[mask],r[mask] + rr[mask]=a;ii[mask]=b + return rr,ii,exp + + +def coord(z,axes,sign=1): + re,im,exp=z + for j in axes: + p=np.array([x for x in range(len(re)) if not(x>>j&1)]);q=p^(1< emit -> independent replay -> wrappers -> phases (+ independent warp-recipe recheck). +Same step layout and STEPS.json as the lineage replay_native.py; usage: run_native_borrow.py BORROW-WORD.json[.gz] WORK_DIR (WORK_DIR must not exist).""" +import json,os,subprocess,sys,time +from pathlib import Path +HERE=Path(__file__).resolve().parent/'code/borrow' +word=Path(sys.argv[1]).resolve();work=Path(sys.argv[2]).resolve();work.mkdir(parents=True,exist_ok=False);local=work/'local' +env=dict(os.environ,PYTHONDONTWRITEBYTECODE='1',PYTHONUTF8='1',PYTHONINTMAXSTRDIGITS='0');env.pop('PYTHONOPTIMIZE',None) +flags=(0x00000040|0x08000000) if os.name=='nt' and os.environ.get('BW_IDLE','1')=='1' else 0 # windowless, IDLE priority +steps=[] +for label,script,args in [('native',HERE/'bw_transport.py',[word,local]),('ledgers',HERE/'bw_emit.py',[local]), + ('local-replay',HERE/'bw_audit_local.py',[local]), + ('wrappers',HERE/'bw_adapters.py',[local/'CANONICAL-WORD.json.gz',local/'RESIDUAL-ADAPTERS.json',local/'WRAPPER-CHECKS.json']), + ('phases',[HERE/'bw_phases.py',HERE/'bw_check_recipes.py'],[local])]: # phases = exact lowering, then the independent warp-recipe recheck + t=time.monotonic();log=b'' + for script in (script if isinstance(script,list) else [script]): + p=subprocess.run([sys.executable,'-B',str(script),*map(str,args)],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,cwd=HERE,env=env,creationflags=flags) + log+=p.stdout + if p.returncode:break + (work/(label+'.log')).write_bytes(log) + steps.append(dict(step=label,exit_code=p.returncode,seconds=time.monotonic()-t));(work/'STEPS.json').write_text(json.dumps(steps,indent=2)+'\n') + assert p.returncode==0,(label,log.decode(errors='replace')[-4000:]) + print('PASS',label,round(steps[-1]['seconds'],1),flush=True) diff --git a/research/t74-native-fast/verify.py b/research/t74-native-fast/verify.py new file mode 100644 index 0000000000..0c311cd6e7 --- /dev/null +++ b/research/t74-native-fast/verify.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Tekalign (@tekuuu), with substantial OpenAI Codex assistance. +"""Fresh complete native replay against the pinned PR2751 reference outputs.""" +import argparse +import json +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from common import HERE, need, sha, source_bytes +from compare import canonical, normalized + + +def main(): + need(__debug__, 'assertions must remain enabled') + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--provider', choices=('base', 'extra'), default='base') + parser.add_argument('--relocate', action='store_true', help='replay a Git-free copy in a path with spaces') + args = parser.parse_args() + if args.relocate: + with tempfile.TemporaryDirectory(prefix='t74-relocate-') as temporary: + root = Path(temporary) + package = root / 'package with spaces' + shutil.copytree(HERE, package, ignore=shutil.ignore_patterns('__pycache__')) + need(not (root / '.git').exists(), 'Git-free relocation') + subprocess.run([sys.executable, '-I', '-B', str(package / 'verify.py'), + '--provider', args.provider], cwd=root, check=True) + print('PASS_T74_NATIVE_FAST_GIT_FREE_RELOCATION', args.provider) + return + source_bytes(HERE / 'vendor') + word = HERE / f'fixtures/WORD-{args.provider}.json.gz' + pins = json.loads((HERE / 'PINS.json').read_text()) + need(sha(word.read_bytes()) == pins[word.relative_to(HERE).as_posix()], 'fixture digest') + expected = json.loads((HERE / 'EXPECTED.json').read_text())[args.provider] + with tempfile.TemporaryDirectory(prefix='t74-native-fast-') as temporary: + work = Path(temporary) / 'replay' + subprocess.run([sys.executable, '-I', '-B', str(HERE / 'run_native.py'), + str(word), str(work)], check=True) + local = work / 'native/local' + output = normalized(local) + need(sha(canonical(output)) == expected['normalized_sha256'], 'all native outputs match reference') + need(sha((local / 'CLIFFORD-RECIPES.json').read_bytes()) == expected['recipe_bytes_sha256'], 'recipe bytes') + need(output['WARP-RECIPE-CHECKS.json'] == expected['coverage'], 'independent warp coverage') + if args.provider == 'base': + from controls import check + check(local) + print('PASS_T74_NATIVE_FAST_REFERENCE_AND_CONTROLS', args.provider) + + +if __name__ == '__main__': + main()