diff --git a/research/two-sided-helper-extraction/.gitattributes b/research/two-sided-helper-extraction/.gitattributes new file mode 100644 index 0000000000..d4d81cd1ac --- /dev/null +++ b/research/two-sided-helper-extraction/.gitattributes @@ -0,0 +1,4 @@ +vendor/** -text +data/** -text +evidence/** -text +allocation/** -text diff --git a/research/two-sided-helper-extraction/ALLOCATION-PINS.json b/research/two-sided-helper-extraction/ALLOCATION-PINS.json new file mode 100644 index 0000000000..36daf943e6 --- /dev/null +++ b/research/two-sided-helper-extraction/ALLOCATION-PINS.json @@ -0,0 +1,14 @@ +{ + "allocation/DISPATCH.json": "65e435bd68e97243c003677271b88485a29d4d0fae2dff1354100404a145e74c", + "allocation/FILL.json.gz": "d6585a3b05fb86efd08b1925c5ae0a03265c30f895f5e2c4e1cdfe91978cd3ef", + "allocation/ORDER.json": "519d1d5dbb997a219fcfcad34c0b03e7838bef24199784d7e964fa10090f66e1", + "allocation/PROFILE.json": "ab0840eda08fa501d444be22c7298bf38b70061b91964ad1b9dd9db388720199", + "allocation/PROVIDERS.json": "91a212677bc21d45990ad811dba16a6ce2f89fc43b61e67f75a09c35c6eace3b", + "allocation/RESULT.json": "5ba974e706ff58a523097693bfdc0e00935ddf4ad5d5ea467c38dc8a4fad4210", + "allocation/baseline/CLAIM.json": "29cd4aa92059a561437d7670b574c51ae4e1cfeaaf6feb6cc318d915869e6d30", + "allocation/baseline/ORDER.json": "519d1d5dbb997a219fcfcad34c0b03e7838bef24199784d7e964fa10090f66e1", + "allocation/baseline/PROFILE.json": "528400282a268b6e5983a5251af6040450fa0e7d9ddf7d65e4a0aa6a0b9096a6", + "allocation/vendor/PLAN.json.gz": "d566cfb87b71639d4138e1f89b543e2dd6a7772070226a2a14c799a6835bf21e", + "allocation/vendor/TEMPLATE.json.gz": "21297b20f1f2dc76eb9dd8124416068c3cb096bab9df17fa4da19bc68dfe082e", + "allocation/vendor/independent_owners.py": "77a848729159e271ba64f403dfd59dddb13044b17b2950fa56700f442e2fe461" +} diff --git a/research/two-sided-helper-extraction/CLAIM.json b/research/two-sided-helper-extraction/CLAIM.json new file mode 100644 index 0000000000..4edc2cb723 --- /dev/null +++ b/research/two-sided-helper-extraction/CLAIM.json @@ -0,0 +1,35 @@ +{ + "baseline_head": "18d03c447886895ef9abf888398178e0428533ca", + "baseline_kappa": "17201845283774695330739999999999999999999998999999999999999999999999/10000000000000000000000000000000000000000000000000000000000000000000000", + "baseline_pr": 2894, + "calls": 666, + "complete_package_manifest_sha256": "a6d0e45723ea87f43ed8026758306adbf44b5cfc8473464c77acb57f32530783", + "complex_lower": "1720398337354237885931/1000000000000000000000000", + "gain": "213808976768352857/1000000000000000000000000", + "helpers": 408, + "independent_inputs": 632, + "kappa": "17203983373542378859309999999999999999999998999999999999999999999999/10000000000000000000000000000000000000000000000000000000000000000000000", + "kappa_decimal": "0.0017203983373542378859309999999999999999999998999999999999999999999999", + "live_families": 66304, + "native_receipt_sha256": "3280682ab975f412ab25e8ec433b2e52d8d3b6226db712ccabbbd2babcc2b84d", + "physical_families": 66795, + "profile": { + "1": 1620344, + "2": 426241, + "23": 1, + "3": 180732, + "32": 14, + "4": 85248, + "48": 26837, + "5": 25700, + "6": 120, + "7": 1, + "8": 5328 + }, + "release_receipt_sha256": "c3fd39e0645b10681a26b74afd08b429e04a139222e156f533654486c4f70214", + "replicas": 74, + "scope": "Conditional finite supplier/outer certificate. Inherited all-size/compiler/theorem hypotheses remain; no selected frontier change, no optimality or independent-human-review claim. Both changed native chains are fresh; retained parent/native evidence explicitly reused by complete receipts.", + "source_manifest_sha256": "56cf455752722051d598a7da1e5ee700637fbaef09189f534413dbe6e0525a83", + "status": "CONDITIONAL_CANDIDATE_COMPLETE_FINITE_RELEASE", + "zero_buffers": 73 +} diff --git a/research/two-sided-helper-extraction/CONSTRUCTION.md b/research/two-sided-helper-extraction/CONSTRUCTION.md new file mode 100644 index 0000000000..650131970c --- /dev/null +++ b/research/two-sided-helper-extraction/CONSTRUCTION.md @@ -0,0 +1,86 @@ +# Paired input/output extraction + +Let M denote the complete non-target forward operator of the pinned PR2894 +word: the A gates after the entry prelude, the B gates and formal invertible +warps, and the restore gates. Target writes are omitted in this definition; +they are checked separately by the full independent word auditor. Operators +are noncommuting formal symbols, so the argument uses no numerical sampling. + +Let H contain zero-entry helper registers which are neither existing restored +helpers nor sources of the initial operator corrections. For a terminal +hyperplane E, let R consist of registers whose current terminal frames lie in +E. Seek a column y and a row alpha, supported on R, such that + +- v = M^-1 y is scalar and supported on H; +- u = alpha M is scalar and supported on H; +- alpha y = u v = 1. + +These are two exact nullspace conditions with a nonzero pairing. Finite-field +linear algebra can nominate candidates, but every published identity here is +replayed over rational coefficients in the free operator algebra. + +Choose an invertible dyadic input change S and output change T with +`S e_h = v`, `u S = e_h^T`, `T y = e_h`, and `e_h^T T = alpha`. +Then the h column and h row of `T M S` are both the corresponding identity +column and row. Register h is restored exactly for every arbitrary dirty +helper input and is not read by other output registers. This supplies the +cold endpoint needed by the inverse-reverse cleanup contract. + +For h=408, E is the binary hyperplane perpendicular to 52, with canonical +basis `(256,128,64,36,20,8,2,1)`. The output certificate is especially small: + +``` +alpha = e_408^T + (1/2)e_42^T + e_105^T +y = 2 e_42 + +408 += (1/2) * 42 +408 += 105 +42 -= 2 * 408 +``` + +All three terminal additions use frame E. The 24 input gates in +`data/TRANSFORM.json` act at frame zero. They include one scaling by 2 and +otherwise dyadic additions. `structure.py` derives S, T, M, u, v, alpha and y +from the literal gates and checks all seven identities, independently of the +word producer. `verify.py` also checks both full target maps and the dual +orientation with the inherited exact auditor. + +The target correction becomes `C S`. The initial operator corrections retain +their inputs because S acts only outside their source set. Warps, the cut, +ports, target levels, removed helpers and the entry prelude are unchanged. +The changed sections are exactly A, restore, helper_final, compensation, +report and cleanup. Inverse-reverse cleanup is regenerated and checked from +the full new word; its new private buffer is allocated, cleared and charged. + +The complete per-call profile changes from +`{1:2404,2:642,3:262,4:128,5:26,8:8}` to +`{1:2407,2:640,3:262,4:128,5:26,8:8}`. Helper408 changes width 9 to 8; +there remain 408 live helpers and 632 independent inputs, with **73** private +zero buffers instead of 72. + +# Owner allocation and cost + +Keeping PR2894's fill is worse despite the local improvement. The shipped fill +starts from that literal T74 allocation, makes 545 same-call width exchanges, +then 222 whole-role relocations. The exchanges preserve the set of physical +owner families at each call. Every relocation explicitly checks the owner +window and rejects a family already used in the call; the final independent +auditor rechecks all 271,728 roles, compact offsets, capacity, chronology and +family distinctness. These are discovery heuristics, with no optimality claim. + +The actual paid profile is +`{1:1620344,2:426241,3:180732,4:85248,5:25700,6:120,7:1,8:5328,23:1,32:14,48:26837}`. +Its rank mass is exactly `65088*74`. It includes every unused owner remainder. +The complete physical stock is `66304 + 408 + 8 + 73 + 2 = 66795`. +The inherited owner-only checker has a historical 72-buffer display field; +our wrapper explicitly replaces that field and labels its provenance. The +complete rebind, block-norm certificate and outer invoice independently check +the actual 73-buffer namespace, endpoints, stock and prefix reserve. + +The admission adapter preserves all inherited tests, with the new source pin +and buffer constants bound explicitly. In particular, the dimension-72 +symplectic-group stock factor is unchanged: it is not a private-buffer count. +The old source/parent artifacts are read-only. Both new providers run the full +five native stages; retained providers and the 16-stage retained parent may be +reused only through exact complete-cache/source/claim receipts, and the replay +records this distinction. diff --git a/research/two-sided-helper-extraction/CREDITS.md b/research/two-sided-helper-extraction/CREDITS.md new file mode 100644 index 0000000000..4233009b6a --- /dev/null +++ b/research/two-sided-helper-extraction/CREDITS.md @@ -0,0 +1,39 @@ +# Credit and scope + +Jeremy Diviney, with substantial OpenAI Codex assistance, contributed the +paired input/output subspace search, the explicit helper408 extraction, the +exact structural certificate, the owner-width exchange/relocation repair, +and the source-bound 73-buffer integration. No independent human review is +claimed. This is a new application of ordinary exact linear algebra to these +literal words, not a claim to have invented nullspace or basis-change methods. + +The immediate parent is Jeremy Kothe / `jeremykothe2`, PR2894 at +`18d03c447886895ef9abf888398178e0428533ca`. Its two preload-resynthesized quartets, +T74 owner order and fill, reconstruction, and complete admission remain +credited. `vendor/preload_move.py` is unchanged from that package. + +The construction inherits Yiyang Lu / `Lyy-iiis`'s PR2857 staged shared kernels +and source-bound overlay/native/release tooling; Dugongue's PR2863 packing; +Marius-Paul Dumitrean's PR2843/PR2802 pattern-flow and retired-helper lineage; +Jeremy Kothe's PR2833 dirt-entry supplier; and Philippe Van Velzen's PR2853 +cost and block-energy lineage. Tekalign's PR2751/PR2839 owner audit and +admission lineage is retained in the corresponding code headers. The exact +moment auditor is PR2894's `tools/audit_moment2857.py`, changing only the +comparison pin and label to PR2894. + +The independently written exact scalar/frame auditor retains its original +icekylinx attribution. The fast native package is copied byte-for-byte from +PR2833's `new/fastnative`; it retains the PR2768 sparse engine and all nested +PR2226 Clifford/operator notices. The copied material, including its original +line endings, is pinned in `PINS.json`. + +The new terminal recovery changes literal gates and adds a cold endpoint. +PR2904's fixed-gate dirty-entry/refit negative census does not cover this +operation. The initial compensation-kernel search failed before this pivot; +it is not presented as a new universal obstruction. Advisory overlap was +checked against open PRs and Discussion bodies before discovery and again +before submission. That coverage is not a novelty guarantee. + +The selected repository result is not changed. A passing finite release uses +the inherited all-size/compiler/outer hypotheses and does not establish an +unconditional integer-multiplication theorem. diff --git a/research/two-sided-helper-extraction/MANIFEST.json b/research/two-sided-helper-extraction/MANIFEST.json new file mode 100644 index 0000000000..b69fc6eaa2 --- /dev/null +++ b/research/two-sided-helper-extraction/MANIFEST.json @@ -0,0 +1,105 @@ +{ + ".gitattributes": "6640fcf0b716dfbc3ed1cba946579ce05c4bd637357ff9bb976de81ca7ff0bbb", + "ALLOCATION-PINS.json": "a7a24a98607aaaf1db431628311330ed3a4f92e64ad1621f0ca993f74628332e", + "CLAIM.json": "2406680a07b43a69b0f12f8462cc43f3616f3c8cb0a46bc767541b45945cd2bf", + "CONSTRUCTION.md": "56ba42c905eb95f096e425db797ca1cffcf181e5f73ec06ecd6f48e6f43f793d", + "CREDITS.md": "5c1532b542227854eceaced764d5f73ad5126d3e139b6f52e5b11a3fc6f64e1b", + "PINS.json": "d67d70971d36ccd8faa4e0edfd65852e0a41888997fc6a3937e725b573ea0e6a", + "README.md": "c8667c41bf605ba13f5527dcb3e6c9369eb4dd3d237112632b10c0961a97c24a", + "SOURCES.json": "e12c71e2668ca5421f8db8b666e051c81564914d8934c6a9af0ab47231425ee8", + "TASK.json": "0e8ffd6d453a113ee6d2b50cbdbcb35cd5928b30ea4ae77ad942e0571a92c7bd", + "VERIFY.json": "abd44951b669e5b8d2bdb063971ce850779f416479a92c696a6ad5e80d1b387f", + "allocation/DISPATCH.json": "65e435bd68e97243c003677271b88485a29d4d0fae2dff1354100404a145e74c", + "allocation/FILL.json.gz": "d6585a3b05fb86efd08b1925c5ae0a03265c30f895f5e2c4e1cdfe91978cd3ef", + "allocation/ORDER.json": "519d1d5dbb997a219fcfcad34c0b03e7838bef24199784d7e964fa10090f66e1", + "allocation/PROFILE.json": "ab0840eda08fa501d444be22c7298bf38b70061b91964ad1b9dd9db388720199", + "allocation/PROVIDERS.json": "91a212677bc21d45990ad811dba16a6ce2f89fc43b61e67f75a09c35c6eace3b", + "allocation/RESULT.json": "5ba974e706ff58a523097693bfdc0e00935ddf4ad5d5ea467c38dc8a4fad4210", + "allocation/baseline/CLAIM.json": "29cd4aa92059a561437d7670b574c51ae4e1cfeaaf6feb6cc318d915869e6d30", + "allocation/baseline/ORDER.json": "519d1d5dbb997a219fcfcad34c0b03e7838bef24199784d7e964fa10090f66e1", + "allocation/baseline/PROFILE.json": "528400282a268b6e5983a5251af6040450fa0e7d9ddf7d65e4a0aa6a0b9096a6", + "allocation/vendor/PLAN.json.gz": "d566cfb87b71639d4138e1f89b543e2dd6a7772070226a2a14c799a6835bf21e", + "allocation/vendor/TEMPLATE.json.gz": "21297b20f1f2dc76eb9dd8124416068c3cb096bab9df17fa4da19bc68dfe082e", + "allocation/vendor/independent_owners.py": "77a848729159e271ba64f403dfd59dddb13044b17b2950fa56700f442e2fe461", + "check_allocation.py": "fb05e0899616cb4abbbae6876f72e9797374f390581dd59a0a4737b208e9d313", + "data/PARENT-base.json.gz": "c20a470aec0f3e61833cb41fe190639eb358f58017143d2336c55c80fba265eb", + "data/PARENT-extra.json.gz": "db34e39876241087b581ed9374c53e9cd393e3e86ef6103bfb54f3077c3d2761", + "data/TRANSFORM.json": "1d38f0369fce0b892d202ce2e5fd7ea95d9a95d3f80734b672cddd5cb93ce8ca", + "data/WORD-base.json.gz": "3657ad53ebe5f156f307a903479e919f2fe812811ce5d5f15e72c3aaf68dfde3", + "data/WORD-extra.json.gz": "b975492ff4cbec0d619cdf2da34f55ce3b20c8a541132e4339cc6c8ae3b2e487", + "evidence/ADAPTER-DERIVATION.json": "8de38d6831110870fd2b649b7575f4e73d24cdbf13f7b91fb8c8ca66ba61a7dc", + "evidence/ADMISSION-RESULT.json": "f6f638bf87d592be93568b02463972ba982644939d3f9d1e2b7afa7a0fc666e0", + "evidence/AUDIT-base.json": "c9c08658b2062307daa471bd038ea697c52e8948c8781a81c989df1235522e23", + "evidence/AUDIT-extra.json": "a4bfb5253f7f59361076e858534ec57eab2a76810a1e5c8a34f07e1e602f3893", + "evidence/ENVIRONMENT.json": "8c22d637dd3951151e5b7764536851f6147b805a49a418651ac84a647137384d", + "evidence/EXACT-OWNER-MOMENT.json": "d7c0187780a0529bc5fd1d6185c2cdcf051cf0112ddea18afe9d04b45f1bd0bb", + "evidence/FULL-NATIVE-RECEIPT.json": "3280682ab975f412ab25e8ec433b2e52d8d3b6226db712ccabbbd2babcc2b84d", + "evidence/FULL-NATIVE-RESULT.json": "7bc7e46e8f273009326c88c2bd8c960ff35cc23400125950141028ca60c10e92", + "evidence/FULL-PACKAGE-MANIFEST.json": "a6d0e45723ea87f43ed8026758306adbf44b5cfc8473464c77acb57f32530783", + "evidence/FULL-STAGES.json": "a987267346f9f176527a69c947d3e2ed9a813b902c2a8bd27a4fbe72e204076b", + "evidence/LOCAL-REPLAY.json": "0b342768d31feafd696b20a5ab54ec0acf06414043e684f3918db4cc95ab81b6", + "evidence/NATIVE-base.json": "85547c3a1807490b9570d7379431d985cba78e85a5598882b1b711c39941c491", + "evidence/NATIVE-extra.json": "991d2436fb5fc40976e57c0e46e3a3be7e8a3beab955f345ec2a8faa468da007", + "evidence/OUTER-INDEPENDENT.json": "e0eee1092e06d735a8c1e4414549286c174d86d69e8ed9295c10d62354d1e9c1", + "evidence/OUTER-LEDGER.json": "e28b67711d816d8ba4ae9916af56a43ff1121b603a99a347a54d1ebd382abd0a", + "evidence/OVERLAP.json": "67d6d034ae19d0f4fbf1d463ea3400bfdaa0bf6feea4501ff2a90ccc56747521", + "evidence/RELEASE-RECEIPT.json": "c3fd39e0645b10681a26b74afd08b429e04a139222e156f533654486c4f70214", + "evidence/RUNTIME-PATCHES.json": "c4d83beb1f6d6e2763f3427cfe653c8e65377fdc42a032d76e4e60db488ed39a", + "evidence/SEARCH.json": "0941522b34afb3108d472655e7364c0309cdca724504ed3e3ca6a0cc60d93bd5", + "evidence/SOURCE-DERIVATION.json": "f6012ed63d486ba566e6fa89544f0fbd0d53cda553e2cc1884112238a6cc1201", + "extract.py": "e9f530fd9a2d72c86a65ae1dea147a61d072969deded314973b5f31de90c91ac", + "reproduce.py": "18ead96a58b5093e3a7e4bd81e6c52621b7f61a200437e1e413cdd04f8840e45", + "run_registered.py": "264dc8588894762ba2bb8bcb9c63e434508b61bf0228d7a0a0a599f0282a3019", + "structure.py": "83f63b6d9a1a543ecfa2c98d479dbe4e7a1c3caf6fd1c3566123308efbc32e96", + "tools/admit_channel408.py": "a62c21eac4e0df502cbfb78c88b19a763fd351cde3c11c0588874f84db6992bf", + "tools/audit_moment.py": "e7147ccb8c57aa32a2cb227234a6a200a0b9e735eb1a655fd79ab29a4d7c0a00", + "tools/build_channel_overlay.py": "8b93cad38c29203587dcc85100701d55c18749e3a891a2dddd686bb8105ed3d4", + "tools/channel_blocknorm.py": "b53ebd53e3948f658c6da4f487a9ea10c9cb0a6acf2435750a32d6efeb9869c0", + "tools/prepare_channel_native.py": "4d207b9bbe3e0b8a86d10ad5d5f329a81da0cf56dce6c03e6fdd5b78e581ce91", + "vendor/audit_local.py": "a38940094f7d19cd6376aafdd4734fa68eabc9aff4c98c3c4a3e9540328b1c90", + "vendor/fastnative/.gitattributes": "92e5734dbb86fb8958622e6dcea5895601800a24b0722ef86220322449a44ff8", + "vendor/fastnative/EXPECTED.json": "8d45fba81564631f9f8614e637b9fbe69dc911b4e2f0b77f0a7071f39cfd7ca8", + "vendor/fastnative/FRESHNESS.json": "92abf8c25be59ff71a90781f38c5db2f9176c623df046a6d0e2327fd0235cb6c", + "vendor/fastnative/LICENSE": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4", + "vendor/fastnative/NATIVE-LINEAGE-NOTICE": "ee0c73ca35877aad0e0b6adc560a3881cb82276dba4cf2d4fc58cd19e57cc420", + "vendor/fastnative/PINS.json": "f619e8e1c163078fb70c6fc3b98a498a671b8c02927b91d6cc253af2a775b6c9", + "vendor/fastnative/README.md": "6a2026383804606cd7981e087192b3488c674f2d9443ec218dcb2e85d06406dc", + "vendor/fastnative/SOURCE-PROVENANCE.json": "8daf4fc7c75db99d34641152682208ce6c974f50d509960d0f4fa021f862abee", + "vendor/fastnative/SOURCES.json": "3599ed28c8d8a9ce096bc13507b066d09e3968587781748b2bc72f634618331b", + "vendor/fastnative/TASK.json": "8159b49d5c73dd887d432a4680dc947f63e7158a01a66d7736ff7138e8149732", + "vendor/fastnative/VERIFY.json": "e46542b70296c039b5bea0c0aa9cfd4e95e1df8859e67885ed3403bea9da7b32", + "vendor/fastnative/benchmark.py": "3e544453c89310281d745a37e861cbd79065b1740d90f1ec883fc200b189a557", + "vendor/fastnative/common.py": "8f04e08b99a370fa82115fc46fbb3af4ab44f4facd47de07b01e1a2499a94914", + "vendor/fastnative/compare.py": "ebf877a6f47ef1fd2b797fd6077bd45d132d8cb56ab7553044bae3d86e238e45", + "vendor/fastnative/controls.py": "03131f4dc6a1830f10e35fb837ada456f060ca510994d250c5c2666a6342c23a", + "vendor/fastnative/evidence/BENCHMARK.json": "9b192c5697514c7b36b709d0e5506915425ca61f24af0210e2508d7b1bdb295f", + "vendor/fastnative/evidence/COVERAGE.json": "8bead250cc97614528d9448dfd29529bf08605daa5e8007e701038ab317e00f6", + "vendor/fastnative/evidence/REGISTERED.log": "78a49def69d0465f4318b9e24613246ba5fb6de19441e54b88fb50dfe823f149", + "vendor/fastnative/evidence/VALIDATION.json": "d265ce16251effd6b5d3b7429f31f98cd385fe79f659cfa24a2820bc17ac70dd", + "vendor/fastnative/fixtures/WORD-base.json.gz": "ae8b6b4d62a9da29331062fae1bd68b0341edf83152f5a5ef50c5109ba578f9a", + "vendor/fastnative/fixtures/WORD-extra.json.gz": "1bb44a73d5841afb954b49ae94dba2e0c536b1eea9436ae5d89de87d8a04e127", + "vendor/fastnative/requirements.txt": "a23aaf94250a9f53031a592980142245a848e2372b6c6c3093e8260b129265b8", + "vendor/fastnative/run_native.py": "a7bfe110fe5098f6ef8bde3c43ecf15e8d1e06149abf7321a4c945383dcc2627", + "vendor/fastnative/stage.py": "3cce27dd5a359ebc4dc70d4aab994aee52bc0a12e59db7da3f902257f876cffe", + "vendor/fastnative/vendor/accelerators/SPARSE-NOTICE.md": "3da80a5155c625bff907a42a82c65bfcf92854d2c960bcea4537c19c99efd4f2", + "vendor/fastnative/vendor/accelerators/SPARSE-PROOF.md": "d73e4522602404caba8e7f247005a45c8a8cd26ffd2a70d65f4f9556a391d053", + "vendor/fastnative/vendor/accelerators/sparse_state.py": "e91210ecd5085cf9add872f40bb434806838da488e12152c63c86e51fb5a7a37", + "vendor/fastnative/vendor/accelerators/tables.py": "2fe087ba4558bd21ca49945dbedaa4047e4170e8fd4e2280701bb2f0481811b5", + "vendor/fastnative/vendor/native/new/code/borrow/NOTICE-PR2226.md": "6b6730303818f6edc2a253eb4d05471eee58f28b5815fb250c32ae376f774c8a", + "vendor/fastnative/vendor/native/new/code/borrow/bw_adapters.py": "c5907050a9a7fa36d4fcba3ad4fe440d1bec2063360c095013891785ba65c3ce", + "vendor/fastnative/vendor/native/new/code/borrow/bw_audit_local.py": "08d5864d9b77902fc5ab5a062a8ea843fe1e572243b8c580abb0a421b2e46d07", + "vendor/fastnative/vendor/native/new/code/borrow/bw_check_recipes.py": "d600b959a0ac462dc28deb8c0d5d8f9e0c76d7f7d7b6f92a296c5ef9e0a1de19", + "vendor/fastnative/vendor/native/new/code/borrow/bw_emit.py": "99b59a6fa3feda86785e4225157dcb1a6169d256cec4f5e0acc9cea7a701df76", + "vendor/fastnative/vendor/native/new/code/borrow/bw_gauss.py": "0884b14d6d77cde419a3c773ad9b21d0d18de1e6e20e6b6d5add458ed32ba4cb", + "vendor/fastnative/vendor/native/new/code/borrow/bw_phases.py": "9d1a620e26715f4c42fd0347ecc14ef5a4a9031867869b64e8bae4d8526a821e", + "vendor/fastnative/vendor/native/new/code/borrow/bw_tamper.py": "eab4b026965b9796eee92239660e1fb1fa629f6d9db44bc27b13911a018a6ee9", + "vendor/fastnative/vendor/native/new/code/borrow/bw_transport.py": "9818e08b819310b40f1441b89be8c4369584a5b3fa5dfe9b86b1df9a7f5d6a76", + "vendor/fastnative/vendor/native/new/code/borrow/vendor/PR2226-NOTICE.md": "f1d45d886926915531e3a59968abf0a4c974d7038f869848e71bd3a21b834422", + "vendor/fastnative/vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py": "2982ead07721e83358dc67c6f49c2b4c16a236a6bebdfd72f58221be1f5d0962", + "vendor/fastnative/vendor/native/new/code/borrow/vendor/pr2226_operators.py": "b37b67a04681c776dafcdc6c9af0e8a2dbfa9893b02e0fa2d77ccc9182a87988", + "vendor/fastnative/vendor/native/new/code/borrow/vendor/pr2226_replay.py": "0f9a47cdaeed0e22938c63251c232d6f23aeee2b62b0b1223cd4473c5428bcf7", + "vendor/fastnative/vendor/native/new/run_native_borrow.py": "8ec7db430f4f4771c06bdcfc31736193614f6ec209d57b63d4e2b75f17fb3ac8", + "vendor/fastnative/verify.py": "6dbdc56ca6cfde987869e12990a495d7eded78dd1887fb3fdf2d196060220fcc", + "vendor/preload_move.py": "c8fda4674644fcd5cbf39b6645ce148a21daa90a998b678cbe51f970b78b0044", + "verify.py": "9cebf9f20ae8d1d66cc066507a92456b719714fd83b7223e5352a507c4b2903f" +} diff --git a/research/two-sided-helper-extraction/PINS.json b/research/two-sided-helper-extraction/PINS.json new file mode 100644 index 0000000000..2125095d52 --- /dev/null +++ b/research/two-sided-helper-extraction/PINS.json @@ -0,0 +1,52 @@ +{ + "data/PARENT-base.json.gz": "c20a470aec0f3e61833cb41fe190639eb358f58017143d2336c55c80fba265eb", + "data/PARENT-extra.json.gz": "db34e39876241087b581ed9374c53e9cd393e3e86ef6103bfb54f3077c3d2761", + "data/TRANSFORM.json": "1d38f0369fce0b892d202ce2e5fd7ea95d9a95d3f80734b672cddd5cb93ce8ca", + "data/WORD-base.json.gz": "3657ad53ebe5f156f307a903479e919f2fe812811ce5d5f15e72c3aaf68dfde3", + "data/WORD-extra.json.gz": "b975492ff4cbec0d619cdf2da34f55ce3b20c8a541132e4339cc6c8ae3b2e487", + "vendor/audit_local.py": "a38940094f7d19cd6376aafdd4734fa68eabc9aff4c98c3c4a3e9540328b1c90", + "vendor/fastnative/.gitattributes": "92e5734dbb86fb8958622e6dcea5895601800a24b0722ef86220322449a44ff8", + "vendor/fastnative/EXPECTED.json": "8d45fba81564631f9f8614e637b9fbe69dc911b4e2f0b77f0a7071f39cfd7ca8", + "vendor/fastnative/FRESHNESS.json": "92abf8c25be59ff71a90781f38c5db2f9176c623df046a6d0e2327fd0235cb6c", + "vendor/fastnative/LICENSE": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4", + "vendor/fastnative/NATIVE-LINEAGE-NOTICE": "ee0c73ca35877aad0e0b6adc560a3881cb82276dba4cf2d4fc58cd19e57cc420", + "vendor/fastnative/PINS.json": "f619e8e1c163078fb70c6fc3b98a498a671b8c02927b91d6cc253af2a775b6c9", + "vendor/fastnative/README.md": "6a2026383804606cd7981e087192b3488c674f2d9443ec218dcb2e85d06406dc", + "vendor/fastnative/SOURCE-PROVENANCE.json": "8daf4fc7c75db99d34641152682208ce6c974f50d509960d0f4fa021f862abee", + "vendor/fastnative/SOURCES.json": "3599ed28c8d8a9ce096bc13507b066d09e3968587781748b2bc72f634618331b", + "vendor/fastnative/TASK.json": "8159b49d5c73dd887d432a4680dc947f63e7158a01a66d7736ff7138e8149732", + "vendor/fastnative/VERIFY.json": "e46542b70296c039b5bea0c0aa9cfd4e95e1df8859e67885ed3403bea9da7b32", + "vendor/fastnative/benchmark.py": "3e544453c89310281d745a37e861cbd79065b1740d90f1ec883fc200b189a557", + "vendor/fastnative/common.py": "8f04e08b99a370fa82115fc46fbb3af4ab44f4facd47de07b01e1a2499a94914", + "vendor/fastnative/compare.py": "ebf877a6f47ef1fd2b797fd6077bd45d132d8cb56ab7553044bae3d86e238e45", + "vendor/fastnative/controls.py": "03131f4dc6a1830f10e35fb837ada456f060ca510994d250c5c2666a6342c23a", + "vendor/fastnative/evidence/BENCHMARK.json": "9b192c5697514c7b36b709d0e5506915425ca61f24af0210e2508d7b1bdb295f", + "vendor/fastnative/evidence/COVERAGE.json": "8bead250cc97614528d9448dfd29529bf08605daa5e8007e701038ab317e00f6", + "vendor/fastnative/evidence/REGISTERED.log": "78a49def69d0465f4318b9e24613246ba5fb6de19441e54b88fb50dfe823f149", + "vendor/fastnative/evidence/VALIDATION.json": "d265ce16251effd6b5d3b7429f31f98cd385fe79f659cfa24a2820bc17ac70dd", + "vendor/fastnative/fixtures/WORD-base.json.gz": "ae8b6b4d62a9da29331062fae1bd68b0341edf83152f5a5ef50c5109ba578f9a", + "vendor/fastnative/fixtures/WORD-extra.json.gz": "1bb44a73d5841afb954b49ae94dba2e0c536b1eea9436ae5d89de87d8a04e127", + "vendor/fastnative/requirements.txt": "a23aaf94250a9f53031a592980142245a848e2372b6c6c3093e8260b129265b8", + "vendor/fastnative/run_native.py": "a7bfe110fe5098f6ef8bde3c43ecf15e8d1e06149abf7321a4c945383dcc2627", + "vendor/fastnative/stage.py": "3cce27dd5a359ebc4dc70d4aab994aee52bc0a12e59db7da3f902257f876cffe", + "vendor/fastnative/vendor/accelerators/SPARSE-NOTICE.md": "3da80a5155c625bff907a42a82c65bfcf92854d2c960bcea4537c19c99efd4f2", + "vendor/fastnative/vendor/accelerators/SPARSE-PROOF.md": "d73e4522602404caba8e7f247005a45c8a8cd26ffd2a70d65f4f9556a391d053", + "vendor/fastnative/vendor/accelerators/sparse_state.py": "e91210ecd5085cf9add872f40bb434806838da488e12152c63c86e51fb5a7a37", + "vendor/fastnative/vendor/accelerators/tables.py": "2fe087ba4558bd21ca49945dbedaa4047e4170e8fd4e2280701bb2f0481811b5", + "vendor/fastnative/vendor/native/new/code/borrow/NOTICE-PR2226.md": "6b6730303818f6edc2a253eb4d05471eee58f28b5815fb250c32ae376f774c8a", + "vendor/fastnative/vendor/native/new/code/borrow/bw_adapters.py": "c5907050a9a7fa36d4fcba3ad4fe440d1bec2063360c095013891785ba65c3ce", + "vendor/fastnative/vendor/native/new/code/borrow/bw_audit_local.py": "08d5864d9b77902fc5ab5a062a8ea843fe1e572243b8c580abb0a421b2e46d07", + "vendor/fastnative/vendor/native/new/code/borrow/bw_check_recipes.py": "d600b959a0ac462dc28deb8c0d5d8f9e0c76d7f7d7b6f92a296c5ef9e0a1de19", + "vendor/fastnative/vendor/native/new/code/borrow/bw_emit.py": "99b59a6fa3feda86785e4225157dcb1a6169d256cec4f5e0acc9cea7a701df76", + "vendor/fastnative/vendor/native/new/code/borrow/bw_gauss.py": "0884b14d6d77cde419a3c773ad9b21d0d18de1e6e20e6b6d5add458ed32ba4cb", + "vendor/fastnative/vendor/native/new/code/borrow/bw_phases.py": "9d1a620e26715f4c42fd0347ecc14ef5a4a9031867869b64e8bae4d8526a821e", + "vendor/fastnative/vendor/native/new/code/borrow/bw_tamper.py": "eab4b026965b9796eee92239660e1fb1fa629f6d9db44bc27b13911a018a6ee9", + "vendor/fastnative/vendor/native/new/code/borrow/bw_transport.py": "9818e08b819310b40f1441b89be8c4369584a5b3fa5dfe9b86b1df9a7f5d6a76", + "vendor/fastnative/vendor/native/new/code/borrow/vendor/PR2226-NOTICE.md": "f1d45d886926915531e3a59968abf0a4c974d7038f869848e71bd3a21b834422", + "vendor/fastnative/vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py": "2982ead07721e83358dc67c6f49c2b4c16a236a6bebdfd72f58221be1f5d0962", + "vendor/fastnative/vendor/native/new/code/borrow/vendor/pr2226_operators.py": "b37b67a04681c776dafcdc6c9af0e8a2dbfa9893b02e0fa2d77ccc9182a87988", + "vendor/fastnative/vendor/native/new/code/borrow/vendor/pr2226_replay.py": "0f9a47cdaeed0e22938c63251c232d6f23aeee2b62b0b1223cd4473c5428bcf7", + "vendor/fastnative/vendor/native/new/run_native_borrow.py": "8ec7db430f4f4771c06bdcfc31736193614f6ec209d57b63d4e2b75f17fb3ac8", + "vendor/fastnative/verify.py": "6dbdc56ca6cfde987869e12990a495d7eded78dd1887fb3fdf2d196060220fcc", + "vendor/preload_move.py": "c8fda4674644fcd5cbf39b6645ce148a21daa90a998b678cbe51f970b78b0044" +} diff --git a/research/two-sided-helper-extraction/README.md b/research/two-sided-helper-extraction/README.md new file mode 100644 index 0000000000..87f1421e9e --- /dev/null +++ b/research/two-sided-helper-extraction/README.md @@ -0,0 +1,90 @@ +# Two-sided helper extraction on PR2894 + +The explicit input/output basis change isolates helper408 as an additional +restored cold helper. Its width drops from 9 to 8, with one additional private +zero buffer. Both changed providers pass exact 632-input forward/dual audits +and the full five-stage native chain. A repaired T74 owner allocation gives + +**κ = 0.001720398337354237885931 − 10⁻⁴⁶ − 10⁻⁷⁰**, conditional on the inherited +supplier/outer theorem hypotheses. This is **+2.13808976768352857×10⁻⁷** +(about **0.0124%**) over [PR2894](https://github.com/CrocSwap/integer-mult-bounds/pull/2894) +at `18d03c447886895ef9abf888398178e0428533ca`. The selected repository result +is not changed. The exact headline and full release receipt are bound in +`CLAIM.json` and `evidence/`. + +This changes the local gate word and the cold-helper endpoint; the subsequent +owner repair is necessary to realize a gain. Keeping the old fill loses. +[CONSTRUCTION.md](CONSTRUCTION.md) explains the paired-nullspace identity and +complete cost changes. The method uses standard exact linear algebra; no +claim of a new general mathematical theorem or packing optimum is made. + +Credit: Jeremy Kothe's PR2894/2833 supplier and allocation, Yiyang Lu's PR2857 +shared-kernel/native/overlay work, Dugongue's PR2863 packing, Marius-Paul +Dumitrean's PR2843/2802 lineage, Philippe Van Velzen's PR2853 cost work, +Tekalign's admission/owner checkers, and the retained exact/native authors. +Our contribution is the helper408 extraction, independent structural +certificate, actual allocation repair and explicit 73-buffer integration. +See [CREDITS.md](CREDITS.md). Substantial OpenAI Codex assistance; no independent +human review is claimed. + +## Reproduce + +Tested on Linux, Python 3.12.3. The registered replay needs NumPy 2.5.4 and +runs the exact construction, semantic controls, both fresh native chains, +owner checks and rational moment. It authenticates the stored full-release +chain; it does not rerun complete integrated admission. + +```sh +python3.12 scripts/research_package.py --package research/two-sided-helper-extraction --check-only +python3.12 scripts/research_package.py --package research/two-sided-helper-extraction +``` + +For a direct local-only check (standard library, fresh output directory): + +```sh +python3.12 -B research/two-sided-helper-extraction/verify.py --work /tmp/helper408-local +python3.12 -B research/two-sided-helper-extraction/check_allocation.py --work /tmp/helper408-owners +``` + +For complete source/native/physical/outer admission, first obtain the exact +upstream Git objects. The driver exports them without changing the checkout +and verifies the complete predecessor manifest before executing its code. + +```sh +git fetch https://github.com/CrocSwap/integer-mult-bounds.git \ + 18d03c447886895ef9abf888398178e0428533ca \ + e9307b48d7d1b690939935ecef0f8e524e6d92f4 +nice -n 15 env OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 \ + python3.12 -B research/two-sided-helper-extraction/reproduce.py \ + --repo . --work /tmp/helper408-complete +``` + +Use the numerical dependencies recorded in `evidence/ENVIRONMENT.json` for the +complete inherited replay. Outputs must be fresh and external. The default +rebuilds the retained native/parent evidence. `--retained /path/to/prior-run` +explicitly reuses that run's `native-cache` and `NATIVE-RECEIPT.json`, only after +full source/claim/cache and all 16 parent stages are authenticated. The recorded +run reused retained evidence from our previous complete replay, and freshly +replayed both changed providers. It does not claim all retained work was fresh. +`--dry-run` only exports/authenticates PR2894 and writes the recipe. + +The integrated certificate uses 74 replicas, 666 calls, 271,728 helper roles, +66,304 live families and **66,795 physical families**, including all **73** +private zero buffers. The exact paid histogram includes every residual owner +child. All inherited phase, cleanup, prefix, stock, geometry, rejection and +outer checks remain required. No fractional packing estimate is used as a +certificate. + +## Open next questions + +1. Can a second independent paired input/output direction be extracted while + preserving helper408? Repeat the exact nullspace construction on the new + word, then charge its actual native and owner costs. A modular nominee or + local width reduction is insufficient. +2. Can a better literal allocation approach the new inventory's relaxation? + Start from the shipped feasible fill and test bounded exchanges or + relocations. Full exact admission remains mandatory for any higher claim. + +The structured questions, stopping rule and original task card are in +[TASK.json](TASK.json). Initial failed screens, solver timeouts and the +successful deterministic repair are summarized in `evidence/SEARCH.json`. diff --git a/research/two-sided-helper-extraction/SOURCES.json b/research/two-sided-helper-extraction/SOURCES.json new file mode 100644 index 0000000000..b9b9a1d41d --- /dev/null +++ b/research/two-sided-helper-extraction/SOURCES.json @@ -0,0 +1,18 @@ +{ + "schema_version": 1, + "base_commit": "572207084e5c2c21958969cc2e4c58fd4df8afb6", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "b1fea0c94436b236cc2b7d41a7be032811b94c81", + "sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "889b95d936746df124872133ae1e7cc339adcb92", + "sha256": "7d185cd8c2af35988d638d969748ad7b670f902606444dbfc748e4402c340df6" + } + ] +} diff --git a/research/two-sided-helper-extraction/TASK.json b/research/two-sided-helper-extraction/TASK.json new file mode 100644 index 0000000000..b5d6ee5e3f --- /dev/null +++ b/research/two-sided-helper-extraction/TASK.json @@ -0,0 +1,72 @@ +{ + "schema_version": 1, + "task_id": "complex-new-helper-inventory", + "priority_revision": 5, + "base_commit": "572207084e5c2c21958969cc2e4c58fd4df8afb6", + "original_card": { + "id": "complex-new-helper-inventory", + "question": "Can a new local cost interface change the deficit-to-recursive-cost ratio beyond current packing?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/complex-local-word-ceiling/README.md", + "research/heterogeneous-owner-assembly/README.md", + "certificates/selected-result.json", + "research/selected-k8-unrestricted-ends/README.md" + ], + "methods": [ + "Propose a changed helper inventory and derive an optimistic exact moment.", + "Design a small completed instance and independently verify its endpoint and rank bill." + ], + "acceptance_gate": "A new physically realizable contract outside the frozen catalogue whose per-call profile, screened with ceiling.ceiling(), beats the selected word's packing ceiling; a lower cap does not establish identical circuitry or order attainable optima, and is insufficient to pass the stronger-budget target under this model. A scoped local result may be retained without a complete supplier. Expanding it into further construction rounds requires the family-level budget and obligation gate in research-family-status.md; an optimistic passing relaxation alone is not acceptance.", + "first_step": { + "command": [ + "python3", + "-B", + "research/complex-local-word-ceiling/verify.py" + ], + "expected": "PASS_COMPLEX_LOCAL_WORD_CEILING", + "inspect": "Read the selected word's per-call local profile, its packing ceiling and the lever table; run levers.py for the ideal budget of the lever you target.", + "scope": "Positive control and planning budget only; this is not a new construction or full cold replay." + }, + "first_experiment": "Before any synthesis, write the candidate per-call local profile (and centre charge / unpaid coordinates if changed) and screen it with ceiling.ceiling(); reject it if even the ideal ceiling does not beat the selected word's by your stated margin.", + "bottleneck_link": "Packing of the selected word is capped at +0.87% (ceiling model); only a lower local excess spend or a changed coverage law raises the cap.", + "allowed_variations": [ + "Narrow to one changed boundary or helper type with explicit counts.", + "If the coverage law, template or guard changes, derive an applicable fully charged replacement bound instead of applying the incumbent ceiling outside its scope." + ], + "scope_change_triggers": [ + "Mixing only providers already inside the pinned catalogue.", + "Only changing helper terminal subspaces and monotone frames within the fixed scalar word, entrances and cleanup contract already covered by #1995/#2013.", + "Continuing a partial cost improvement while leaving the same unpriced consumer, restoration or central-readout obligation unresolved; refresh the family expansion decision first. Local product-retiming evidence has a narrow scope and is not a ban on changed graphs or contracts." + ], + "overlap_terms": [ + "helper inventory", + "heterogeneous-owner", + "mutable leaver" + ] + }, + "scope_status": "refined", + "actual_scope": "Two-sided dyadic basis changes extracting one additional cold helper from the PR2894 non-target operator; exact local/native audits, actual T74 hosting and complete outer accounting.", + "scope_change_reason": "Direct compensation-kernel/first-frame screens yielded no admissible extension; allowing a coupled input/output basis change changes the local helper endpoint and literal gate word outside fixed-gate entry/refit screens.", + "bottleneck_link": "A smaller helper width alone is not profitable: the full budget includes local delta3H1-2H2, an additional private zero buffer, actual owner residuals and all outer costs.", + "budget_minutes": 60, + "stop_rule": "Promote only if exact local/native/owner/outer checks all pass and the fully charged value beats pinned PR2894; otherwise publish the scoped construction and unresolved admission.", + "outcome": "completed", + "evidence": "CLAIM.json, evidence/ADMISSION-RESULT.json, RELEASE-RECEIPT.json, FULL-NATIVE-RECEIPT.json, EXACT-OWNER-MOMENT.json; registered and full replay commands in README.", + "author": "Jeremy Diviney", + "ai_assistance": "Substantial OpenAI Codex assistance for exact algebra, optimized NumPy/SciPy nomination, deterministic owner repair, implementation and verification. No subagents used.", + "open_questions": [ + { + "question": "Can a second independent input/output channel be isolated without spoiling the first?", + "why_it_matters": "The exact subspace screen retains more than one paired direction; an additional recovered helper could further change the paid profile.", + "first_step": "Repeat the exact paired-nullspace construction after helper408, then compare the complete local and actual idle budgets.", + "blocked_by": "Both provider native checks and a newly charged owner/stock/outer certificate for any composed word." + }, + { + "question": "How much of the new inventory packing relaxation can be attained?", + "why_it_matters": "The exhibited repair leaves residues and does not claim optimality.", + "first_step": "Use the shipped literal fill as a feasible seed for bounded width exchanges/relocations; recheck actual windows and families.", + "blocked_by": "Any candidate needs complete exact outer admission; a fractional root alone is not a new bound." + } + ] +} diff --git a/research/two-sided-helper-extraction/VERIFY.json b/research/two-sided-helper-extraction/VERIFY.json new file mode 100644 index 0000000000..6643b2df33 --- /dev/null +++ b/research/two-sided-helper-extraction/VERIFY.json @@ -0,0 +1,12 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": ["numpy==2.5.4"], + "inputs": [], + "commands": [{ + "argv": ["{python}", "-B", "{package}/run_registered.py"], + "timeout_seconds": 300, + "checks": "Complete package/vendor/data pins; exact source-stage and two-sided subspace identities; both 632-input abstract forward/dual audits and four semantic mutations; fresh five-stage native chains for both words (all-column, phases, cleanup, rejection controls); actual T74 owner geometry plus mutations and directed rational moment; stored complete release/native receipt chain. Full integrated outer/retained replay is a separate reproduce.py command." + }] +} diff --git a/research/two-sided-helper-extraction/allocation/DISPATCH.json b/research/two-sided-helper-extraction/allocation/DISPATCH.json new file mode 100644 index 0000000000..9544fee4e6 --- /dev/null +++ b/research/two-sided-helper-extraction/allocation/DISPATCH.json @@ -0,0 +1 @@ +[[0,0,"extra"],[0,37,"extra"],[0,1,"extra"],[0,38,"extra"],[0,2,"extra"],[0,39,"extra"],[0,3,"extra"],[0,40,"extra"],[0,4,"extra"],[0,41,"extra"],[1,0,"extra"],[1,37,"extra"],[0,5,"extra"],[0,42,"extra"],[1,1,"extra"],[1,38,"extra"],[0,6,"extra"],[0,43,"extra"],[1,2,"extra"],[1,39,"extra"],[0,7,"extra"],[0,44,"extra"],[1,3,"extra"],[1,40,"extra"],[0,8,"extra"],[0,45,"extra"],[1,4,"extra"],[1,41,"extra"],[0,9,"extra"],[0,46,"extra"],[2,0,"extra"],[2,37,"extra"],[1,5,"extra"],[1,42,"extra"],[0,10,"extra"],[0,47,"extra"],[2,1,"extra"],[2,38,"extra"],[1,6,"extra"],[1,43,"extra"],[0,11,"extra"],[0,48,"extra"],[2,2,"extra"],[2,39,"extra"],[1,7,"extra"],[1,44,"extra"],[0,12,"extra"],[0,49,"extra"],[2,3,"extra"],[2,40,"extra"],[1,8,"extra"],[1,45,"extra"],[0,13,"extra"],[0,50,"extra"],[2,4,"extra"],[2,41,"extra"],[1,9,"extra"],[1,46,"extra"],[3,0,"extra"],[3,37,"extra"],[0,14,"extra"],[0,51,"extra"],[2,5,"extra"],[2,42,"extra"],[1,10,"extra"],[1,47,"extra"],[3,1,"extra"],[3,38,"extra"],[0,15,"extra"],[0,52,"extra"],[2,6,"extra"],[2,43,"extra"],[1,11,"extra"],[1,48,"extra"],[3,2,"extra"],[3,39,"extra"],[0,16,"extra"],[0,53,"extra"],[2,7,"extra"],[2,44,"extra"],[1,12,"extra"],[1,49,"extra"],[3,3,"extra"],[3,40,"extra"],[0,17,"extra"],[0,54,"extra"],[2,8,"extra"],[2,45,"extra"],[1,13,"extra"],[1,50,"extra"],[3,4,"extra"],[3,41,"extra"],[0,18,"extra"],[0,55,"extra"],[2,9,"extra"],[2,46,"extra"],[4,0,"extra"],[4,37,"extra"],[1,14,"extra"],[1,51,"extra"],[3,5,"extra"],[3,42,"extra"],[0,19,"extra"],[0,56,"extra"],[2,10,"extra"],[2,47,"extra"],[4,1,"extra"],[4,38,"extra"],[1,15,"extra"],[1,52,"extra"],[3,6,"extra"],[3,43,"extra"],[0,20,"extra"],[0,57,"extra"],[2,11,"extra"],[2,48,"extra"],[4,2,"extra"],[4,39,"extra"],[1,16,"extra"],[1,53,"extra"],[3,7,"extra"],[3,44,"extra"],[0,21,"extra"],[0,58,"extra"],[2,12,"extra"],[2,49,"extra"],[4,3,"extra"],[4,40,"extra"],[1,17,"extra"],[1,54,"extra"],[3,8,"extra"],[3,45,"extra"],[0,22,"extra"],[0,59,"extra"],[2,13,"extra"],[2,50,"extra"],[4,4,"extra"],[4,41,"extra"],[1,18,"extra"],[1,55,"extra"],[3,9,"extra"],[3,46,"extra"],[0,23,"extra"],[0,60,"extra"],[5,0,"extra"],[5,37,"extra"],[2,14,"extra"],[2,51,"extra"],[4,5,"extra"],[4,42,"extra"],[1,19,"extra"],[1,56,"extra"],[3,10,"extra"],[3,47,"extra"],[0,24,"extra"],[0,61,"extra"],[5,1,"extra"],[5,38,"extra"],[2,15,"extra"],[2,52,"extra"],[4,6,"extra"],[4,43,"extra"],[1,20,"extra"],[1,57,"extra"],[3,11,"extra"],[3,48,"extra"],[0,25,"extra"],[0,62,"extra"],[5,2,"extra"],[5,39,"extra"],[2,16,"extra"],[2,53,"extra"],[4,7,"extra"],[4,44,"extra"],[1,21,"extra"],[1,58,"extra"],[3,12,"extra"],[3,49,"extra"],[0,26,"extra"],[0,63,"extra"],[5,3,"extra"],[5,40,"extra"],[2,17,"extra"],[2,54,"extra"],[4,8,"extra"],[4,45,"extra"],[1,22,"extra"],[1,59,"extra"],[3,13,"extra"],[3,50,"extra"],[0,27,"extra"],[0,64,"extra"],[5,4,"extra"],[5,41,"extra"],[2,18,"extra"],[2,55,"extra"],[4,9,"extra"],[4,46,"extra"],[1,23,"extra"],[1,60,"extra"],[6,0,"extra"],[6,37,"extra"],[3,14,"extra"],[3,51,"extra"],[0,28,"extra"],[0,65,"extra"],[5,5,"extra"],[5,42,"extra"],[2,19,"extra"],[2,56,"extra"],[4,10,"extra"],[4,47,"extra"],[1,24,"extra"],[1,61,"extra"],[6,1,"extra"],[6,38,"extra"],[3,15,"extra"],[3,52,"extra"],[0,29,"extra"],[0,66,"extra"],[5,6,"extra"],[5,43,"extra"],[2,20,"extra"],[2,57,"extra"],[4,11,"extra"],[4,48,"extra"],[1,25,"extra"],[1,62,"extra"],[6,2,"extra"],[6,39,"extra"],[3,16,"extra"],[3,53,"extra"],[0,30,"extra"],[0,67,"extra"],[5,7,"extra"],[5,44,"extra"],[2,21,"extra"],[2,58,"extra"],[4,12,"extra"],[4,49,"extra"],[1,26,"extra"],[1,63,"extra"],[6,3,"extra"],[6,40,"extra"],[3,17,"extra"],[3,54,"extra"],[0,31,"extra"],[0,68,"extra"],[5,8,"extra"],[5,45,"extra"],[2,22,"extra"],[2,59,"extra"],[4,13,"extra"],[4,50,"extra"],[1,27,"extra"],[1,64,"extra"],[6,4,"extra"],[6,41,"extra"],[3,18,"extra"],[3,55,"extra"],[0,32,"extra"],[0,69,"extra"],[5,9,"extra"],[5,46,"extra"],[2,23,"extra"],[2,60,"extra"],[7,0,"extra"],[7,37,"extra"],[4,14,"extra"],[4,51,"extra"],[1,28,"extra"],[1,65,"extra"],[6,5,"extra"],[6,42,"extra"],[3,19,"extra"],[3,56,"extra"],[0,33,"extra"],[0,70,"extra"],[5,10,"extra"],[5,47,"extra"],[2,24,"extra"],[2,61,"extra"],[7,1,"extra"],[7,38,"extra"],[4,15,"extra"],[4,52,"extra"],[1,29,"extra"],[1,66,"extra"],[6,6,"extra"],[6,43,"extra"],[3,20,"extra"],[3,57,"extra"],[0,34,"extra"],[0,71,"extra"],[5,11,"extra"],[5,48,"extra"],[2,25,"extra"],[2,62,"extra"],[7,2,"extra"],[7,39,"extra"],[4,16,"extra"],[4,53,"extra"],[1,30,"extra"],[1,67,"extra"],[6,7,"extra"],[6,44,"extra"],[3,21,"extra"],[3,58,"extra"],[0,35,"extra"],[0,72,"extra"],[5,12,"extra"],[5,49,"extra"],[2,26,"extra"],[2,63,"extra"],[7,3,"extra"],[7,40,"extra"],[4,17,"extra"],[4,54,"extra"],[1,31,"extra"],[1,68,"extra"],[6,8,"extra"],[6,45,"extra"],[3,22,"extra"],[3,59,"extra"],[0,36,"extra"],[0,73,"extra"],[5,13,"extra"],[5,50,"extra"],[2,27,"extra"],[2,64,"extra"],[7,4,"extra"],[7,41,"extra"],[4,18,"extra"],[4,55,"extra"],[1,32,"extra"],[1,69,"extra"],[6,9,"extra"],[6,46,"extra"],[3,23,"extra"],[3,60,"extra"],[8,0,"extra"],[8,37,"extra"],[5,14,"extra"],[5,51,"extra"],[2,28,"extra"],[2,65,"extra"],[7,5,"extra"],[7,42,"extra"],[4,19,"extra"],[4,56,"extra"],[1,33,"extra"],[1,70,"extra"],[6,10,"extra"],[6,47,"extra"],[3,24,"extra"],[3,61,"extra"],[8,1,"extra"],[8,38,"extra"],[5,15,"extra"],[5,52,"extra"],[2,29,"extra"],[2,66,"extra"],[7,6,"extra"],[7,43,"extra"],[4,20,"extra"],[4,57,"extra"],[1,34,"extra"],[1,71,"extra"],[6,11,"extra"],[6,48,"extra"],[3,25,"extra"],[3,62,"extra"],[8,2,"extra"],[8,39,"extra"],[5,16,"extra"],[5,53,"extra"],[2,30,"extra"],[2,67,"extra"],[7,7,"extra"],[7,44,"extra"],[4,21,"extra"],[4,58,"extra"],[1,35,"extra"],[1,72,"extra"],[6,12,"extra"],[6,49,"extra"],[3,26,"extra"],[3,63,"extra"],[8,3,"extra"],[8,40,"extra"],[5,17,"extra"],[5,54,"extra"],[2,31,"extra"],[2,68,"extra"],[7,8,"extra"],[7,45,"extra"],[4,22,"extra"],[4,59,"extra"],[1,36,"extra"],[1,73,"extra"],[6,13,"extra"],[6,50,"extra"],[3,27,"extra"],[3,64,"extra"],[8,4,"extra"],[8,41,"extra"],[5,18,"extra"],[5,55,"extra"],[2,32,"extra"],[2,69,"extra"],[7,9,"extra"],[7,46,"extra"],[4,23,"extra"],[4,60,"extra"],[6,14,"extra"],[6,51,"extra"],[3,28,"gauge44"],[3,65,"gauge44"],[8,5,"gauge44"],[8,42,"gauge44"],[5,19,"gauge44"],[5,56,"gauge44"],[2,33,"gauge44"],[2,70,"gauge44"],[7,10,"gauge44"],[7,47,"gauge44"],[4,24,"gauge44"],[4,61,"gauge44"],[6,15,"gauge44"],[6,52,"gauge44"],[3,29,"gauge44"],[3,66,"gauge44"],[8,6,"gauge44"],[8,43,"gauge44"],[5,20,"gauge44"],[5,57,"gauge44"],[2,34,"gauge44"],[2,71,"gauge44"],[7,11,"gauge44"],[7,48,"gauge44"],[4,25,"gauge44"],[4,62,"gauge44"],[6,16,"gauge44"],[6,53,"gauge44"],[3,30,"gauge44"],[3,67,"gauge44"],[8,7,"gauge44"],[8,44,"gauge44"],[5,21,"gauge44"],[5,58,"gauge44"],[2,35,"gauge44"],[2,72,"gauge44"],[7,12,"gauge44"],[7,49,"gauge44"],[4,26,"gauge44"],[4,63,"gauge44"],[6,17,"gauge44"],[6,54,"gauge44"],[3,31,"gauge44"],[3,68,"gauge44"],[8,8,"gauge44"],[8,45,"gauge44"],[5,22,"gauge44"],[5,59,"gauge44"],[2,36,"gauge44"],[2,73,"gauge44"],[7,13,"gauge44"],[7,50,"gauge44"],[4,27,"gauge44"],[4,64,"gauge44"],[6,18,"gauge44"],[6,55,"gauge44"],[3,32,"gauge44"],[3,69,"gauge44"],[8,9,"gauge44"],[8,46,"gauge44"],[5,23,"gauge44"],[5,60,"gauge44"],[7,14,"gauge44"],[7,51,"gauge44"],[4,28,"gauge44"],[4,65,"gauge44"],[6,19,"gauge44"],[6,56,"gauge44"],[3,33,"gauge44"],[3,70,"gauge44"],[8,10,"gauge44"],[8,47,"gauge44"],[5,24,"gauge44"],[5,61,"gauge44"],[7,15,"gauge44"],[7,52,"gauge44"],[4,29,"gauge44"],[4,66,"gauge44"],[6,20,"gauge44"],[6,57,"gauge44"],[3,34,"gauge44"],[3,71,"gauge44"],[8,11,"gauge44"],[8,48,"gauge44"],[5,25,"gauge44"],[5,62,"gauge44"],[7,16,"gauge44"],[7,53,"gauge44"],[4,30,"gauge44"],[4,67,"gauge44"],[6,21,"gauge44"],[6,58,"gauge44"],[3,35,"gauge44"],[3,72,"gauge44"],[8,12,"gauge44"],[8,49,"gauge44"],[5,26,"gauge44"],[5,63,"gauge44"],[7,17,"gauge44"],[7,54,"gauge44"],[4,31,"gauge44"],[4,68,"gauge44"],[6,22,"gauge44"],[6,59,"gauge44"],[3,36,"gauge44"],[3,73,"gauge44"],[8,13,"gauge44"],[8,50,"gauge44"],[5,27,"gauge44"],[5,64,"gauge44"],[7,18,"gauge44"],[7,55,"gauge44"],[4,32,"gauge44"],[4,69,"gauge44"],[6,23,"gauge44"],[6,60,"gauge44"],[8,14,"gauge44"],[8,51,"gauge44"],[5,28,"gauge44"],[5,65,"gauge44"],[7,19,"gauge44"],[7,56,"gauge44"],[4,33,"gauge44"],[4,70,"gauge44"],[6,24,"gauge44"],[6,61,"gauge44"],[8,15,"gauge44"],[8,52,"gauge44"],[5,29,"gauge44"],[5,66,"gauge44"],[7,20,"gauge44"],[7,57,"gauge44"],[4,34,"gauge44"],[4,71,"gauge44"],[6,25,"gauge44"],[6,62,"gauge44"],[8,16,"gauge44"],[8,53,"gauge44"],[5,30,"gauge44"],[5,67,"gauge44"],[7,21,"gauge44"],[7,58,"gauge44"],[4,35,"gauge44"],[4,72,"gauge44"],[6,26,"gauge44"],[6,63,"gauge44"],[8,17,"gauge44"],[8,54,"gauge44"],[5,31,"gauge44"],[5,68,"gauge44"],[7,22,"gauge44"],[7,59,"gauge44"],[4,36,"gauge44"],[4,73,"gauge44"],[6,27,"gauge44"],[6,64,"gauge44"],[8,18,"gauge44"],[8,55,"gauge44"],[5,32,"gauge44"],[5,69,"gauge44"],[7,23,"gauge44"],[7,60,"gauge44"],[6,28,"gauge44"],[6,65,"gauge44"],[8,19,"gauge44"],[8,56,"gauge44"],[5,33,"gauge44"],[5,70,"gauge44"],[7,24,"gauge44"],[7,61,"gauge44"],[6,29,"gauge44"],[6,66,"gauge44"],[8,20,"gauge44"],[8,57,"gauge44"],[5,34,"gauge44"],[5,71,"gauge44"],[7,25,"gauge44"],[7,62,"gauge44"],[6,30,"gauge44"],[6,67,"gauge44"],[8,21,"gauge44"],[8,58,"gauge44"],[5,35,"gauge44"],[5,72,"gauge44"],[7,26,"gauge44"],[7,63,"gauge44"],[6,31,"gauge44"],[6,68,"gauge44"],[8,22,"gauge44"],[8,59,"gauge44"],[5,36,"gauge44"],[5,73,"gauge44"],[7,27,"gauge44"],[7,64,"gauge44"],[6,32,"gauge44"],[6,69,"gauge44"],[8,23,"gauge44"],[8,60,"gauge44"],[7,28,"gauge44"],[7,65,"gauge44"],[6,33,"gauge44"],[6,70,"gauge44"],[8,24,"gauge44"],[8,61,"gauge44"],[7,29,"gauge44"],[7,66,"gauge44"],[6,34,"gauge44"],[6,71,"gauge44"],[8,25,"gauge44"],[8,62,"gauge44"],[7,30,"gauge44"],[7,67,"gauge44"],[6,35,"gauge44"],[6,72,"gauge44"],[8,26,"gauge44"],[8,63,"gauge44"],[7,31,"gauge44"],[7,68,"gauge44"],[6,36,"gauge44"],[6,73,"gauge44"],[8,27,"gauge44"],[8,64,"gauge44"],[7,32,"gauge44"],[7,69,"gauge44"],[8,28,"gauge44"],[8,65,"gauge44"],[7,33,"gauge44"],[7,70,"gauge44"],[8,29,"gauge44"],[8,66,"gauge44"],[7,34,"gauge44"],[7,71,"gauge44"],[8,30,"gauge44"],[8,67,"gauge44"],[7,35,"gauge44"],[7,72,"gauge44"],[8,31,"gauge44"],[8,68,"gauge44"],[7,36,"gauge44"],[7,73,"gauge44"],[8,32,"gauge44"],[8,69,"gauge44"],[8,33,"gauge44"],[8,70,"gauge44"],[8,34,"gauge44"],[8,71,"gauge44"],[8,35,"gauge44"],[8,72,"gauge44"],[8,36,"gauge44"],[8,73,"gauge44"]] \ No newline at end of file diff --git a/research/two-sided-helper-extraction/allocation/FILL.json.gz b/research/two-sided-helper-extraction/allocation/FILL.json.gz new file mode 100644 index 0000000000..68b0b7f7df Binary files /dev/null and b/research/two-sided-helper-extraction/allocation/FILL.json.gz differ diff --git a/research/two-sided-helper-extraction/allocation/ORDER.json b/research/two-sided-helper-extraction/allocation/ORDER.json new file mode 100644 index 0000000000..7409c4df10 --- /dev/null +++ b/research/two-sided-helper-extraction/allocation/ORDER.json @@ -0,0 +1 @@ +[[0,0],[0,37],[0,1],[0,38],[0,2],[0,39],[0,3],[0,40],[0,4],[0,41],[1,0],[1,37],[0,5],[0,42],[1,1],[1,38],[0,6],[0,43],[1,2],[1,39],[0,7],[0,44],[1,3],[1,40],[0,8],[0,45],[1,4],[1,41],[0,9],[0,46],[2,0],[2,37],[1,5],[1,42],[0,10],[0,47],[2,1],[2,38],[1,6],[1,43],[0,11],[0,48],[2,2],[2,39],[1,7],[1,44],[0,12],[0,49],[2,3],[2,40],[1,8],[1,45],[0,13],[0,50],[2,4],[2,41],[1,9],[1,46],[3,0],[3,37],[0,14],[0,51],[2,5],[2,42],[1,10],[1,47],[3,1],[3,38],[0,15],[0,52],[2,6],[2,43],[1,11],[1,48],[3,2],[3,39],[0,16],[0,53],[2,7],[2,44],[1,12],[1,49],[3,3],[3,40],[0,17],[0,54],[2,8],[2,45],[1,13],[1,50],[3,4],[3,41],[0,18],[0,55],[2,9],[2,46],[4,0],[4,37],[1,14],[1,51],[3,5],[3,42],[0,19],[0,56],[2,10],[2,47],[4,1],[4,38],[1,15],[1,52],[3,6],[3,43],[0,20],[0,57],[2,11],[2,48],[4,2],[4,39],[1,16],[1,53],[3,7],[3,44],[0,21],[0,58],[2,12],[2,49],[4,3],[4,40],[1,17],[1,54],[3,8],[3,45],[0,22],[0,59],[2,13],[2,50],[4,4],[4,41],[1,18],[1,55],[3,9],[3,46],[0,23],[0,60],[5,0],[5,37],[2,14],[2,51],[4,5],[4,42],[1,19],[1,56],[3,10],[3,47],[0,24],[0,61],[5,1],[5,38],[2,15],[2,52],[4,6],[4,43],[1,20],[1,57],[3,11],[3,48],[0,25],[0,62],[5,2],[5,39],[2,16],[2,53],[4,7],[4,44],[1,21],[1,58],[3,12],[3,49],[0,26],[0,63],[5,3],[5,40],[2,17],[2,54],[4,8],[4,45],[1,22],[1,59],[3,13],[3,50],[0,27],[0,64],[5,4],[5,41],[2,18],[2,55],[4,9],[4,46],[1,23],[1,60],[6,0],[6,37],[3,14],[3,51],[0,28],[0,65],[5,5],[5,42],[2,19],[2,56],[4,10],[4,47],[1,24],[1,61],[6,1],[6,38],[3,15],[3,52],[0,29],[0,66],[5,6],[5,43],[2,20],[2,57],[4,11],[4,48],[1,25],[1,62],[6,2],[6,39],[3,16],[3,53],[0,30],[0,67],[5,7],[5,44],[2,21],[2,58],[4,12],[4,49],[1,26],[1,63],[6,3],[6,40],[3,17],[3,54],[0,31],[0,68],[5,8],[5,45],[2,22],[2,59],[4,13],[4,50],[1,27],[1,64],[6,4],[6,41],[3,18],[3,55],[0,32],[0,69],[5,9],[5,46],[2,23],[2,60],[7,0],[7,37],[4,14],[4,51],[1,28],[1,65],[6,5],[6,42],[3,19],[3,56],[0,33],[0,70],[5,10],[5,47],[2,24],[2,61],[7,1],[7,38],[4,15],[4,52],[1,29],[1,66],[6,6],[6,43],[3,20],[3,57],[0,34],[0,71],[5,11],[5,48],[2,25],[2,62],[7,2],[7,39],[4,16],[4,53],[1,30],[1,67],[6,7],[6,44],[3,21],[3,58],[0,35],[0,72],[5,12],[5,49],[2,26],[2,63],[7,3],[7,40],[4,17],[4,54],[1,31],[1,68],[6,8],[6,45],[3,22],[3,59],[0,36],[0,73],[5,13],[5,50],[2,27],[2,64],[7,4],[7,41],[4,18],[4,55],[1,32],[1,69],[6,9],[6,46],[3,23],[3,60],[8,0],[8,37],[5,14],[5,51],[2,28],[2,65],[7,5],[7,42],[4,19],[4,56],[1,33],[1,70],[6,10],[6,47],[3,24],[3,61],[8,1],[8,38],[5,15],[5,52],[2,29],[2,66],[7,6],[7,43],[4,20],[4,57],[1,34],[1,71],[6,11],[6,48],[3,25],[3,62],[8,2],[8,39],[5,16],[5,53],[2,30],[2,67],[7,7],[7,44],[4,21],[4,58],[1,35],[1,72],[6,12],[6,49],[3,26],[3,63],[8,3],[8,40],[5,17],[5,54],[2,31],[2,68],[7,8],[7,45],[4,22],[4,59],[1,36],[1,73],[6,13],[6,50],[3,27],[3,64],[8,4],[8,41],[5,18],[5,55],[2,32],[2,69],[7,9],[7,46],[4,23],[4,60],[6,14],[6,51],[3,28],[3,65],[8,5],[8,42],[5,19],[5,56],[2,33],[2,70],[7,10],[7,47],[4,24],[4,61],[6,15],[6,52],[3,29],[3,66],[8,6],[8,43],[5,20],[5,57],[2,34],[2,71],[7,11],[7,48],[4,25],[4,62],[6,16],[6,53],[3,30],[3,67],[8,7],[8,44],[5,21],[5,58],[2,35],[2,72],[7,12],[7,49],[4,26],[4,63],[6,17],[6,54],[3,31],[3,68],[8,8],[8,45],[5,22],[5,59],[2,36],[2,73],[7,13],[7,50],[4,27],[4,64],[6,18],[6,55],[3,32],[3,69],[8,9],[8,46],[5,23],[5,60],[7,14],[7,51],[4,28],[4,65],[6,19],[6,56],[3,33],[3,70],[8,10],[8,47],[5,24],[5,61],[7,15],[7,52],[4,29],[4,66],[6,20],[6,57],[3,34],[3,71],[8,11],[8,48],[5,25],[5,62],[7,16],[7,53],[4,30],[4,67],[6,21],[6,58],[3,35],[3,72],[8,12],[8,49],[5,26],[5,63],[7,17],[7,54],[4,31],[4,68],[6,22],[6,59],[3,36],[3,73],[8,13],[8,50],[5,27],[5,64],[7,18],[7,55],[4,32],[4,69],[6,23],[6,60],[8,14],[8,51],[5,28],[5,65],[7,19],[7,56],[4,33],[4,70],[6,24],[6,61],[8,15],[8,52],[5,29],[5,66],[7,20],[7,57],[4,34],[4,71],[6,25],[6,62],[8,16],[8,53],[5,30],[5,67],[7,21],[7,58],[4,35],[4,72],[6,26],[6,63],[8,17],[8,54],[5,31],[5,68],[7,22],[7,59],[4,36],[4,73],[6,27],[6,64],[8,18],[8,55],[5,32],[5,69],[7,23],[7,60],[6,28],[6,65],[8,19],[8,56],[5,33],[5,70],[7,24],[7,61],[6,29],[6,66],[8,20],[8,57],[5,34],[5,71],[7,25],[7,62],[6,30],[6,67],[8,21],[8,58],[5,35],[5,72],[7,26],[7,63],[6,31],[6,68],[8,22],[8,59],[5,36],[5,73],[7,27],[7,64],[6,32],[6,69],[8,23],[8,60],[7,28],[7,65],[6,33],[6,70],[8,24],[8,61],[7,29],[7,66],[6,34],[6,71],[8,25],[8,62],[7,30],[7,67],[6,35],[6,72],[8,26],[8,63],[7,31],[7,68],[6,36],[6,73],[8,27],[8,64],[7,32],[7,69],[8,28],[8,65],[7,33],[7,70],[8,29],[8,66],[7,34],[7,71],[8,30],[8,67],[7,35],[7,72],[8,31],[8,68],[7,36],[7,73],[8,32],[8,69],[8,33],[8,70],[8,34],[8,71],[8,35],[8,72],[8,36],[8,73]] \ No newline at end of file diff --git a/research/two-sided-helper-extraction/allocation/PROFILE.json b/research/two-sided-helper-extraction/allocation/PROFILE.json new file mode 100644 index 0000000000..916437d9e1 --- /dev/null +++ b/research/two-sided-helper-extraction/allocation/PROFILE.json @@ -0,0 +1 @@ +{"1":1620344,"2":426241,"3":180732,"4":85248,"5":25700,"6":120,"7":1,"8":5328,"23":1,"32":14,"48":26837} \ No newline at end of file diff --git a/research/two-sided-helper-extraction/allocation/PROVIDERS.json b/research/two-sided-helper-extraction/allocation/PROVIDERS.json new file mode 100644 index 0000000000..45de4bc33f --- /dev/null +++ b/research/two-sided-helper-extraction/allocation/PROVIDERS.json @@ -0,0 +1 @@ +{"extra":{"actual_paid_profile":{"1":2407,"2":640,"3":262,"4":128,"5":26,"8":8},"widths":[9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4,9,9,9,9,4,9,9,9,9,9,9,9,9,9,9,4,9,9,9,9,4,9,9,9,9,9,9,9,9,4,9,4,9,8,9,9,4,9,9,9,9,9,9,9,9,4,9,4,9,8,9,9,4,9,9,9,9,9,9,4,9,4,9,4,9,9,9,9,4,9,9,9,9,9,9,4,9,4,9,4,9,9,9,9,4,9,9,9,9,9,9,4,9,4,9,4,9,9,9,9,4,9,9,9,9,9,9,4,9,4,9,4,9,9,9,9,4,9,9,9,9,9,9,9,9,9,9,9,9,9,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,7,7,7,7,7,7,7,7,9,8,8,9,8,9,8,9,9,9,9,9,9,9,9,9,8,8,7,7,7,7,8,9,8,9,7,7,7,7,7,7,9,9,9,9,8,8,8,9,8,8,9,9,9,9,8,7,7,8,9,8,8,9,9,9,9,8,8,8,7,7,7,7,7,7,7,7,8,7,7,7,7,7,7,7,7,7,7,7,8,7,8,8,9,9,9,9,8,8,8,8,7,7,7,7,9,8,9,8,8,8,8,8,7,7,9,8,9,8,7,7,7,7,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,5,5,8,8,8,8]},"gauge44":{"actual_paid_profile":{"1":2407,"2":640,"3":262,"4":128,"5":26,"8":8},"widths":[9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4,9,9,9,9,4,9,9,9,9,9,9,9,9,9,9,4,9,9,9,9,4,9,9,9,9,9,9,9,9,4,9,4,9,8,9,9,4,9,9,9,9,9,9,9,9,4,9,4,9,8,9,9,4,9,9,9,9,9,9,4,9,4,9,4,9,9,9,9,4,9,9,9,9,9,9,4,9,4,9,4,9,9,9,9,4,9,9,9,9,9,9,4,9,4,9,4,9,9,9,9,4,9,9,9,9,9,9,4,9,4,9,4,9,9,9,9,4,9,9,9,9,9,9,9,9,9,9,9,9,9,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,7,7,7,7,7,7,7,7,9,8,8,9,8,9,8,9,9,9,9,9,9,9,9,9,8,8,7,7,7,7,8,9,8,9,7,7,7,7,7,7,9,9,9,9,8,8,8,9,8,8,9,9,9,9,8,7,7,8,9,8,8,9,9,9,9,8,8,8,7,7,7,7,7,7,7,7,8,7,7,7,7,7,7,7,7,7,7,7,8,7,8,8,9,9,9,9,8,8,8,8,7,7,7,7,9,8,9,8,8,8,8,8,7,7,9,8,9,8,7,7,7,7,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,5,5,8,8,8,8]}} \ No newline at end of file diff --git a/research/two-sided-helper-extraction/allocation/RESULT.json b/research/two-sided-helper-extraction/allocation/RESULT.json new file mode 100644 index 0000000000..325169cd4c --- /dev/null +++ b/research/two-sided-helper-extraction/allocation/RESULT.json @@ -0,0 +1 @@ +{"calls":666,"floating_root":0.0017203983373542838,"idle":{"1":17282,"2":1,"3":6240,"5":8384,"6":120,"7":1,"23":1,"32":14,"48":26837},"live":66304,"physical":66795,"physical_scope":"actual helper408 buffer count; whole outer invoice not yet admitted","profile":{"1":1620344,"2":426241,"3":180732,"4":85248,"5":25700,"6":120,"7":1,"8":5328,"23":1,"32":14,"48":26837},"rank_mass":4816512,"replicas":74,"roles":271728,"status":"PASS_INDEPENDENT_OWNER_CHECK_FLOATING_PRICE_ONLY"} \ No newline at end of file diff --git a/research/two-sided-helper-extraction/allocation/baseline/CLAIM.json b/research/two-sided-helper-extraction/allocation/baseline/CLAIM.json new file mode 100644 index 0000000000..7a0f12d1df --- /dev/null +++ b/research/two-sided-helper-extraction/allocation/baseline/CLAIM.json @@ -0,0 +1,39 @@ +{ + "admission_result_sha256": "e8ec9091be8e6c20752fdc9e9904870f60303fba7194af029a16498afdc7f318", + "baseline_claim_sha256": "c2a04b639c86f462caef654a29817545c57b8e5ba809e37d4d476d3577f5cd6f", + "baseline_head": "0b2e2537b368a0cade07ce3f71452ea018ebe394", + "baseline_kappa": "17200966286848326009719999999999999999999998999999999999999999999999/10000000000000000000000000000000000000000000000000000000000000000000000", + "baseline_pr": 2857, + "calls": 666, + "display": "0.001720184528377469533074 - 10^-46 - 10^-70", + "gain_decimal_over_pr2875": "8.372296058360512999292439366446879999990E-8", + "gain_over_full_pr2857": "43949846318466051/500000000000000000000000", + "gain_over_pr2863": "8372296058360513/100000000000000000000000", + "gain_over_pr2875": "8372296058360512999292439366446879999990000000000000000999999990000000000000001/100000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "helper_roles": 271728, + "inherited_hypotheses": "All-size compiler; common-label/source access; mutable source; hosting; precision/tape; recovery; ordinary recursion; BIT; analytic transfer. No new Lean audit or unconditional multiplication theorem.", + "kappa": "17201845283774695330739999999999999999999998999999999999999999999999/10000000000000000000000000000000000000000000000000000000000000000000000", + "kappa_decimal": "0.0017201845283774695330739999999999999999999998999999999999999999999999", + "live": 66304, + "native_receipt_sha256": "bd438796daa50d36f03cc6df6f0c4ed655ac61804e586e73056286d0bfb3127f", + "original_source_head": "e9307b48d7d1b690939935ecef0f8e524e6d92f4", + "paid_profile": { + "1": 1618380, + "2": 427572, + "3": 180819, + "4": 85248, + "48": 26825, + "5": 25863, + "8": 5328 + }, + "physical": 66794, + "preload_move_review_sha256": "7510f96d3c368f12dba9ffd69a8df30f68d8a23ceb6cd9792415941f04c313ab", + "proof_origin": "Informal proofs and exact finite computational checks, with AI assistance. No independent human peer review claimed.", + "release_receipt_sha256": "c96f5e285893966b8b5cd39c08461adea88f0d8985feafb9de3fad1d9d840890", + "replicas": 74, + "retained_payload": 2048, + "scope": "Conditional outer headline. Two more staged quartets (preload re-synthesis) on the PR2857 shared-kernel words with a residue-free T74 owner fill. No maximum or optimality claim over changed native words, inventories, geometries, controllers or multiplication algorithms.", + "source_manifest_entries": 553, + "source_manifest_sha256": "4da246899e2c509dd8c6e5af34905c6124ca17671b188e11ac37e36adf449504", + "status": "PASS_CONDITIONAL_T74_PRELOAD_MOVE_RELEASE" +} diff --git a/research/two-sided-helper-extraction/allocation/baseline/ORDER.json b/research/two-sided-helper-extraction/allocation/baseline/ORDER.json new file mode 100644 index 0000000000..7409c4df10 --- /dev/null +++ b/research/two-sided-helper-extraction/allocation/baseline/ORDER.json @@ -0,0 +1 @@ +[[0,0],[0,37],[0,1],[0,38],[0,2],[0,39],[0,3],[0,40],[0,4],[0,41],[1,0],[1,37],[0,5],[0,42],[1,1],[1,38],[0,6],[0,43],[1,2],[1,39],[0,7],[0,44],[1,3],[1,40],[0,8],[0,45],[1,4],[1,41],[0,9],[0,46],[2,0],[2,37],[1,5],[1,42],[0,10],[0,47],[2,1],[2,38],[1,6],[1,43],[0,11],[0,48],[2,2],[2,39],[1,7],[1,44],[0,12],[0,49],[2,3],[2,40],[1,8],[1,45],[0,13],[0,50],[2,4],[2,41],[1,9],[1,46],[3,0],[3,37],[0,14],[0,51],[2,5],[2,42],[1,10],[1,47],[3,1],[3,38],[0,15],[0,52],[2,6],[2,43],[1,11],[1,48],[3,2],[3,39],[0,16],[0,53],[2,7],[2,44],[1,12],[1,49],[3,3],[3,40],[0,17],[0,54],[2,8],[2,45],[1,13],[1,50],[3,4],[3,41],[0,18],[0,55],[2,9],[2,46],[4,0],[4,37],[1,14],[1,51],[3,5],[3,42],[0,19],[0,56],[2,10],[2,47],[4,1],[4,38],[1,15],[1,52],[3,6],[3,43],[0,20],[0,57],[2,11],[2,48],[4,2],[4,39],[1,16],[1,53],[3,7],[3,44],[0,21],[0,58],[2,12],[2,49],[4,3],[4,40],[1,17],[1,54],[3,8],[3,45],[0,22],[0,59],[2,13],[2,50],[4,4],[4,41],[1,18],[1,55],[3,9],[3,46],[0,23],[0,60],[5,0],[5,37],[2,14],[2,51],[4,5],[4,42],[1,19],[1,56],[3,10],[3,47],[0,24],[0,61],[5,1],[5,38],[2,15],[2,52],[4,6],[4,43],[1,20],[1,57],[3,11],[3,48],[0,25],[0,62],[5,2],[5,39],[2,16],[2,53],[4,7],[4,44],[1,21],[1,58],[3,12],[3,49],[0,26],[0,63],[5,3],[5,40],[2,17],[2,54],[4,8],[4,45],[1,22],[1,59],[3,13],[3,50],[0,27],[0,64],[5,4],[5,41],[2,18],[2,55],[4,9],[4,46],[1,23],[1,60],[6,0],[6,37],[3,14],[3,51],[0,28],[0,65],[5,5],[5,42],[2,19],[2,56],[4,10],[4,47],[1,24],[1,61],[6,1],[6,38],[3,15],[3,52],[0,29],[0,66],[5,6],[5,43],[2,20],[2,57],[4,11],[4,48],[1,25],[1,62],[6,2],[6,39],[3,16],[3,53],[0,30],[0,67],[5,7],[5,44],[2,21],[2,58],[4,12],[4,49],[1,26],[1,63],[6,3],[6,40],[3,17],[3,54],[0,31],[0,68],[5,8],[5,45],[2,22],[2,59],[4,13],[4,50],[1,27],[1,64],[6,4],[6,41],[3,18],[3,55],[0,32],[0,69],[5,9],[5,46],[2,23],[2,60],[7,0],[7,37],[4,14],[4,51],[1,28],[1,65],[6,5],[6,42],[3,19],[3,56],[0,33],[0,70],[5,10],[5,47],[2,24],[2,61],[7,1],[7,38],[4,15],[4,52],[1,29],[1,66],[6,6],[6,43],[3,20],[3,57],[0,34],[0,71],[5,11],[5,48],[2,25],[2,62],[7,2],[7,39],[4,16],[4,53],[1,30],[1,67],[6,7],[6,44],[3,21],[3,58],[0,35],[0,72],[5,12],[5,49],[2,26],[2,63],[7,3],[7,40],[4,17],[4,54],[1,31],[1,68],[6,8],[6,45],[3,22],[3,59],[0,36],[0,73],[5,13],[5,50],[2,27],[2,64],[7,4],[7,41],[4,18],[4,55],[1,32],[1,69],[6,9],[6,46],[3,23],[3,60],[8,0],[8,37],[5,14],[5,51],[2,28],[2,65],[7,5],[7,42],[4,19],[4,56],[1,33],[1,70],[6,10],[6,47],[3,24],[3,61],[8,1],[8,38],[5,15],[5,52],[2,29],[2,66],[7,6],[7,43],[4,20],[4,57],[1,34],[1,71],[6,11],[6,48],[3,25],[3,62],[8,2],[8,39],[5,16],[5,53],[2,30],[2,67],[7,7],[7,44],[4,21],[4,58],[1,35],[1,72],[6,12],[6,49],[3,26],[3,63],[8,3],[8,40],[5,17],[5,54],[2,31],[2,68],[7,8],[7,45],[4,22],[4,59],[1,36],[1,73],[6,13],[6,50],[3,27],[3,64],[8,4],[8,41],[5,18],[5,55],[2,32],[2,69],[7,9],[7,46],[4,23],[4,60],[6,14],[6,51],[3,28],[3,65],[8,5],[8,42],[5,19],[5,56],[2,33],[2,70],[7,10],[7,47],[4,24],[4,61],[6,15],[6,52],[3,29],[3,66],[8,6],[8,43],[5,20],[5,57],[2,34],[2,71],[7,11],[7,48],[4,25],[4,62],[6,16],[6,53],[3,30],[3,67],[8,7],[8,44],[5,21],[5,58],[2,35],[2,72],[7,12],[7,49],[4,26],[4,63],[6,17],[6,54],[3,31],[3,68],[8,8],[8,45],[5,22],[5,59],[2,36],[2,73],[7,13],[7,50],[4,27],[4,64],[6,18],[6,55],[3,32],[3,69],[8,9],[8,46],[5,23],[5,60],[7,14],[7,51],[4,28],[4,65],[6,19],[6,56],[3,33],[3,70],[8,10],[8,47],[5,24],[5,61],[7,15],[7,52],[4,29],[4,66],[6,20],[6,57],[3,34],[3,71],[8,11],[8,48],[5,25],[5,62],[7,16],[7,53],[4,30],[4,67],[6,21],[6,58],[3,35],[3,72],[8,12],[8,49],[5,26],[5,63],[7,17],[7,54],[4,31],[4,68],[6,22],[6,59],[3,36],[3,73],[8,13],[8,50],[5,27],[5,64],[7,18],[7,55],[4,32],[4,69],[6,23],[6,60],[8,14],[8,51],[5,28],[5,65],[7,19],[7,56],[4,33],[4,70],[6,24],[6,61],[8,15],[8,52],[5,29],[5,66],[7,20],[7,57],[4,34],[4,71],[6,25],[6,62],[8,16],[8,53],[5,30],[5,67],[7,21],[7,58],[4,35],[4,72],[6,26],[6,63],[8,17],[8,54],[5,31],[5,68],[7,22],[7,59],[4,36],[4,73],[6,27],[6,64],[8,18],[8,55],[5,32],[5,69],[7,23],[7,60],[6,28],[6,65],[8,19],[8,56],[5,33],[5,70],[7,24],[7,61],[6,29],[6,66],[8,20],[8,57],[5,34],[5,71],[7,25],[7,62],[6,30],[6,67],[8,21],[8,58],[5,35],[5,72],[7,26],[7,63],[6,31],[6,68],[8,22],[8,59],[5,36],[5,73],[7,27],[7,64],[6,32],[6,69],[8,23],[8,60],[7,28],[7,65],[6,33],[6,70],[8,24],[8,61],[7,29],[7,66],[6,34],[6,71],[8,25],[8,62],[7,30],[7,67],[6,35],[6,72],[8,26],[8,63],[7,31],[7,68],[6,36],[6,73],[8,27],[8,64],[7,32],[7,69],[8,28],[8,65],[7,33],[7,70],[8,29],[8,66],[7,34],[7,71],[8,30],[8,67],[7,35],[7,72],[8,31],[8,68],[7,36],[7,73],[8,32],[8,69],[8,33],[8,70],[8,34],[8,71],[8,35],[8,72],[8,36],[8,73]] \ No newline at end of file diff --git a/research/two-sided-helper-extraction/allocation/baseline/PROFILE.json b/research/two-sided-helper-extraction/allocation/baseline/PROFILE.json new file mode 100644 index 0000000000..a1a5cb62c3 --- /dev/null +++ b/research/two-sided-helper-extraction/allocation/baseline/PROFILE.json @@ -0,0 +1 @@ +{"1":1618380,"2":427572,"3":180819,"4":85248,"5":25863,"8":5328,"48":26825} \ No newline at end of file diff --git a/research/two-sided-helper-extraction/allocation/vendor/PLAN.json.gz b/research/two-sided-helper-extraction/allocation/vendor/PLAN.json.gz new file mode 100644 index 0000000000..7a1db55a4d Binary files /dev/null and b/research/two-sided-helper-extraction/allocation/vendor/PLAN.json.gz differ diff --git a/research/two-sided-helper-extraction/allocation/vendor/TEMPLATE.json.gz b/research/two-sided-helper-extraction/allocation/vendor/TEMPLATE.json.gz new file mode 100644 index 0000000000..114808c32b Binary files /dev/null and b/research/two-sided-helper-extraction/allocation/vendor/TEMPLATE.json.gz differ diff --git a/research/two-sided-helper-extraction/allocation/vendor/independent_owners.py b/research/two-sided-helper-extraction/allocation/vendor/independent_owners.py new file mode 100644 index 0000000000..16013201b1 --- /dev/null +++ b/research/two-sided-helper-extraction/allocation/vendor/independent_owners.py @@ -0,0 +1,111 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Independent integer-time and mask check of the actual parameterized-replica owner allocation with PR2802 retired7 providers. + +Chronology/mask method derives from Tekalign's PR2751 independent_owners.py; +Marius-Paul Dumitrean's PR2802 retired7 native construction and the retained +provider frame checker keep their +upstream attribution. No solver, producer, emitter or floating arithmetic is +imported. This checks finite geometry, not global native/outer admission. +""" +from pathlib import Path +from collections import Counter,defaultdict +import argparse,hashlib,gzip,json,sys,types +sys.dont_write_bytecode=True +def need(v,msg): + if not v:raise ValueError(msg) +def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() +def read(p): + b=Path(p).read_bytes();return json.loads(gzip.decompress(b)if str(p).endswith('.gz')else b) +def inputs(PROVIDER): + provider_pins={'inputs/PLAN.json.gz':'afb3c5c8134fc2cfce0b50a21758490c225574994b2c3c5161e53e2355acc6fa','inputs/GLOBAL-TEMPLATE.json.gz':'21297b20f1f2dc76eb9dd8124416068c3cb096bab9df17fa4da19bc68dfe082e','independent_local.py':'ee1faab70095fa312fc61d375ddf015b76104cb1a542ae7876a149e7999faa20','inputs/PROVIDERS.json':'391075b1411a3976850c633f92f58c35ed3f046f09d55bd435d7545124543fd4','inputs/WORD-base.json.gz':'dca8becca633ffc5e998985631bcbcab1123b27ca7f10ac6a96b1ec21ce69a66','inputs/WORD-extra.json.gz':'6bcb3c2c73eaf7558ddc6ef6b484334f8d96b9d2b227e265483b657de00f4bb7'} + hashes={} + for n,pin in provider_pins.items(): + p=PROVIDER/n;need(sha(p)==pin,'pinned PR2802 provider source '+n);hashes[str(p)]=pin + L=types.ModuleType('retained_independent_frames');exec(compile((PROVIDER/'independent_local.py').read_bytes(),'pinned_PR2802_independent_local.py','exec'),L.__dict__);providers=read(PROVIDER/'inputs/PROVIDERS.json') + for tag,pid in [('base','gauge44'),('extra','extra')]: + word=read(PROVIDER/f'inputs/WORD-{tag}.json.gz');report,start,ends=L.check_frames(word);L.check_cleanup(word);L.algebra(word) + widths=[L.dm(ends[k])-L.dm(start[k])for k in sorted(start)if k>=224] + need(widths==providers[pid]['widths']and len(widths)==408,'actual ordered provider frame widths');need(len(word['centers'])==8,'eight centres');providers[pid]['actual_paid_profile']={int(k):v for k,v in report['profile'].items()} + return read(PROVIDER/'inputs/PLAN.json.gz'),read(PROVIDER/'inputs/GLOBAL-TEMPLATE.json.gz'),providers,hashes + +def windows(template,order,T): + ranks={c['child']:c['rank']for c in template['idle_children']};pairs={e['stage']:e['pair']for e in template['recipe']if e['kind']=='local'} + blocks={};stage=None + for event in template['execution_schedule']: + if event['kind']in('bank_padding_cover_sweep','translate_every_live_family'):continue + if event['kind']=='local_cover_sweep':stage=event['stage'];blocks[stage]=[] + need(stage is not None,'source event before local call');blocks[stage].append(event) + need(set(blocks)==set(range(9)),'nine source stages') + progress=[0]*T;last={};result={} + for t,(stage,replica)in enumerate(order): + need(0<=replica0,'idle source position');start=last.get((replica,event['pair']),-1) + for child in event['child_indices']: + if child in ranks:result[replica,child]=(ranks[child],start,t) + elif kind in ('terminal_Y_translations','terminal'):pass # inherited terminal phase; no pending-window endpoints + else:raise ValueError('unknown source event kind') + need(progress==[9]*T,'complete replica source progression');return result + +def check(T,order,fill,dispatch,claimed,plan,template,providers): + need(type(T)is int and T>0,'positive T');N=9*T + need(len(order)==N and set(map(tuple,order))=={(s,r)for s in range(9)for r in range(T)},'complete T call coverage') + win=windows(template,order,T) + need(set(dispatch)==set(map(tuple,order))and all(p in providers for p in dispatch.values()),'provider dispatch coverage') + for s,r,pid in fill.get('dispatch_overrides',[]):need(dispatch.get((s,r))==pid,'final dispatch override binding') + need(fill['columns']==['time','helper','owner_replica','child','port','offset'],'literal role columns') + need(len(fill['rows'])==N*408,'complete role count');helpers=[0]*N;families=[0]*N;occupied={};lastrow={} + for idx,row in enumerate(fill['rows']): + need(len(row)==6 and all(type(x)is int for x in row),'integer role shape');t,h,o,c,p,z=row + need(0<=tlastrow[key][0]:lastrow[key]=(z,idx,w) + need(helpers==[(1<<408)-1]*N,'all helper identities');idle=Counter() + for(o,c),(cap,_,_)in win.items(): + for p in range(112): + key=(o,c,p);mask=occupied.get(key,0);used=mask.bit_count();need(mask==(1<0\nassert m==73 and W==896*T and W==BJ['live']" + ] + ] + }, + { + "after_sha256": "ebaf637f1f818dac9c0fce0ee3f18df300873105818cea29a8ae9e8b737b5c7d", + "before_sha256": "08ca58abff11bdfba721dc56ab8acf06ec1b7c48a8699a0955cf35324680aca7", + "path": "code/witness.py", + "replacements": [ + [ + " with open(os.environ['WITNESS_RECORD'],'a')as f:f.write(json.dumps([key,got],default=str)+chr(10))", + " import time as _wr_time\n _wr_path=Path(os.environ['WITNESS_RECORD'])\n _wr_lock=_wr_path.with_name(_wr_path.name+'.append.lock')\n _wr_deadline=_wr_time.monotonic()+60\n _wr_fd=None\n while _wr_fd is None:\n try:_wr_fd=os.open(_wr_lock,os.O_CREAT|os.O_EXCL|os.O_WRONLY)\n except FileExistsError:\n if _wr_time.monotonic()>=_wr_deadline:raise TimeoutError('discovery record lock timeout; existing lock preserved')\n _wr_time.sleep(.005)\n try:\n with _wr_path.open('a',encoding='utf-8',newline='\\n')as _wr_out:\n _wr_out.write(json.dumps([key,got],default=str)+chr(10))\n _wr_out.flush()\n finally:\n os.close(_wr_fd)\n _wr_lock.unlink()" + ] + ] + }, + { + "after_sha256": "8b4cae2a3c7bebfee704c820e6235063940e52d323fedc2dbb7508ad06729f7a", + "before_sha256": "63140c78372e088b3f34bc22549b169fd56bed8c66af9871281297bb8455b395", + "path": "verify.py", + "replacements": [ + [ + "run('lift-parent',P/'lift_parent.py','--owners',work/'rebuilt-owners','--out',work/'rebuilt-parent')", + "run('lift-parent',P/'lift_parent.py','--package',P,'--owners',work/'rebuilt-owners','--out',work/'rebuilt-parent')" + ] + ] + }, + { + "after_sha256": "0d8cc021d2401d047aaec79060ec2ea28ba06f12eca8dbf4c60c78bb31975c4e", + "before_sha256": "ebaf637f1f818dac9c0fce0ee3f18df300873105818cea29a8ae9e8b737b5c7d", + "path": "code/witness.py", + "replacements": [ + [ + "PAYLOAD==1<<(192+(GEO['dimension']+1)//2+2*CALLS+4).bit_length()", + "PAYLOAD==1<<(128+(GEO['dimension']+1)//2+18+1330+1+4).bit_length()" + ] + ] + }, + { + "after_sha256": "c5106e0d7a97382677fa228fbade989262347968a0e54acfcf6712aa37e02f47", + "before_sha256": "bb213d0af12218ff7c9c572717e522d8bbeeb2856b87a253f4a7f44e0fd71f15", + "path": "code/invoice_allcold.py", + "replacements": [ + [ + " required_prefix=localbits+input_l2_bits+call_count+bridge_sweeps+4", + " from blocknorm_certificate import certify\n blocknorm=certify(template, {pid:base/'providers'/pid for pid in template['local_providers']})\n assert blocknorm['status'] == 'PASS_TENSOR_BLOCK_NORM_CERTIFICATE'\n assert localbits <= 128, 'actual native scalar/Horner prefix exceeds charged local reserve'\n required_prefix=localbits+input_l2_bits+blocknorm['max_active_depth']+blocknorm['stock_l2_bits']+1+4" + ] + ] + }, + { + "after_sha256": "0d522b09c7fe6a5e62fe80c28f3eefe733557a82d77c6212e5d4b91ffb7e3421", + "before_sha256": "02502a217fe8c9e10229075b50745518beac512c48db20e64c3e06514a4da5b5", + "path": "independent_core.py", + "replacements": [ + [ + " payload = 1 << (192 + (M+1)//2 + 2*len(c['order']) + 4).bit_length()", + " require(localbits <= 128, 'measured native prefix exceeds local reserve')\n payload = 1 << (128 + (M+1)//2 + 18 + 1330 + 1 + 4).bit_length()" + ] + ] + }, + { + "after_sha256": "d598a2ac1e2e8eaee14a8c285e0277a7ae44ca6a15bd2b5cfc67fb40844fb387", + "before_sha256": "c5106e0d7a97382677fa228fbade989262347968a0e54acfcf6712aa37e02f47", + "path": "code/invoice_allcold.py", + "replacements": [ + [ + " complete_invocation_sweeps=call_count,bridge_sweeps=bridge_sweeps,row_prefix_extra=2*payload,", + " complete_invocation_sweeps=call_count,bridge_sweeps=bridge_sweeps,row_prefix_extra=2*payload,blocknorm=blocknorm," + ], + [ + " primitive_arithmetic_margin_bits=4,controller_audit_sha256=", + " tensor_block_norm=blocknorm,partial_cover_margin_bits=1,physical_stock_l2_bits=blocknorm['stock_l2_bits'],primitive_arithmetic_margin_bits=4,controller_audit_sha256=" + ], + [ + "Sum every actual invocation and bridge sweep and take the maximum local scalar/Horner prefix over both orientations of the fixed provider.", + "All invocations and bridge sweeps remain charged. Bound completed-boundary energy by at most eighteen active steps per owner replica, using exact tensor-isomorphic whole-family helper unitaries. Add the full group-indexed physical-stock sup-to-l2 factor and one partial-cover margin, then the maximum local scalar/Horner prefix." + ] + ] + }, + { + "after_sha256": "e051aaa166e01263780d5ae03699690670b597fed6593af4c37a7e978825eb85", + "before_sha256": "0d522b09c7fe6a5e62fe80c28f3eefe733557a82d77c6212e5d4b91ffb7e3421", + "path": "independent_core.py", + "replacements": [ + [ + " prefix = localbits + (M + 1) // 2 + len(c['order']) + c['bridges'] + 4", + " bn=c['blocknorm']\n require(bn['status']=='PASS_TENSOR_BLOCK_NORM_CERTIFICATE' and bn['max_active_depth']==18 and bn['stock_l2_bits']<=1330, 'independent tensor block certificate')\n prefix = localbits + (M + 1) // 2 + bn['max_active_depth'] + bn['stock_l2_bits'] + 1 + 4" + ], + [ + "prefix_formula=dict(local_scalar=localbits, input_l2=(M + 1) // 2, invocations=len(c['order']), bridges=c['bridges'], margin=4)", + "prefix_formula=dict(local_scalar=localbits, input_l2=(M + 1) // 2, invocations=len(c['order']), bridges=c['bridges'], active_block_depth=18,stock_l2=bn['stock_l2_bits'],partial_cover=1,margin=4),blocknorm=bn" + ] + ] + }, + { + "after_sha256": "393323f150d0bb686419804d51cf43d0f58450d2a1e7929725acdd26fdbb3640", + "before_sha256": "2286f00e462ff28abbb3f396095463482a1e063213b9526a7225275980c77eaf", + "path": "audit_mixed.py", + "replacements": [ + [ + "pending=A.check_pending_axes(ctx);receipt=A.check_roles(ctx,roles)", + "import blocknorm_certificate as BN;ctx['blocknorm']=BN.certify_context(ctx,roles,dirs,source_parent=parent);pending=A.check_pending_axes(ctx);receipt=A.check_roles(ctx,roles)" + ] + ] + }, + { + "after_sha256": "6e994250794f792338b0edef391393cdf2a775e3d72d0c44e7753245027bdf6b", + "before_sha256": "f25e1e870df5d5a16a1e367b3df8843cb01644ab4b75895d7939af81e4fcb833", + "path": "code/assemble.py", + "replacements": [ + [ + " assert invoice['global_prefix_bits']==max(z['prefix_bits']for p in invoice['providers'].values()for z in p['local'].values())+37+CALLS+CALLS+4", + " bn=invoice['blocknorm']\n assert bn['status']=='PASS_TENSOR_BLOCK_NORM_CERTIFICATE' and bn['replicas']==REPLICAS\n assert bn['max_active_depth']==bn['boundary_depth_bits']==18 and bn['active_calls_per_block']==bn['bridges_per_block']==9\n assert bn['block_width_families']==896 and bn['physical_families']==invoice['physical'] and bn['live_families']==invoice['live']\n assert bn['partial_cover_bits']==1 and bn['input_l2_bits']==37 and bn['local_reserve_bits']==128 and bn['retained_payload_bits']==PAYLOAD\n localbits=max(z['prefix_bits']for p in invoice['providers'].values()for z in p['local'].values())\n assert bn['local_actual_prefix_bits']==localbits and localbits<=128\n assert invoice['global_prefix_bits']==bn['actual_prefix_bits']==localbits+37+18+bn['stock_l2_bits']+1+4\n assert bn['required_reserve_bits']==128+37+18+bn['stock_l2_bits']+1+40\nassert m==73 and W==896*T and W==BJ['live']" + ] + ] + }, + { + "after_sha256": "ebaf637f1f818dac9c0fce0ee3f18df300873105818cea29a8ae9e8b737b5c7d", + "before_sha256": "08ca58abff11bdfba721dc56ab8acf06ec1b7c48a8699a0955cf35324680aca7", + "path": "code/witness.py", + "replacements": [ + [ + " with open(os.environ['WITNESS_RECORD'],'a')as f:f.write(json.dumps([key,got],default=str)+chr(10))", + " import time as _wr_time\n _wr_path=Path(os.environ['WITNESS_RECORD'])\n _wr_lock=_wr_path.with_name(_wr_path.name+'.append.lock')\n _wr_deadline=_wr_time.monotonic()+60\n _wr_fd=None\n while _wr_fd is None:\n try:_wr_fd=os.open(_wr_lock,os.O_CREAT|os.O_EXCL|os.O_WRONLY)\n except FileExistsError:\n if _wr_time.monotonic()>=_wr_deadline:raise TimeoutError('discovery record lock timeout; existing lock preserved')\n _wr_time.sleep(.005)\n try:\n with _wr_path.open('a',encoding='utf-8',newline='\\n')as _wr_out:\n _wr_out.write(json.dumps([key,got],default=str)+chr(10))\n _wr_out.flush()\n finally:\n os.close(_wr_fd)\n _wr_lock.unlink()" + ] + ] + }, + { + "after_sha256": "8b4cae2a3c7bebfee704c820e6235063940e52d323fedc2dbb7508ad06729f7a", + "before_sha256": "63140c78372e088b3f34bc22549b169fd56bed8c66af9871281297bb8455b395", + "path": "verify.py", + "replacements": [ + [ + "run('lift-parent',P/'lift_parent.py','--owners',work/'rebuilt-owners','--out',work/'rebuilt-parent')", + "run('lift-parent',P/'lift_parent.py','--package',P,'--owners',work/'rebuilt-owners','--out',work/'rebuilt-parent')" + ] + ] + }, + { + "after_sha256": "0d8cc021d2401d047aaec79060ec2ea28ba06f12eca8dbf4c60c78bb31975c4e", + "before_sha256": "ebaf637f1f818dac9c0fce0ee3f18df300873105818cea29a8ae9e8b737b5c7d", + "path": "code/witness.py", + "replacements": [ + [ + "PAYLOAD==1<<(192+(GEO['dimension']+1)//2+2*CALLS+4).bit_length()", + "PAYLOAD==1<<(128+(GEO['dimension']+1)//2+18+1330+1+4).bit_length()" + ] + ] + }, + { + "after_sha256": "c5106e0d7a97382677fa228fbade989262347968a0e54acfcf6712aa37e02f47", + "before_sha256": "bb213d0af12218ff7c9c572717e522d8bbeeb2856b87a253f4a7f44e0fd71f15", + "path": "code/invoice_allcold.py", + "replacements": [ + [ + " required_prefix=localbits+input_l2_bits+call_count+bridge_sweeps+4", + " from blocknorm_certificate import certify\n blocknorm=certify(template, {pid:base/'providers'/pid for pid in template['local_providers']})\n assert blocknorm['status'] == 'PASS_TENSOR_BLOCK_NORM_CERTIFICATE'\n assert localbits <= 128, 'actual native scalar/Horner prefix exceeds charged local reserve'\n required_prefix=localbits+input_l2_bits+blocknorm['max_active_depth']+blocknorm['stock_l2_bits']+1+4" + ] + ] + }, + { + "after_sha256": "0d522b09c7fe6a5e62fe80c28f3eefe733557a82d77c6212e5d4b91ffb7e3421", + "before_sha256": "02502a217fe8c9e10229075b50745518beac512c48db20e64c3e06514a4da5b5", + "path": "independent_core.py", + "replacements": [ + [ + " payload = 1 << (192 + (M+1)//2 + 2*len(c['order']) + 4).bit_length()", + " require(localbits <= 128, 'measured native prefix exceeds local reserve')\n payload = 1 << (128 + (M+1)//2 + 18 + 1330 + 1 + 4).bit_length()" + ] + ] + }, + { + "after_sha256": "d598a2ac1e2e8eaee14a8c285e0277a7ae44ca6a15bd2b5cfc67fb40844fb387", + "before_sha256": "c5106e0d7a97382677fa228fbade989262347968a0e54acfcf6712aa37e02f47", + "path": "code/invoice_allcold.py", + "replacements": [ + [ + " complete_invocation_sweeps=call_count,bridge_sweeps=bridge_sweeps,row_prefix_extra=2*payload,", + " complete_invocation_sweeps=call_count,bridge_sweeps=bridge_sweeps,row_prefix_extra=2*payload,blocknorm=blocknorm," + ], + [ + " primitive_arithmetic_margin_bits=4,controller_audit_sha256=", + " tensor_block_norm=blocknorm,partial_cover_margin_bits=1,physical_stock_l2_bits=blocknorm['stock_l2_bits'],primitive_arithmetic_margin_bits=4,controller_audit_sha256=" + ], + [ + "Sum every actual invocation and bridge sweep and take the maximum local scalar/Horner prefix over both orientations of the fixed provider.", + "All invocations and bridge sweeps remain charged. Bound completed-boundary energy by at most eighteen active steps per owner replica, using exact tensor-isomorphic whole-family helper unitaries. Add the full group-indexed physical-stock sup-to-l2 factor and one partial-cover margin, then the maximum local scalar/Horner prefix." + ] + ] + }, + { + "after_sha256": "e051aaa166e01263780d5ae03699690670b597fed6593af4c37a7e978825eb85", + "before_sha256": "0d522b09c7fe6a5e62fe80c28f3eefe733557a82d77c6212e5d4b91ffb7e3421", + "path": "independent_core.py", + "replacements": [ + [ + " prefix = localbits + (M + 1) // 2 + len(c['order']) + c['bridges'] + 4", + " bn=c['blocknorm']\n require(bn['status']=='PASS_TENSOR_BLOCK_NORM_CERTIFICATE' and bn['max_active_depth']==18 and bn['stock_l2_bits']<=1330, 'independent tensor block certificate')\n prefix = localbits + (M + 1) // 2 + bn['max_active_depth'] + bn['stock_l2_bits'] + 1 + 4" + ], + [ + "prefix_formula=dict(local_scalar=localbits, input_l2=(M + 1) // 2, invocations=len(c['order']), bridges=c['bridges'], margin=4)", + "prefix_formula=dict(local_scalar=localbits, input_l2=(M + 1) // 2, invocations=len(c['order']), bridges=c['bridges'], active_block_depth=18,stock_l2=bn['stock_l2_bits'],partial_cover=1,margin=4),blocknorm=bn" + ] + ] + }, + { + "after_sha256": "393323f150d0bb686419804d51cf43d0f58450d2a1e7929725acdd26fdbb3640", + "before_sha256": "2286f00e462ff28abbb3f396095463482a1e063213b9526a7225275980c77eaf", + "path": "audit_mixed.py", + "replacements": [ + [ + "pending=A.check_pending_axes(ctx);receipt=A.check_roles(ctx,roles)", + "import blocknorm_certificate as BN;ctx['blocknorm']=BN.certify_context(ctx,roles,dirs,source_parent=parent);pending=A.check_pending_axes(ctx);receipt=A.check_roles(ctx,roles)" + ] + ] + }, + { + "after_sha256": "6e994250794f792338b0edef391393cdf2a775e3d72d0c44e7753245027bdf6b", + "before_sha256": "f25e1e870df5d5a16a1e367b3df8843cb01644ab4b75895d7939af81e4fcb833", + "path": "code/assemble.py", + "replacements": [ + [ + " assert invoice['global_prefix_bits']==max(z['prefix_bits']for p in invoice['providers'].values()for z in p['local'].values())+37+CALLS+CALLS+4", + " bn=invoice['blocknorm']\n assert bn['status']=='PASS_TENSOR_BLOCK_NORM_CERTIFICATE' and bn['replicas']==REPLICAS\n assert bn['max_active_depth']==bn['boundary_depth_bits']==18 and bn['active_calls_per_block']==bn['bridges_per_block']==9\n assert bn['block_width_families']==896 and bn['physical_families']==invoice['physical'] and bn['live_families']==invoice['live']\n assert bn['partial_cover_bits']==1 and bn['input_l2_bits']==37 and bn['local_reserve_bits']==128 and bn['retained_payload_bits']==PAYLOAD\n localbits=max(z['prefix_bits']for p in invoice['providers'].values()for z in p['local'].values())\n assert bn['local_actual_prefix_bits']==localbits and localbits<=128\n assert invoice['global_prefix_bits']==bn['actual_prefix_bits']==localbits+37+18+bn['stock_l2_bits']+1+4\n assert bn['required_reserve_bits']==128+37+18+bn['stock_l2_bits']+1+4=224 and r not in protected} + assert set(v)<=H and all(r in H and not ops for r,ops in u) + u={r:c for (r,ops),c in u.items()} + for r,row in M.items(): + mv=defaultdict(Q) + for (c,ops),a in row.items():mv[ops]+=a*v.get(c,Q(0)) + assert {ops:a for ops,a in mv.items() if a}==({():y[r]} if r in y else {}) + assert sum(alpha.get(r,Q(0))*c for r,c in y.items())==1 + us=defaultdict(Q) + for r,a in u.items(): + for c,b in S[r].items():us[c]+=a*b + assert {r:c for r,c in us.items() if c}=={h:Q(1)} + assert all(sum(row.get(c,Q(0))*a for c,a in y.items())==(1 if r==h else 0) for r,row in T.items()) + return {'status':'PASS_EXACT_TWO_SIDED_SUBSPACE_CERTIFICATE','helper':h,'v':{str(r):str(c) for r,c in v.items()},'u':{str(r):str(c) for r,c in u.items()},'alpha':{str(r):str(c) for r,c in alpha.items()},'y':{str(r):str(c) for r,c in y.items()},'identities':['S e_h = v','u S = e_h^T','M v = y','alpha M = u','alpha y = 1','T y = e_h','e_h^T T = alpha'],'scope':'Exact free-operator identities before target writes; full target correctness checked separately.'} diff --git a/research/two-sided-helper-extraction/tools/admit_channel408.py b/research/two-sided-helper-extraction/tools/admit_channel408.py new file mode 100644 index 0000000000..dbc974a289 --- /dev/null +++ b/research/two-sided-helper-extraction/tools/admit_channel408.py @@ -0,0 +1,415 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Tekalign (@tekuuu), with substantial OpenAI Codex assistance. +"""Prepare and fully admit a changed-replica literal order/fill derivative. + +PR2833 extension by Yiyang Lu with OpenAI Codex assistance: add the exact +immutable dirt-entry source profile and exact full outer-claim comparisons to +PR2833 and the newer PR2843 T124 allocation. All +inherited native, owner, invoice, block-norm, controls and release checks retained. + +Research runtime only: native providers must already have passed freshly and +are authenticated by --native-receipt. --prepare-only stops before discovery. +Default complete admission preserves the original verify.py and release stages. +Source inputs and the native cache are read-only; all output uses fresh --work. +""" +import argparse +from fractions import Fraction as Q +import gzip +import hashlib +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tarfile +import time + +SOURCE_COMMIT = 'local-joint12-refit393' +SOURCE_MANIFEST = '1e75eabffe1ce311cc3bddc05e76118cbdedfc806200a906c57fbc5a5dd213eb' +PARENT_MANIFEST = 'e0eefc96567fbb45e19e6de0ca295381dbe0e686c08ddc783639b065c7c791d4' +PRECISION = dict(endpoint_digits=24, grid_digits=18, margin_digits=28, bootstrap_steps=12) +COMPARISON_SHA = '252b7bbdbef293f643633ff95ba7d1eabbe83e1eebcd1cb06f51834256bde1f3' +COMPARISON_HEAD = 'e8b771ba132fe632796b28c1742a8d096c04519f' +NATIVE_STAGES = ['native', 'ledgers', 'local-replay', 'wrappers', 'phases'] +# Supported immutable source versions; CLI selection never accepts arbitrary hashes. +SOURCE_PROFILES = { + 'channel408': dict(commit='two-sided-helper408-pr2894',manifest='56cf455752722051d598a7da1e5ee700637fbaef09189f534413dbe6e0525a83',helpers=408,source_file_count=610,upstream_head='18d03c447886895ef9abf888398178e0428533ca'), + 'shared-four': dict(commit='shared-four-kernel-pr2833', manifest='54dc42f25c1d8b85adcf593c4bf6c0f83f7351388af857812790b8a0b4c3d869', helpers=408, source_file_count=547, upstream_head='e9307b48d7d1b690939935ecef0f8e524e6d92f4'), + 'preload-move': dict(commit='preload-move-pr2857', manifest='4da246899e2c509dd8c6e5af34905c6124ca17671b188e11ac37e36adf449504', helpers=408, source_file_count=553, upstream_head='e9307b48d7d1b690939935ecef0f8e524e6d92f4'), + 'pr2833': dict(commit='pr2833-dirtentry', manifest='c8ec4d1b7be08d2ad30730a07392ad9cb6d0222f2c35bef43c9a80a39b16e41f', helpers=408, source_file_count=541, upstream_head='e9307b48d7d1b690939935ecef0f8e524e6d92f4'), + 'pr2766': dict(commit='local-joint12-refit393', manifest='1e75eabffe1ce311cc3bddc05e76118cbdedfc806200a906c57fbc5a5dd213eb', helpers=415, source_file_count=491, upstream_head='e6df920cd0110e4b629e2ad84eddcb539001e174'), + 'pr2802': dict(commit='local-joint12-pr2733', manifest='9c72b4301057a6c204c40bb6584eb74b779e06618bcd98d706d726c3e2c92451', helpers=408, source_file_count=506, upstream_head='17b2ee6ef3cf1468e78a6267f0ecbc9a0e6f60dd'), +} +COMPARISONS = { + 'pr2894': dict(pr=2894,head='18d03c447886895ef9abf888398178e0428533ca',sha256='29cd4aa92059a561437d7670b574c51ae4e1cfeaaf6feb6cc318d915869e6d30',field='kappa'), + 'pr2857': dict(pr=2857, head='0b2e2537b368a0cade07ce3f71452ea018ebe394', sha256='c2a04b639c86f462caef654a29817545c57b8e5ba809e37d4d476d3577f5cd6f', field='kappa'), + 'pr2848': dict(pr=2848, head='c50d12e4720cd1fef2b5a65e337e37de9731879a', sha256='aceb1394b3e8f3abcc9b1a0dc82756ab937ffbefc2f37305a229a00ccc5137e9', field='kappa'), + 'pr2843': dict(pr=2843, head='47a7227c044cd0cabb1432a06c61dd5d60c07f5a', sha256='0adc0edfade0260c65e79867b6c8b96f58dfe29d38aa30cfb8f3d5e9c7e828d9', field='kappa'), + 'pr2833': dict(pr=2833, head='e9307b48d7d1b690939935ecef0f8e524e6d92f4', sha256='6f2c4195f0226c5a7f9ba604bc038cfd4100ba3caeeac8ed2defb6fb00632b70', field='kappa_rational'), + 'pr2767': dict(pr=2767, head='e8b771ba132fe632796b28c1742a8d096c04519f', sha256='252b7bbdbef293f643633ff95ba7d1eabbe83e1eebcd1cb06f51834256bde1f3', field='kappa_rational'), + 'pr2802': dict(pr=2802, head='17b2ee6ef3cf1468e78a6267f0ecbc9a0e6f60dd', sha256='a2fcbc8a3ad3095ecbd310a26c02e9d11c28e4d105669a08bbdfb39d7704db51', field='kappa'), +} + + + +# Discovery records are shared by parallel mutation-audit processes on Windows. +# Only discovery bookkeeping changes; strict pin comparison below it is untouched. +DISCOVERY_APPEND_OLD = " with open(os.environ['WITNESS_RECORD'],'a')as f:f.write(json.dumps([key,got],default=str)+chr(10))" +DISCOVERY_APPEND_NEW = r''' import time as _wr_time + _wr_path=Path(os.environ['WITNESS_RECORD']) + _wr_lock=_wr_path.with_name(_wr_path.name+'.append.lock') + _wr_deadline=_wr_time.monotonic()+60 + _wr_fd=None + while _wr_fd is None: + try:_wr_fd=os.open(_wr_lock,os.O_CREAT|os.O_EXCL|os.O_WRONLY) + except FileExistsError: + if _wr_time.monotonic()>=_wr_deadline:raise TimeoutError('discovery record lock timeout; existing lock preserved') + _wr_time.sleep(.005) + try: + with _wr_path.open('a',encoding='utf-8',newline='\n')as _wr_out: + _wr_out.write(json.dumps([key,got],default=str)+chr(10)) + _wr_out.flush() + finally: + os.close(_wr_fd) + _wr_lock.unlink()''' + + +def need(ok, why): + if not ok: + raise RuntimeError(why) + + +def sha(path): + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def read(path): + body = path.read_bytes() + return json.loads(gzip.decompress(body) if path.suffix == '.gz' else body) + + +def write(path, value): + # All output targets belong to this fresh work tree; never unlink an open lock. + lock = path.with_name(path.name + '.lock') + descriptor = os.open(lock, os.O_CREAT | os.O_EXCL | os.O_WRONLY) + try: + os.write(descriptor, str(os.getpid()).encode()) + os.close(descriptor) + descriptor = None + path.write_text(json.dumps(value, sort_keys=True, indent=2) + '\n', encoding='utf-8', newline='\n') + finally: + if descriptor is not None: + os.close(descriptor) + lock.unlink() + + +def tree(root, exclude=()): + result = {} + for path in sorted(root.rglob('*')): + need(not path.is_symlink(), 'unbound symlink: ' + str(path)) + name = path.relative_to(root).as_posix() + if path.is_file() and name not in exclude: + result[name] = sha(path) + return result + + +def main(): + ap = argparse.ArgumentParser(description=__doc__) + for name in ('source', 'fill', 'order', 'dispatch', 'native-cache', 'native-receipt', 'work', 'replica-helper-dir', 'reconstructor', 'comparison-claim', 'blocknorm-checker'): + ap.add_argument('--' + name, type=Path, required=True) + ap.add_argument('--jobs', type=int, default=4) + ap.add_argument('--prepare-only', action='store_true') + ap.add_argument('--source-profile', choices=['channel408'], default='channel408') + ap.add_argument('--comparison-profile', choices=['pr2894'], default='pr2894') + a = ap.parse_args() + global SOURCE_COMMIT, SOURCE_MANIFEST, COMPARISON_SHA, COMPARISON_HEAD + source_profile = SOURCE_PROFILES[a.source_profile] + comparison = COMPARISONS[a.comparison_profile] + SOURCE_COMMIT, SOURCE_MANIFEST = source_profile['commit'], source_profile['manifest'] + COMPARISON_SHA, COMPARISON_HEAD = comparison['sha256'], comparison['head'] + expected_helpers, comparison_pr = source_profile['helpers'], comparison['pr'] + need(not sys.flags.optimize and a.jobs > 0, 'enabled assertions and positive jobs required') + source, cache, work = a.source.resolve(), a.native_cache.resolve(), a.work.resolve() + need(not work.exists() and not work.is_relative_to(source) and not work.is_relative_to(cache), + 'fresh external work required') + need(sha(source / 'MANIFEST.json') == SOURCE_MANIFEST, 'COMPOSED manifest pin') + source_files = read(source / 'MANIFEST.json') + need(len(source_files) == source_profile['source_file_count'] and tree(source, ('MANIFEST.json',)) == source_files, + 'complete COMPOSED source inventory and hashes') + helper_dir = a.replica_helper_dir.resolve() + helper_paths = [helper_dir / n for n in ('lift_parent.py', 'replica_parent.py')] + [a.reconstructor.resolve()] + external_hashes = {str(p): sha(p) for p in helper_paths + [a.fill.resolve(), a.order.resolve(), a.dispatch.resolve(), a.comparison_claim.resolve(), a.blocknorm_checker.resolve()]} + need(sha(a.comparison_claim) == COMPARISON_SHA, 'exact pinned frontier headline comparison') + comparison_claim = read(a.comparison_claim) + need('headline_kappa_source' not in comparison_claim and comparison['field'] in comparison_claim, + 'comparison must be full headline outer claim, not supplier-only CLAIM') + previous = Q(comparison_claim[comparison['field']]) + need(previous == Q(comparison_claim['kappa']), 'comparison rational/decimal equality') + order_input = read(a.order) + need(order_input and all(isinstance(x,list) and len(x)==2 and all(type(v)is int for v in x) for x in order_input), 'literal integer call order') + T = 1 + max(r for st,r in order_input) + need(T > 0 and len(order_input)==9*T and set(map(tuple,order_input))=={(st,r) for st in range(9) for r in range(T)}, 'complete new replica coverage') + need(all([st for st,r in order_input if r==rep]==list(range(9)) for rep in range(T)), 'source stage projection') + dispatch_input = read(a.dispatch) + need(len(dispatch_input)==9*T and {(st,r) for st,r,pid in dispatch_input}==set(map(tuple,order_input)), 'complete explicit dispatch') + native_receipt = read(a.native_receipt) + need(native_receipt['status'] == 'PASS_COMPOSED_FRESH_NATIVE_PROVIDERS_AND_AUTHENTICATED_CACHE' + and native_receipt['source_commit'] == SOURCE_COMMIT + and native_receipt['manifest_sha256'] == SOURCE_MANIFEST, 'native receipt source binding') + need(tree(cache) == native_receipt['cache_files'], 'complete native/parent cache hashes') + old = source / 'vendor/pr1297' + need(sha(old / 'MANIFEST.json') == PARENT_MANIFEST, 'retained parent pin') + parent_receipt = cache / '_receipts' / PARENT_MANIFEST / 'RECEIPT.json' + need(sha(parent_receipt) == native_receipt['retained_parent_receipt_sha256'], 'parent receipt pin') + pr = read(parent_receipt) + need(pr['vendor_manifest_sha256'] == PARENT_MANIFEST and pr['claim_sha256'] == sha(old / 'CLAIM.json'), + 'parent receipt claim binding') + for name, digest in pr['files'].items(): + need(sha(parent_receipt.parent / name) == digest, 'parent receipt file') + parent_result = read(parent_receipt.parent / 'RESULT.json') + need(parent_result['status'] == 'PASS_GLOBAL_MIXED_X54_FUSIONS_NATIVE_AND_STRICT_ADMISSION' + and parent_result['kappa'] == read(old / 'CLAIM.json')['kappa'], 'retained parent completed admission') + natives = {} + for tag in ('base', 'extra'): + word = source / ('new/borrow/words/BORROW-WORD-43' + tag + '.json.gz') + entry = cache / sha(word) + binding = native_receipt['providers'][tag] + need(binding['word_sha256'] == sha(word) + and tree(entry, ('CACHE.json',)) == binding['complete_native_files'], 'native full-tree binding') + need(read(entry / 'local/FULL-WORD.json.gz') == read(word), 'native complete word') + stages = read(entry / 'STEPS.json') + need([s['step'] for s in stages] == NATIVE_STAGES and all(s['exit_code'] == 0 for s in stages), + 'native five-stage coverage') + checks = read(entry / 'local/LOCAL-CHECKS.json') + need(all(checks[o]['paid_profile'] == read(word)['report']['local_profile'] for o in ('forward', 'backward')), + 'native actual paid profiles') + natives[tag] = entry + work.mkdir(parents=True) + package = work / 'package' + shutil.copytree(source, package) + # Only the fresh external clone changes. Immutable source/cache inventories remain pinned. + for hp in helper_paths[:2]: + shutil.copy2(hp, package / hp.name) + need(sha(package / hp.name)==external_hashes[str(hp)], 'helper copy hash') + shutil.copy2(a.blocknorm_checker, package / 'blocknorm_certificate.py') + shutil.copy2(a.blocknorm_checker, package / 'code/blocknorm_certificate.py') + need(sha(package / 'blocknorm_certificate.py') == external_hashes[str(a.blocknorm_checker.resolve())], 'block-norm checker exact source binding') + shutil.copy2(a.reconstructor, package / 'reconstruct.py') + need(sha(package / 'reconstruct.py')==external_hashes[str(a.reconstructor.resolve())], 'reconstructor copy hash') + # The original subprocesses also write generated hash-bound source. Windows + # callers use a process-scoped LF adapter; no system configuration is changed. + lf_probe = work / '.lf-preflight.txt' + lf_probe.write_text('LF\n', encoding='utf-8') + need(lf_probe.read_bytes()==b'LF\n', 'process-scoped LF output required on Windows') + lf_probe.unlink() + env = dict(os.environ, PYTHONDONTWRITEBYTECODE='1', PYTHONUTF8='1', PYTHONINTMAXSTRDIGITS='0', + OPENBLAS_NUM_THREADS='1', OMP_NUM_THREADS='1', AUDIT_FAST_SHARDS=str(a.jobs)) + for name in ('PYTHONOPTIMIZE', 'WITNESS_SPEC', 'WITNESS_DISCOVER', 'WITNESS_RECORD'): + env.pop(name, None) + stages, patches = [], [] + + def run(name, script, *args): + start = time.monotonic() + command = [sys.executable, '-B', str(script), *map(str, args)] + log = work / (name + '.log') + with log.open('w') as output: + result = subprocess.run(command, env=env, cwd=work, stdin=subprocess.DEVNULL, + stdout=output, stderr=subprocess.STDOUT) + stages.append(dict(name=name, exit_code=result.returncode, seconds=time.monotonic() - start, + script_sha256=sha(script), log_sha256=sha(log), command=command)) + write(work / 'STAGES.json', stages) + need(result.returncode == 0, 'failed ' + name + '; see ' + str(log)) + print('PASS', name, flush=True) + + def patch(name, replacements): + path = package / name + before = sha(path) + body = path.read_text() + for old_text, new_text in replacements: + need(body.count(old_text) == 1, 'exact patch preimage: ' + name + ': ' + old_text[:80]) + body = body.replace(old_text, new_text) + path.write_text(body) + patches.append(dict(path=name, before_sha256=before, after_sha256=sha(path), replacements=replacements)) + + # PR2530's already checked correction: restored zero buffers occupy physical + # rows. COMPOSED's shipped SPEC includes them; its rebound SPEC omitted them. + patch('new/rebind.py', [ + ("physical=spec['expected']['live'] + 8 + R + 2)", + "physical=spec['expected']['live'] + 8 + R + 2 + max(len(rd(d / 'CANONICAL-WORD.json.gz').get('zero_buffers', [])) for d in locs.values()))")]) + # At T37 the historical fixed333 mutant is a no-op. Preserve the + # undercharge test by subtracting one from both actual charges, and + # require every geometry mutant to differ before the unchanged assembly. + patch('geometry_controls.py', [ + (" i['complete_invocation_sweeps']=i['bridge_sweeps']=333", + " i['complete_invocation_sweeps']-=1;i['bridge_sweeps']-=1"), + (" o,i=copy.deepcopy(owner),copy.deepcopy(invoice);fn(o,i);oh=digest(o);i['owner_audit_sha256']=oh", + " o,i=copy.deepcopy(owner),copy.deepcopy(invoice);fn(o,i);assert (o,i)!=(owner,invoice), 'geometry mutant must change actual receipts';oh=digest(o);i['owner_audit_sha256']=oh")]) + # Preserve the exact fixed-grid-maximum equality while deriving precision + # from the same SPEC read by both independent outer arithmetic checkers. + patch('verify_release.py', [ + ('Fraction(1, 10 ** 3046) - Fraction(1, 10 ** 3022)', + "Fraction(1, 10 ** (spec['outer_refinement']['endpoint_digits'] + 46)) - Fraction(1, 10 ** (spec['outer_refinement']['endpoint_digits'] + 22))"), + ('epsilon=1-(1025/1024)e-3080', "epsilon=1-(1025/1024)e-{spec['outer_refinement']['endpoint_digits']+80}"), + ('at the one 3000-digit rejection call', "at the one {spec['outer_refinement']['endpoint_digits']}-digit rejection call")]) + # Keep the native dimension and paid moment ledger fixed; bind replica + # width to both the checked source geometry and the independent B invoice. + patch('outer/check_ledger.py', [ + ('assert (m,W)==(73,66304)', + "T=spec['geometry']['replicas']\nassert type(T) is int and T>0\nassert m==73 and W==896*T and W==BJ['live']")]) + patch('code/witness.py', [(DISCOVERY_APPEND_OLD, DISCOVERY_APPEND_NEW)]) + patch('verify.py', [ + ("run('lift-parent',P/'lift_parent.py','--owners',work/'rebuilt-owners','--out',work/'rebuilt-parent')", + "run('lift-parent',P/'lift_parent.py','--package',P,'--owners',work/'rebuilt-owners','--out',work/'rebuilt-parent')")]) + # A sharper local reserve is certified against actual scalar/Horner + # prefixes of BOTH orientations and BOTH providers. All sweep and physical + # row charges remain unchanged; this never omits an invocation or bridge. + patch('code/witness.py', [ + ("PAYLOAD==1<<(192+(GEO['dimension']+1)//2+2*CALLS+4).bit_length()", + "PAYLOAD==1<<(128+(GEO['dimension']+1)//2+18+1330+1+4).bit_length()")]) + patch('code/invoice_allcold.py', [ + (" required_prefix=localbits+input_l2_bits+call_count+bridge_sweeps+4", + " from blocknorm_certificate import certify\n blocknorm=certify(template, {pid:base/'providers'/pid for pid in template['local_providers']})\n assert blocknorm['status'] == 'PASS_TENSOR_BLOCK_NORM_CERTIFICATE'\n assert localbits <= 128, 'actual native scalar/Horner prefix exceeds charged local reserve'\n required_prefix=localbits+input_l2_bits+blocknorm['max_active_depth']+blocknorm['stock_l2_bits']+1+4")]) + patch('independent_core.py', [ + (" payload = 1 << (192 + (M+1)//2 + 2*len(c['order']) + 4).bit_length()", + " require(localbits <= 128, 'measured native prefix exceeds local reserve')\n payload = 1 << (128 + (M+1)//2 + 18 + 1330 + 1 + 4).bit_length()")]) + patch('code/invoice_allcold.py', [ + (" complete_invocation_sweeps=call_count,bridge_sweeps=bridge_sweeps,row_prefix_extra=2*payload,", + " complete_invocation_sweeps=call_count,bridge_sweeps=bridge_sweeps,row_prefix_extra=2*payload,blocknorm=blocknorm,"), + (" primitive_arithmetic_margin_bits=4,controller_audit_sha256=", " tensor_block_norm=blocknorm,partial_cover_margin_bits=1,physical_stock_l2_bits=blocknorm['stock_l2_bits'],primitive_arithmetic_margin_bits=4,controller_audit_sha256="), + ("Sum every actual invocation and bridge sweep and take the maximum local scalar/Horner prefix over both orientations of the fixed provider.", + "All invocations and bridge sweeps remain charged. Bound completed-boundary energy by at most eighteen active steps per owner replica, using exact tensor-isomorphic whole-family helper unitaries. Add the full group-indexed physical-stock sup-to-l2 factor and one partial-cover margin, then the maximum local scalar/Horner prefix.")]) + patch('independent_core.py', [ + (" prefix = localbits + (M + 1) // 2 + len(c['order']) + c['bridges'] + 4", + " bn=c['blocknorm']\n require(bn['status']=='PASS_TENSOR_BLOCK_NORM_CERTIFICATE' and bn['max_active_depth']==18 and bn['stock_l2_bits']<=1330, 'independent tensor block certificate')\n prefix = localbits + (M + 1) // 2 + bn['max_active_depth'] + bn['stock_l2_bits'] + 1 + 4"), + ("prefix_formula=dict(local_scalar=localbits, input_l2=(M + 1) // 2, invocations=len(c['order']), bridges=c['bridges'], margin=4)", + "prefix_formula=dict(local_scalar=localbits, input_l2=(M + 1) // 2, invocations=len(c['order']), bridges=c['bridges'], active_block_depth=18,stock_l2=bn['stock_l2_bits'],partial_cover=1,margin=4),blocknorm=bn")]) + patch('audit_mixed.py', [ + ("pending=A.check_pending_axes(ctx);receipt=A.check_roles(ctx,roles)", + "import blocknorm_certificate as BN;ctx['blocknorm']=BN.certify_context(ctx,roles,dirs,source_parent=parent);pending=A.check_pending_axes(ctx);receipt=A.check_roles(ctx,roles)")]) + patch('code/assemble.py', [ + (" assert invoice['global_prefix_bits']==max(z['prefix_bits']for p in invoice['providers'].values()for z in p['local'].values())+37+CALLS+CALLS+4", + " bn=invoice['blocknorm']\n assert bn['status']=='PASS_TENSOR_BLOCK_NORM_CERTIFICATE' and bn['replicas']==REPLICAS\n assert bn['max_active_depth']==bn['boundary_depth_bits']==18 and bn['active_calls_per_block']==bn['bridges_per_block']==9\n assert bn['block_width_families']==896 and bn['physical_families']==invoice['physical'] and bn['live_families']==invoice['live']\n assert bn['partial_cover_bits']==1 and bn['input_l2_bits']==37 and bn['local_reserve_bits']==128 and bn['retained_payload_bits']==PAYLOAD\n localbits=max(z['prefix_bits']for p in invoice['providers'].values()for z in p['local'].values())\n assert bn['local_actual_prefix_bits']==localbits and localbits<=128\n assert invoice['global_prefix_bits']==bn['actual_prefix_bits']==localbits+37+18+bn['stock_l2_bits']+1+4\n assert bn['required_reserve_bits']==128+37+18+bn['stock_l2_bits']+1+4 previous, + 'candidate must strictly improve full exact pinned frontier headline before full release') + outer_claim = read(source / 'outer/OUTER-CLAIM.json') + outer_claim.update(kappa=row['decimal'], kappa_rational=row['rational'], + baseline_head=COMPARISON_HEAD, baseline_kappa=str(previous), gain=str(kappa-previous), + b='certified complex_lower - 1e-104 (outer/B.json)', + retuned_slacks='Endpoint precision24; free gaps follow outer/check_ledger.py from the frozen SPEC.', + fixed_grid_maximum='kappa=C-10^-70-10^-46 exactly; same fixed-grid-maximum proof at precision24.') + write(package / 'outer/OUTER-CLAIM.json', outer_claim) + (package / 'provenance').mkdir(exist_ok=True) + shutil.copy2(a.comparison_claim, package / ('provenance/PR' + str(comparison_pr) + '-HEADLINE-CLAIM.json')) + write(package / 'MANIFEST.json', tree(package, ('MANIFEST.json',))) + run('release', package / 'verify_release.py', '--main', source.parents[1], '--work', work / 'release', + '--native-cache', cache, '--jobs', a.jobs) + receipt = read(work / 'release/RELEASE-RECEIPT.json') + need(receipt['status'] == 'PASS_RELEASE' and Q(receipt['kappa_decimal']) == kappa + and receipt['manifest_sha256'] == sha(package / 'MANIFEST.json'), 'complete release binding') + need(sha(source / 'MANIFEST.json') == SOURCE_MANIFEST + and tree(source, ('MANIFEST.json',)) == source_files and tree(cache) == native_receipt['cache_files'], + 'read-only source/cache inputs changed') + need(all(sha(Path(p))==h for p,h in external_hashes.items()), 'external candidate/helper inputs changed during admission') + result.update(status='PASS_REPLICA_ORDER_FILL_DERIVATIVE_COMPLETE_RELEASE', + complex_lower=str(C), kappa=str(kappa), kappa_decimal=row['decimal'], + gain=str(kappa-previous), release_receipt_sha256=sha(work / 'release/RELEASE-RECEIPT.json'), + package_manifest_sha256=sha(package / 'MANIFEST.json'), stages=stages, + scope='Conditional finite construction and modern outer arithmetic. Exact inherited theorem obligations remain. Both native providers explicitly reused from authenticated fresh five-stage runs.') + write(work / 'RESULT.json', result) + print(result['status'], row['decimal'], flush=True) + + +if __name__ == '__main__': + main() diff --git a/research/two-sided-helper-extraction/tools/audit_moment.py b/research/two-sided-helper-extraction/tools/audit_moment.py new file mode 100644 index 0000000000..0d96586a00 --- /dev/null +++ b/research/two-sided-helper-extraction/tools/audit_moment.py @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Independent dyadic interval moment auditor, atlas D020. +Uses only Python integers/Fraction; imports no inherited numerical implementation. +This authenticates a paid histogram and its root, not a physical realization. +""" +from fractions import Fraction as F +from pathlib import Path +from functools import lru_cache +from collections import Counter +import argparse,json,hashlib + +BITS=192 +SCALE=1<=1,'log domain');k=0 + while q>2:q/=2;k+=1 + def unit(y): + z=(y-1)/(y+1);z2=z*z;term=z;value=F(0) + for j in range(128): + value+=term/(2*j+1);term*=z2 + remainder=2*term/(257*(1-z2)) + return 2*value,2*value+remainder + l,u=unit(q);l2,u2=unit(F(2));return down(l+k*l2),up(u+k*u2) +def exp_bounds(y): + need(0<=y0,'profile domain');l,u=log_bounds(F(73,rank));a=exp_bounds(b*l)[0];z=exp_bounds(b*u)[1];weight=F(rank*count,73*W);lo+=weight*a;hi+=weight*z + return down(lo),up(hi) +def run(candidate,source): + import sys + if hasattr(sys,'set_int_max_str_digits'):sys.set_int_max_str_digits(0) + need(hashlib.sha256((source/'CLAIM.json').read_bytes()).hexdigest()=='29cd4aa92059a561437d7670b574c51ae4e1cfeaaf6feb6cc318d915869e6d30','exact pinned PR2894 full headline') + prof={int(k):v for k,v in json.loads((candidate/'PROFILE.json').read_bytes()).items()} + old={int(k):v for k,v in json.loads((source/'PROFILE.json').read_bytes()).items()} + W=896*(1+max(r for s,r in json.loads((candidate/'ORDER.json').read_bytes()))) + oldW=896*(1+max(r for s,r in json.loads((source/'ORDER.json').read_bytes()))) + need(sum(r*n for r,n in prof.items())==W*73-W*320//896,'new rank mass') + need(sum(r*n for r,n in old.items())==oldW*73-oldW*320//896,'old rank mass') + # No floating endpoint or inherited numerical implementation is used. + q=10**26;lo=0;hi=q//200 + need(moment(prof,F(lo,q),W)[1]<1 and moment(prof,F(hi,q),W)[0]>1,'global root bracket') + while hi-lo>1: + mid=(lo+hi)//2;l,u=moment(prof,F(mid,q),W) + if u<1:lo=mid + elif l>1:hi=mid + else:raise ValueError('interval precision insufficient') + endpoint=F((lo//100),10**24) + target=endpoint-F(1,10**46)-F(1,10**70) + prior=F(json.loads((source/'CLAIM.json').read_bytes())['kappa']) + need(target>prior and target1,'overstated endpoint rejected') + wrong=dict(prof);wrong[32]=wrong.get(32,0)+1 + need(moment(wrong,F(lo,q),W)[0]>1,'omitted rank charge rejected') + import decimal + with decimal.localcontext() as c: + c.prec=80 + todec=lambda x:str(decimal.Decimal(x.numerator)/decimal.Decimal(x.denominator)) + texttarget=todec(target);textgain=todec(target-prior) + return dict(status='PASS_SEPARATE_EXACT_RATIONAL_FRONTIER_MOMENT',lower=str(F(lo,q)),upper=str(F(hi,q)),outer_endpoint=str(endpoint),target=str(target),target_decimal=texttarget,previous=str(prior),gain=str(target-prior),gain_decimal=textgain,W=W,oldW=oldW,normalized_profile_delta=normalized_delta,new_moment_at_full_prior=[str(x)for x in at_old],profile_sha256=hashlib.sha256((candidate/'PROFILE.json').read_bytes()).hexdigest(),baseline_profile_sha256=hashlib.sha256((source/'PROFILE.json').read_bytes()).hexdigest(),baseline_claim_sha256=hashlib.sha256((source/'CLAIM.json').read_bytes()).hexdigest(),method='Independent 128-term atanh / degree24 exponential with explicit positive tails and outward 192-bit dyadic rounding',controls=['zero log/exp identities','overstated endpoint','added rank32 charge'],scope='Complete paid histogram and exact moment only; full native/physical/outer release is separate.') +if __name__=='__main__': + p=argparse.ArgumentParser();p.add_argument('--candidate',type=Path,required=True);p.add_argument('--source',type=Path,required=True);p.add_argument('--out',type=Path,required=True);a=p.parse_args() + need(not a.out.exists(),'fresh output required');d=run(a.candidate,a.source);a.out.write_text(json.dumps(d,sort_keys=True,indent=2)+'\n',encoding='utf-8',newline='\n');print(json.dumps({k:d[k]for k in ['status','target_decimal','gain_decimal','lower','upper']})) diff --git a/research/two-sided-helper-extraction/tools/build_channel_overlay.py b/research/two-sided-helper-extraction/tools/build_channel_overlay.py new file mode 100644 index 0000000000..5b9ab21a63 --- /dev/null +++ b/research/two-sided-helper-extraction/tools/build_channel_overlay.py @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Append the declared two-sided helper408 stage to immutable PR2894 source.""" +import argparse,gzip,hashlib,json,shutil,sys,types +from pathlib import Path +sys.dont_write_bytecode=True +PARENT='4da246899e2c509dd8c6e5af34905c6124ca17671b188e11ac37e36adf449504' +def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() +def read(p): + b=p.read_bytes();return json.loads(gzip.decompress(b) if p.suffix=='.gz' else b) +def save(p,x):p.write_text(json.dumps(x,indent=2,sort_keys=True)+'\n') +def tree(p): + assert not any(f.is_symlink() for f in p.rglob('*')) + return {f.relative_to(p).as_posix():sha(f) for f in sorted(p.rglob('*')) if f.is_file() and f!=p/'MANIFEST.json'} +def main(): + ap=argparse.ArgumentParser();ap.add_argument('--source',type=Path,required=True);ap.add_argument('--local-package',type=Path,required=True);ap.add_argument('--out',type=Path,required=True);a=ap.parse_args();src=a.source.resolve();out=a.out.resolve();p=a.local_package.resolve() + assert __debug__ and not out.exists() and not out.is_relative_to(src) + assert sha(src/'MANIFEST.json')==PARENT and tree(src)==read(src/'MANIFEST.json') + pins=read(p/'PINS.json');assert all(sha(p/n)==h for n,h in pins.items()) + shutil.copytree(src,out);local=out/'new/borrow/channel408';local.mkdir() + for n in ['PINS.json','verify.py','extract.py','structure.py',*pins]: + dest=local/n;dest.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(p/n,dest) + shutil.copy2(p/'extract.py',out/'new/borrow/channel_extract.py') + prov=read(src/'new/BORROW-PROVIDERS.json');records={} + for tag,pid in [('base','gauge44'),('extra','extra')]: + q=out/f'new/borrow/words/BORROW-WORD-43{tag}.json.gz';assert q.read_bytes()==(p/f'data/PARENT-{tag}.json.gz').read_bytes() + shutil.copy2(q,out/f'new/borrow/inputs/PM-WORD-{tag}.json.gz');shutil.copy2(p/f'data/WORD-{tag}.json.gz',q) + w=read(q);hs=sorted(set(range(224,704))-set(w['removed'])) + prov[pid]={'widths':[len(w['helper_final'].get(str(h),[0]*9))-len(w['start_extra'].get(str(h),[])) for h in hs],'actual_paid_profile':w['report']['local_profile']} + records[tag]={'parent_sha256':sha(p/f'data/PARENT-{tag}.json.gz'),'word_sha256':sha(q)} + save(out/'new/BORROW-PROVIDERS.json',prov) + path=out/'new/rebuild_borrow.py';text=path.read_text();anchor=" final=json.loads(gzip.decompress(shipped.read_bytes()))" + assert text.count(anchor)==1 + block=""" # Explicit two-sided input/output change; the extra cold helper is charged. + import channel_extract + channel_parent=json.loads(gzip.decompress((D/'inputs'/f'PM-WORD-{wt}.json.gz').read_bytes())) + assert chain[-1]==channel_parent + channel_transform=json.loads((D/'channel408/data/TRANSFORM.json').read_text()) + channel_word=channel_extract.apply(chain[-1],channel_transform) + assert set(k_ for k_ in chain[-1] if chain[-1][k_]!=channel_word[k_])==channel_extract.ALLOWED + chain.append(channel_word);steps.append('two-sided-helper408') +""" + path.write_text(text.replace(anchor,block+anchor)) + path=out/'verify.py';text=path.read_text();line=next(s for s in text.splitlines() if s.startswith("run('preload-move-independent-review'")) + new=line.replace("P/'new/borrow/words/BORROW-WORD-43base.json.gz'","P/'new/borrow/inputs/PM-WORD-base.json.gz'").replace("P/'new/borrow/words/BORROW-WORD-43extra.json.gz'","P/'new/borrow/inputs/PM-WORD-extra.json.gz'") + new+="\nrun('two-sided-helper408-review',P/'new/borrow/channel408/verify.py','--work',work/'two-sided-helper408-review')" + assert text.count(line)==1;path.write_text(text.replace(line,new)) + before=tree(src);after=tree(out);save(out/'MANIFEST.json',after) + changes={n:{'before':before.get(n),'after':after.get(n)} for n in set(before)|set(after) if before.get(n)!=after.get(n)} + expected={'new/BORROW-PROVIDERS.json','new/rebuild_borrow.py','verify.py','new/borrow/channel_extract.py'}|{f'new/borrow/words/BORROW-WORD-43{tag}.json.gz' for tag in ('base','extra')}|{f'new/borrow/inputs/PM-WORD-{tag}.json.gz' for tag in ('base','extra')}|{'new/borrow/channel408/'+n for n in ['PINS.json','verify.py','extract.py','structure.py',*pins]} + assert set(changes)==expected and tree(src)==before + result={'status':'PASS_SOURCE_BOUND_TWO_SIDED_HELPER408_OVERLAY','parent_manifest_sha256':PARENT,'manifest_sha256':sha(out/'MANIFEST.json'),'source_file_count':len(after),'changes':changes,'words':records,'builder_sha256':sha(Path(__file__))} + save(out.parent/(out.name+'-DERIVATION.json'),result);print(result['status'],result['manifest_sha256'],len(after)) +if __name__=='__main__':main() diff --git a/research/two-sided-helper-extraction/tools/channel_blocknorm.py b/research/two-sided-helper-extraction/tools/channel_blocknorm.py new file mode 100644 index 0000000000..20afc31774 --- /dev/null +++ b/research/two-sided-helper-extraction/tools/channel_blocknorm.py @@ -0,0 +1,268 @@ +"""Physical-owner boundary certificate; retains the completed native phase audit. + +certify(hosted, local_dirs) is a finite premise checker for the separate universal +block-energy lemma. It does not replace frame/phase/primitive or release checks. +""" +import gzip, hashlib, json +from collections import Counter +from fractions import Fraction as Q +from pathlib import Path + + +def require(ok, message): + if not ok: + raise AssertionError('blocknorm: ' + message) + + +def digest(path): + return hashlib.sha256(Path(path).read_bytes()).hexdigest() + + +def read(path): + path = Path(path) + raw = gzip.decompress(path.read_bytes()) if path.suffix == '.gz' else path.read_bytes() + return json.loads(raw) + + +def replay_endpoint(events, v, helpers, back): + """Exact rows in the free warp algebra, plus private first-write discipline. + + Frame transports/centre children retain the separately audited native + coordinate interfaces. A warp prefixes a formal invertible operator; only + adjacent inverse pairs cancel. Thus no numerical sampling is used. + """ + n = 2*v + helpers + rows = {('L', i): {(i, ()): Q(1)} for i in range(n)} + live_z, allocated, freed, cleared_c = set(), set(), set(), Counter() + tags = {'phase', 'scalar', 'warp', 'center', 'climb', 'adapter', 'residual_adapter', 'zero_buffer'} + for index, event in enumerate(events): + tag = event[0] + require(tag in tags, 'unknown native event') + if tag == 'zero_buffer': + _, action, z = event + r = ('Z', z) + if action == 'alloc': + require(z not in allocated and r not in rows, 'zero buffer duplicate allocation') + allocated.add(z); live_z.add(z); rows[r] = {} + else: + require(action == 'free' and z in live_z and not rows[r], 'zero buffer release nonzero/unallocated') + live_z.remove(z); freed.add(z) + elif tag == 'scalar': + e = event[1]; op = e[0]; target = tuple(e[1]) + require(op in ('clear','copy','scale','add'), 'unknown scalar') + source = tuple(e[2]) if op in ('copy','add') else None + for r in [target] + ([source] if source else []): + require(r[0] in ('L','C','Z'), 'unknown register class') + if r[0] == 'L': require(0 <= r[1] < n, 'live role range') + if r[0] == 'C': require(0 <= r[1] < 8, 'centre role range') + if r[0] == 'Z': require(r[1] in live_z, 'zero buffer read/write before alloc or after free') + if op == 'clear': + rows[target] = {} + if target[0] == 'C': cleared_c[target[1]] += 1 + elif op == 'copy': + require(source in rows, 'source read before initialization') + # First private write must be an explicit clear, even if copy overwrites. + require(target in rows, 'private copy before first clear') + rows[target] = dict(rows[source]) + elif op == 'scale': + require(target in rows, 'scale before first clear') + q = Q(e[2], e[3]); rows[target] = {j:q*x for j,x in rows[target].items() if q*x} + else: + require(target in rows and source in rows, 'add read before first clear') + q = Q(e[3],e[4]); dest=rows[target] + require(target != source, 'aliased scalar add') + for j,x in rows[source].items(): + y=dest.get(j,Q(0))+q*x + if y: dest[j]=y + else: dest.pop(j,None) + elif tag == 'warp': + r, op = tuple(event[1]), event[2] + require(r in rows and (r[0] != 'Z' or r[1] in live_z), 'warp before initialization') + require(isinstance(op,int) and op != 0, 'invalid formal warp') + rows[r] = {(i, word[1:] if word and word[0] == -op else (op,)+word): x + for (i,word),x in rows[r].items()} + elif tag == 'center': + require(('C',event[1]) in rows, 'centre child before first clear') + require(not live_z and allocated == freed and len(allocated)==73, 'all73 private zero buffers released') + require(set(cleared_c)==set(range(8)) and all(cleared_c[k]==2 for k in range(8)), 'each centre first and terminal clear') + require(all(not row for r,row in rows.items() if r[0] in ('C','Z')), 'private work nonzero at boundary') + for i in range(n): + want={(i,()):Q(1)} + if back and i0 and live%896==0, 'live896T') + T=live//896 + stock_bits, stock_l2_bits=full_stock_l2(physical) + require(physical==live+8+408+73+2 and physical <= 2**20, 'physical stock bound') + ns=d['private_namespace'] + require(ns=={'centers':[live,live+8], 'reserved_tableau':[live+8,live+416], + 'zero_buffers':[live+416,live+489], 'coefficient':[live+489,live+491]}, 'private namespaces') + registry=d['local_providers']; require(set(local_dirs)==set(registry), 'complete provider directory map') + endpoint, localbits = certify_providers(registry, local_dirs) + require(localbits<=128, 'local prefix128 reserve') + calls=d['calls']; require(len(calls)==9*T, '9T calls') + bycall={}; stages=[Counter() for _ in range(T)]; foreign=0 + pairs=[0,0,0,1,1,2,2,3,3]; backwards={1,3,5,7} + for call in calls: + r,s=call['replica'],call['stage']; pid=call['provider_id'] + require(isinstance(r,int) and 0<=r=0, 'family-local helper route') + if route[0]==3: require(width==9 and len(route)==3, 'full-width helper route') + else: require(len(route)==5 and route[3]==width and len(route[4])==9-width and len(set(route[4]))==9-width and all(0<=x<9 for x in route[4]), 'residual spectator permutation') + foreign += (f//896 != r) + require(call['time'] not in bycall, 'serialized call times'); bycall[call['time']]=call + stages[r][s]+=1 + require(all(c==Counter(range(9)) for c in stages), 'every replica9 calls exactly') + kinds={'local_cover_sweep','idle_cover_sweep','bridge','terminal','terminal_Y_translations','bank_padding_cover_sweep','translate_every_live_family'} + seq=[[] for _ in range(T)]; active=[0]*T; bridges=[0]*T; globals_seen=[] + for event in d['execution_schedule']: + kind=event['kind']; require(kind in kinds, 'known schedule event') + if kind in ('bank_padding_cover_sweep','translate_every_live_family'): + globals_seen.append(kind); require(event['families']==([live,live] if kind=='bank_padding_cover_sweep' else [0,live]), 'family-local global sweep') + continue + r=event['replica']; require(0<=rk and piv[j]>>k&1:piv[j]^=piv[k] + return tuple(piv[k] for k in sorted(piv,reverse=True)) + +def contained(a,b):return basis(a+b)==b + +def registers(e):return e[1:3] if e[0]=='add' else e[1:2] + +def apply(e,rows,dual=False): + if e[0]=='add': + t,s=e[1:3];q=F(e[3],e[4]);require(t!=s,'self add') + if dual:t,s,q=s,t,-q + dst=rows[t] + for k,x in list(rows[s].items()): + a=dst.get(k,F(0))+q*x + if a:dst[k]=a + else:dst.pop(k,None) + elif e[0]=='scale': + t=e[1];q=F(e[2],e[3]);require(q!=0,'zero scale') + if dual:q=1/q + rows[t]={k:q*x for k,x in rows[t].items()} + else:raise RuntimeError('unknown scalar primitive') + +def invert(e): + r=list(e) + if r[0]=='add':r[3]=-r[3] + else:r[2],r[3]=r[3],r[2] + return r + +def check_parent_interface(word,main): + # Read only the retained boundary data. No builder or local checker is imported. + relative="research/community-k492-audit/pr622/replay/baseline558/complex-global/base/split-centres/CANONICAL-WORD.json.gz" + path=main/relative;raw=path.read_bytes() + require(hashlib.sha256(raw).hexdigest()=="66d3c3c70983224650643a0a05a21ac6c6959f84d0f4528650601016f5a76844",'parent canonical input pin') + parent=json.loads(gzip.decompress(raw)) + tau=lambda x:x^(43 if (x&43).bit_count()%2 else 0) + ports=parent['ports'];v=word['report']['v'] + require(len(ports)==len(set(ports))==v,'parent port count') + require(set(map(tau,word['ports']))==set(ports),'transported source/target ports') + moved={i:ports.index(tau(p)) for i,p in enumerate(word['ports'])} + centers=[moved.get(r,r) for r in word['centers']] + actual=[list(basis([tau(x) for x in frame])) for frame in word['center_frames']] + expected=[parent['frames'][f] for f in parent['center_frames']] + require(len(centers)==len(set(centers))==len(actual)==8,'eight distinct centre carriers') + require(actual==expected and all(len(f)==8 for f in actual),'ordered centre frame interface') + return dict(parent_path=relative,parent_file_sha256=hashlib.sha256(raw).hexdigest(), + transport_tau=43,ordered_frame_bases_match=True,all_ports_match=True, + transported_centers=centers,source_centers=[r for r in centers if r=2*v} + for e in w['precondition']:apply(e,dirt) + compensation=[['add',y,k,-a.numerator,a.denominator,[]] for y in range(v,2*v) for k,a in sorted(dirt[y].items())] + entering=set(map(int,w.get('start_extra',{})));lowends=set(map(int,w.get('helper_final',{}))) + coldends=lowends-entering + require(not any(e[2] in entering for e in compensation),'nonzero entrance response') + require(not any(r in entering|coldends for e in w['precondition']+compensation for r in registers(e)), 'pre-wrapper touch of residual helper') + require(all(e[-1]==[] for e in w['precondition']+compensation),'nonzero frame precondition') + early=w.get('early_cleanup',[]);earlyids={i for i,U in early} + require(len(earlyids)==len(early),'duplicate early cleanup gate') + tail=[w['cleanup'][i][:-1]+[U] for i,U in early] + cleanup=[e for i,e in enumerate(w['cleanup']) if i not in earlyids] + prefix=w['precondition']+compensation+main + program=prefix+tail+cleanup + for dual in (False,True): + actual=ident() + for e in program:apply(e,actual,dual) + expected=ident() + for t in range(v):expected[t if dual else v+t][v+t if dual else t]=F(-1 if dual else 1) + bad=[i for i in range(n) if actual[i]!=expected[i]] + require(not bad,'all-column endpoint failure '+str((dual,bad[:8]))) + print('endpoint', 'dual' if dual else 'forward','PASS',flush=True) + full=basis([1<>=1;i+=1 + return y + +def ginv(cols,h): + # inverse columns over F2 (None if singular), Gauss-Jordan on (G | I) column-wise + piv={}; + for i in range(h): + a=cols[i];b=1<>s&1:a^=piv[s][0];b^=piv[s][1] + if a:return None + pre.append(b) + return pre # pre[t] = G^{-1}(e_t) + +def gtrans(cols,h): + # transpose: column j of G^T = row j of G + return [sum(((cols[i]>>j)&1)< E (used for B-phase warps and for A-phase prelude warps)""" + inv=ginv(cols,h);require(inv is not None,'G not invertible') + require(all(gmul(cols,inv[t])==1<(Gx, (G+G^-T)x + G^-T z) + GiT=gtrans(inv,h) # G^{-T}: columns j = row j of G^{-1} + # G^{-T}(z): via columns GiT + def M(vec): + x=vec&((1<>h + gx=gmul(cols,x);S=gx^gmul(GiT,x) # (G + G^{-T}) x + return gx|((S^gmul(GiT,z))<>h)|((vec&((1<0)-(op<0))*(abs(op)+dsym)) + walg_add(rows[src],row,-c) + return + if e[0]=='warp': + op=e[2];s=(op>0)-(op<0) + if dual:op=s*(abs(op)+dsym) # dual orientation: K_G^{-T} is a distinct free symbol + rows[e[1]]=walg_warp(rows[e[1]],op);return + if e[0]=='add': + t,s=e[1:3];q=F(e[3],e[4]);require(t!=s,'self add') + if dual:t,s,q=s,t,-q + walg_add(rows[t],rows[s],q) + else: + t=e[1];q=F(e[2],e[3]);require(q!=0,'zero scale') + if dual:q=1/q + rows[t]={k:q*x for k,x in rows[t].items()} + +def invert_item(e,full): + if e[0]=='warp':return ['warp',e[1],-e[2]] + r=list(e) + if r[0]=='add':r[3]=-r[3] + else:r[2],r[3]=r[3],r[2] + return r + +def run_borrow(path,out,main,base,w,data,begin): + v,h,R=w['report']['v'],w['report']['h'],w['report']['R'];n=2*v+R + require((v,h)==(112,9),'wrong source geometry') + require(main is None,'--main parent interface is not available for coordinate-changed BORROW-WORD; use --base') + full=basis([1<=2*v,'correction source must be a remaining helper') + require(s not in entering,'correction source has nonzero entrance frame') + require(len(word)>=1 and all(1<=abs(o)<=K for o in word),'correction operator word') + require(c!=0 and c.denominator&(c.denominator-1)==0,'correction coefficient') + # the source is the lender of the operator it is read through + require(all(warps[abs(o)-1][1]==s for o in word),'correction source is not the lender of its operator') + # --- 4. frames: literal chain, monotone, paid profile --------------------------------------- + end=[full]*v+[basis([x for x in range(1,1<0 else list(to_),list(to_) if op_>0 else list(fr_),h) + require(cur[r_]==basis(fr_),'prelude warp frame mismatch '+str((r_,op_))) + cur[r_]=basis(to_) + else: + for q in registers(e):climb(q,e[-1]) + for e in Aord: + for q in registers(e):climb(q,e[-1]) + lev={int(t):basis(U) for t,U in w.get('target_levels',{}).items()} + require(all(cur[v+t]==lev.get(t,()) for t in range(v)),'target centre levels') + for q,U in zip(w['centers'],w['center_frames']): + U=basis(U);require(cur[q]==U,'center frame') + served={lev.get(e[1]-v,()) for e in w['cut'] if e[2]==q} + for T in sorted(served,key=lambda x:-len(x)): + require(contained(T,U),'center path not nested') + if T!=U:paid[len(U)-len(T)]+=1 + U=T + byposition={} + for op,rec in enumerate(warps,1):byposition.setdefault(rec[0],[]).append(op) + B=w['B'];forward=[] # chronological program of the (recorded) non-target word + for e in Aord:forward.append(e) + for p in range(len(B)+1): + for op in byposition.get(p,[]): + _,lender,cols,U,E=warps[op-1] + require(cur[lender]==basis(U),'warp frame mismatch '+str((op,lender,cur[lender],basis(U)))) + cur[lender]=basis(E);forward.append(['warp',lender,op]) + if p=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/two-sided-helper-extraction/vendor/fastnative/common.py b/research/two-sided-helper-extraction/vendor/fastnative/common.py new file mode 100644 index 0000000000..9ed8d88b97 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/compare.py b/research/two-sided-helper-extraction/vendor/fastnative/compare.py new file mode 100644 index 0000000000..f3c60c6133 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/controls.py b/research/two-sided-helper-extraction/vendor/fastnative/controls.py new file mode 100644 index 0000000000..5877dead77 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/evidence/BENCHMARK.json b/research/two-sided-helper-extraction/vendor/fastnative/evidence/BENCHMARK.json new file mode 100644 index 0000000000..53c0d77ab3 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/evidence/COVERAGE.json b/research/two-sided-helper-extraction/vendor/fastnative/evidence/COVERAGE.json new file mode 100644 index 0000000000..6ccc53ea51 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/evidence/REGISTERED.log b/research/two-sided-helper-extraction/vendor/fastnative/evidence/REGISTERED.log new file mode 100644 index 0000000000..dd419f7dee --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/evidence/VALIDATION.json b/research/two-sided-helper-extraction/vendor/fastnative/evidence/VALIDATION.json new file mode 100644 index 0000000000..9848bae05c --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/fixtures/WORD-base.json.gz b/research/two-sided-helper-extraction/vendor/fastnative/fixtures/WORD-base.json.gz new file mode 100644 index 0000000000..f1fc67a6ea Binary files /dev/null and b/research/two-sided-helper-extraction/vendor/fastnative/fixtures/WORD-base.json.gz differ diff --git a/research/two-sided-helper-extraction/vendor/fastnative/fixtures/WORD-extra.json.gz b/research/two-sided-helper-extraction/vendor/fastnative/fixtures/WORD-extra.json.gz new file mode 100644 index 0000000000..f06e80c4dd Binary files /dev/null and b/research/two-sided-helper-extraction/vendor/fastnative/fixtures/WORD-extra.json.gz differ diff --git a/research/two-sided-helper-extraction/vendor/fastnative/requirements.txt b/research/two-sided-helper-extraction/vendor/fastnative/requirements.txt new file mode 100644 index 0000000000..aaa34fa3b2 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/requirements.txt @@ -0,0 +1 @@ +numpy==2.2.6 diff --git a/research/two-sided-helper-extraction/vendor/fastnative/run_native.py b/research/two-sided-helper-extraction/vendor/fastnative/run_native.py new file mode 100644 index 0000000000..64ef0eb83f --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/stage.py b/research/two-sided-helper-extraction/vendor/fastnative/stage.py new file mode 100644 index 0000000000..9ecc54bca4 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/accelerators/SPARSE-NOTICE.md b/research/two-sided-helper-extraction/vendor/fastnative/vendor/accelerators/SPARSE-NOTICE.md new file mode 100644 index 0000000000..a3b31e157f --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/accelerators/SPARSE-PROOF.md b/research/two-sided-helper-extraction/vendor/fastnative/vendor/accelerators/SPARSE-PROOF.md new file mode 100644 index 0000000000..bbd5990439 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/accelerators/sparse_state.py b/research/two-sided-helper-extraction/vendor/fastnative/vendor/accelerators/sparse_state.py new file mode 100644 index 0000000000..ca39f73494 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/accelerators/tables.py b/research/two-sided-helper-extraction/vendor/fastnative/vendor/accelerators/tables.py new file mode 100644 index 0000000000..5d546d8a05 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/NOTICE-PR2226.md b/research/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/NOTICE-PR2226.md new file mode 100644 index 0000000000..a14b299ef5 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/bw_adapters.py b/research/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/bw_adapters.py new file mode 100644 index 0000000000..82beaa9c1d --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/bw_audit_local.py b/research/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/bw_audit_local.py new file mode 100644 index 0000000000..912a0c447c --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/bw_tamper.py b/research/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/bw_tamper.py new file mode 100644 index 0000000000..a519863fd8 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/bw_transport.py b/research/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/bw_transport.py new file mode 100644 index 0000000000..08248542b1 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/vendor/PR2226-NOTICE.md b/research/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/vendor/PR2226-NOTICE.md new file mode 100644 index 0000000000..5ea70357a0 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py b/research/two-sided-helper-extraction/vendor/fastnative/vendor/native/new/code/borrow/vendor/clifford/clifford_exact.py new file mode 100644 index 0000000000..166841a037 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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/two-sided-helper-extraction/vendor/fastnative/verify.py b/research/two-sided-helper-extraction/vendor/fastnative/verify.py new file mode 100644 index 0000000000..0c311cd6e7 --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/fastnative/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() diff --git a/research/two-sided-helper-extraction/vendor/preload_move.py b/research/two-sided-helper-extraction/vendor/preload_move.py new file mode 100644 index 0000000000..55b435035b --- /dev/null +++ b/research/two-sided-helper-extraction/vendor/preload_move.py @@ -0,0 +1,133 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Declared preload-move stage: two more staged quartets on the PR2857 shared-kernel words. + +Preload re-synthesis (quartets (456,457,466,467) and (458,459,464,465)) by Jeremy Kothe +(jeremykothe2), with AI assistance; the staged-kernel gate shapes, frame/inverse-cleanup +conventions and the dirt-entry supplier are credited in CREDITS.md (PR2857 Lyy-iiis, PR2863 +Dugongue, PR2833 Jeremy Kothe, PR2853 philippeVV). + +apply(word, patch) takes the decoded PR2857 shared-kernel word and a DECLARED patch input +that lists every changed gate. Every listed old gate must be present at its index, no +other gate may change, the changed sections are limited to +{A, B, compensation, start_extra, report, cleanup}, the frame/paid profile and width +inventory are re-derived exactly from the changed word and must equal the declaration, and +the inverse-reverse cleanup is re-derived. The inherited exact auditor (forward and dual +free-operator replay over every input column) is the separate semantic check. +No file, import, process or output is touched by apply(). +""" +import copy, hashlib, json +from collections import Counter + +SOURCE_CANONICAL = { + 'base': 'c0af0ef7ee6282e91f046d027983b35eaed7ebcb46489134d47e07724cf664bc', + 'extra': '61b20fbe78fdcbca0cde0597befcc254017ee206dad0724c576672aca690c66f', +} +ALLOWED_SECTIONS = {'A', 'B', 'compensation', 'start_extra', 'report', 'cleanup'} + +def require(ok, reason): + if not ok:raise ValueError(str(reason)) + +def canon(w):return hashlib.sha256(json.dumps(w,sort_keys=True,separators=(',',':')).encode()).hexdigest() + +def basis(vs): + piv={} + for a in vs: + while a: + bit=a.bit_length()-1 + if bit in piv:a^=piv[bit] + else:piv[bit]=a;break + for k in sorted(piv): + for j in piv: + if j>k and piv[j]>>k&1:piv[j]^=piv[k] + return tuple(piv[k] for k in sorted(piv,reverse=True)) + +def contained(a,b):return basis(a+b)==b + +def restored_of(w): + n=2*w['report']['v']+w['report']['R'] + return {g[1]-n for g in w['cleanup'] if g[1]>=n}|{g[2]-n for g in w['cleanup'] if g[0]=='add' and g[2]>=n} + +def derive_cleanup(w,restored): + v=w['report']['v'];n=2*v+w['report']['R'];full=list(basis([1<=224) + return {str(k):v for k,v in sorted(paid.items())},{str(k):v for k,v in sorted(inv.items())} + +def apply(word, patch): + """Return (changed word, ledger). Authenticates the decoded source first.""" + require(patch.get('stage')=='preload-move','stage tag') + digest=canon(word);require(digest==patch['source_canonical_sha256'],'source canonical hash differs from the declared source') + require(patch['variant'] in SOURCE_CANONICAL and SOURCE_CANONICAL[patch['variant']]==digest,'unauthorized decoded source SHA256') + x=copy.deepcopy(word) + # A: replacements and insertions, both addressed by index in the SOURCE A (before any edit). + ops=patch['A_edits'];seen=set();byp={};repl={} + for e in ops: + if e['op']=='replace': + i=e['index'];require(i not in seen and i not in repl,('duplicate A replace',i));require(word['A'][i]==e['old'],('A old gate mismatch',i,word['A'][i]));repl[i]=e['new'] + else: + require(e['op']=='insert' and 0<=e['before']<=len(word['A']),'A edit op');byp.setdefault(e['before'],[]).append(e['gate']) + A=[] + for p in range(len(word['A'])+1): + A.extend(copy.deepcopy(g) for g in byp.get(p,[])) + if p