diff --git a/docs/ci-verification.md b/docs/ci-verification.md index 63ba3e9aa8..52b62d0481 100644 --- a/docs/ci-verification.md +++ b/docs/ci-verification.md @@ -1,8 +1,25 @@ # CI verification -## Current selected-family replay: #6030 +## Current selected-family replay: #7000 with #7001 The [selected record](../certificates/selected-result.json) binds conditional +κ = 0.00363005817 to the [application review](research/pr-intake-evidence/pr7000-application/PROOF-REVIEW.md), +[validation receipts](research/pr-intake-evidence/pr7000-application/VALIDATION.json), +and [explicit source closure](../certificates/frontier7000-source.json). +`make frontier7000-verify` follows that exact-source selected replay. The review +reuses eleven authenticated preceding executions and records seven fresh serial +application, scalar and complete native-catalogue executions. The earlier +monolithic timeout is retained separately and is not completed coverage. +Consult the receipts for exact commands, source heads and limits. + +The five inherited framework assumptions remain. No complete uniform word, +literal multiplier execution, independent human proof or formal-kernel proof +is asserted. Routine research submissions do not need to rerun this +selected-family replay. The sections below preserve historical checkpoints. + +## Historical selected-family replay: #6030 + +The [historical checkpoint](../certificates/checkpoints/frontier6030.json) binds conditional κ = 0.003125804 to the [proof review](research/pr-intake-evidence/pr6030-audit/PROOF-REVIEW.md), [validation receipts](research/pr-intake-evidence/pr6030-audit/VALIDATION.json), and [explicit source closure](../certificates/frontier6030-source.json). diff --git a/research/bit-fixed-bank-split-bound/NOTICE b/research/bit-fixed-bank-split-bound/NOTICE new file mode 100644 index 0000000000..6f60f5fbdd --- /dev/null +++ b/research/bit-fixed-bank-split-bound/NOTICE @@ -0,0 +1,4 @@ +Apache-2.0. +Retained BIT word and signed invoice from #6726 and #7001, pricing from +#7294. Credit #5599 and #5679 for the common-frame split identity. +OpenAI Codex and subagents materially assisted. diff --git a/research/bit-fixed-bank-split-bound/PRICE.json b/research/bit-fixed-bank-split-bound/PRICE.json new file mode 100644 index 0000000000..188b239248 --- /dev/null +++ b/research/bit-fixed-bank-split-bound/PRICE.json @@ -0,0 +1,469 @@ +{ + "adapter_relative_pins": { + "frozen/INVENTORY.json": "8b9723cb93ce95163cf1aec8a830ba7e06f1a4274e50f5110ce09b8d6aa95472", + "frozen/PRICE.json": "6706bb6225d5e41fa74eef932d92802dd48b722a6a9a6e3ea0040edd76e299f4", + "worker.py": "278e2d1012db8c171c78c526681e3b2764da8f4b681f027a8682268a6efed2ea" + }, + "copies": 36, + "covered_pivots": 434, + "dependency_relative_pins": { + "CONTINUATION.json": "1b99adc18dc7bb1839cc98d17b3be022bae939dd16d0f7d6bcea8fc24cd1f678", + "audit.py": "3aec134ceb6da7e6cf42ff8134ce3d7de62c06aa2f168fae95623d0fdb79f0c3", + "inputs/INVOICE.json": "a46b6c6040f75184cab5467656811ad988c216e3bc8e44d595a5015b6e49620b", + "inputs/WORD.json.gz": "51203e7fc75ba10bd3ac3f8e675759f47e13d262bea66b6600d1e515095cad78", + "price.py": "6a33aac4c7032de9bb3881da248f5371b69c6b9af0893220825727f3d4878fae", + "replay.py": "7be49a2c71ffb76a27229f0e307043d37a2da10d707ba4fe3cebbe100392d557" + }, + "last_tested_clock": 31974, + "pivot_event_counts": { + "222": 77, + "223": 60, + "224": 64, + "225": 65, + "226": 70, + "227": 67, + "228": 69, + "229": 73, + "230": 60, + "231": 62, + "232": 59, + "233": 68, + "234": 70, + "235": 64, + "236": 63, + "237": 82, + "238": 75, + "239": 69, + "240": 39, + "241": 61, + "242": 66, + "243": 68, + "244": 61, + "245": 70, + "246": 61, + "247": 62, + "248": 65, + "249": 62, + "250": 71, + "251": 70, + "252": 67, + "253": 39, + "254": 60, + "255": 62, + "256": 64, + "257": 61, + "258": 57, + "259": 65, + "260": 69, + "261": 65, + "262": 67, + "263": 65, + "264": 85, + "265": 69, + "266": 72, + "267": 39, + "268": 64, + "269": 62, + "270": 61, + "271": 68, + "272": 63, + "273": 60, + "274": 70, + "275": 57, + "276": 76, + "277": 59, + "278": 61, + "279": 60, + "280": 71, + "281": 66, + "282": 63, + "283": 60, + "284": 63, + "285": 66, + "286": 66, + "287": 61, + "288": 68, + "289": 66, + "290": 53, + "291": 64, + "292": 69, + "293": 64, + "294": 63, + "295": 62, + "296": 62, + "297": 63, + "298": 71, + "299": 60, + "300": 61, + "301": 69, + "302": 66, + "303": 73, + "304": 51, + "305": 60, + "306": 62, + "307": 64, + "308": 68, + "309": 67, + "310": 56, + "311": 64, + "312": 68, + "313": 67, + "314": 67, + "315": 69, + "316": 65, + "317": 62, + "318": 67, + "319": 61, + "320": 73, + "321": 67, + "322": 67, + "323": 39, + "324": 59, + "325": 69, + "326": 70, + "327": 59, + "328": 64, + "329": 64, + "330": 59, + "331": 20, + "332": 64, + "333": 67, + "334": 20, + "335": 66, + "336": 62, + "337": 67, + "338": 56, + "339": 61, + "340": 67, + "341": 19, + "342": 58, + "343": 61, + "344": 67, + "345": 68, + "346": 76, + "347": 66, + "348": 57, + "349": 64, + "350": 67, + "351": 81, + "352": 70, + "353": 73, + "354": 39, + "355": 76, + "356": 66, + "357": 70, + "358": 39, + "359": 64, + "360": 63, + "361": 62, + "362": 61, + "363": 74, + "364": 48, + "365": 61, + "366": 66, + "367": 60, + "368": 61, + "369": 70, + "370": 62, + "371": 63, + "372": 73, + "373": 64, + "374": 63, + "375": 54, + "376": 65, + "377": 74, + "378": 67, + "379": 55, + "380": 71, + "381": 61, + "382": 61, + "383": 80, + "384": 67, + "385": 64, + "386": 39, + "387": 84, + "388": 67, + "389": 74, + "390": 39, + "391": 79, + "392": 73, + "393": 74, + "394": 39, + "395": 65, + "396": 50, + "397": 58, + "398": 69, + "399": 64, + "400": 57, + "401": 58, + "402": 62, + "403": 67, + "404": 60, + "405": 53, + "406": 52, + "407": 64, + "408": 62, + "409": 59, + "410": 62, + "411": 62, + "412": 66, + "413": 54, + "414": 75, + "415": 61, + "416": 66, + "417": 52, + "418": 61, + "419": 58, + "420": 62, + "421": 66, + "422": 60, + "423": 63, + "424": 67, + "425": 67, + "426": 62, + "427": 58, + "428": 67, + "429": 68, + "430": 61, + "431": 60, + "432": 65, + "433": 64, + "434": 65, + "435": 64, + "436": 66, + "437": 53, + "438": 66, + "439": 54, + "440": 66, + "441": 71, + "442": 63, + "443": 63, + "444": 54, + "445": 66, + "446": 62, + "447": 65, + "448": 69, + "449": 66, + "450": 63, + "451": 59, + "452": 52, + "453": 65, + "454": 60, + "455": 66, + "456": 62, + "457": 61, + "458": 58, + "459": 64, + "460": 66, + "461": 50, + "462": 63, + "463": 65, + "464": 73, + "465": 54, + "466": 66, + "467": 59, + "468": 50, + "469": 58, + "470": 67, + "471": 58, + "472": 63, + "473": 64, + "474": 60, + "475": 68, + "476": 67, + "477": 52, + "478": 66, + "479": 63, + "480": 151, + "481": 151, + "482": 151, + "483": 152, + "484": 150, + "485": 152, + "486": 151, + "487": 147, + "488": 145, + "489": 142, + "490": 142, + "491": 141, + "492": 140, + "493": 142, + "494": 140, + "495": 140, + "496": 142, + "497": 141, + "498": 142, + "499": 140, + "500": 141, + "501": 114, + "502": 116, + "503": 23, + "504": 23, + "505": 114, + "506": 116, + "507": 23, + "508": 25, + "509": 115, + "510": 116, + "511": 114, + "512": 115, + "513": 23, + "514": 116, + "515": 25, + "516": 115, + "517": 115, + "518": 115, + "519": 131, + "520": 130, + "521": 131, + "522": 137, + "523": 130, + "524": 10, + "525": 131, + "526": 130, + "527": 130, + "528": 130, + "529": 130, + "530": 131, + "531": 111, + "532": 111, + "533": 10, + "534": 111, + "535": 23, + "536": 110, + "537": 111, + "538": 111, + "539": 25, + "540": 25, + "541": 111, + "542": 111, + "543": 25, + "544": 20, + "545": 112, + "546": 111, + "547": 111, + "548": 111, + "549": 130, + "550": 130, + "551": 131, + "552": 129, + "553": 135, + "554": 130, + "555": 128, + "556": 134, + "557": 128, + "558": 128, + "559": 128, + "560": 129, + "561": 22, + "562": 109, + "563": 23, + "564": 108, + "565": 108, + "566": 108, + "567": 23, + "568": 108, + "569": 107, + "570": 26, + "571": 109, + "572": 108, + "573": 22, + "574": 109, + "575": 25, + "576": 108, + "577": 107, + "578": 109, + "579": 107, + "580": 22, + "581": 107, + "582": 23, + "583": 106, + "584": 108, + "585": 106, + "586": 22, + "587": 108, + "588": 106, + "589": 26, + "590": 106, + "591": 106, + "592": 23, + "593": 108, + "594": 25, + "595": 106, + "596": 108, + "597": 26, + "598": 88, + "599": 87, + "600": 88, + "601": 88, + "602": 22, + "603": 89, + "604": 23, + "605": 87, + "606": 89, + "607": 22, + "608": 89, + "609": 88, + "610": 25, + "611": 26, + "612": 89, + "613": 87, + "614": 88, + "615": 95, + "616": 94, + "617": 95, + "618": 25, + "619": 26, + "620": 95, + "621": 95, + "622": 95, + "623": 95, + "624": 25, + "625": 22, + "626": 96, + "627": 94, + "628": 96, + "629": 26, + "630": 22, + "631": 94, + "632": 96, + "633": 10, + "634": 9, + "635": 9, + "636": 10, + "637": 10, + "638": 10, + "639": 10, + "640": 9, + "641": 10, + "642": 10, + "643": 10, + "644": 133, + "645": 10, + "646": 10, + "647": 9, + "648": 9, + "649": 10, + "650": 9, + "651": 10, + "652": 9, + "653": 122, + "654": 9, + "655": 9 + }, + "positive_pivot_credits": {}, + "positive_pivots": 0, + "stats": { + "chart_banks": 9116, + "group_contexts": 9314 + }, + "status": "COMPLETE", + "target": "10018846261809/2500000000000000", + "unresolved_pivots": [], + "whole_signed_baseline": [ + "-300519496095736769319964186406477641296364427008833/5000000000000000000000000000000000000000000000000", + "-150259748047868384659982093203238820648182213480307/2500000000000000000000000000000000000000000000000" + ], + "whole_stock_saving_upper": "0", + "whole_target_margin_upper": "-150259748047868384659982093203238820648182213480307/2500000000000000000000000000000000000000000000000" +} diff --git a/research/bit-fixed-bank-split-bound/README.md b/research/bit-fixed-bank-split-bound/README.md new file mode 100644 index 0000000000..d590da9cd0 --- /dev/null +++ b/research/bit-fixed-bank-split-bound/README.md @@ -0,0 +1,74 @@ +# Retained BIT fixed-bank productive split exclusion + +**NO VERIFIED GAIN. Exact κ change 0%.** On the exact retained #7001 +36-copy BIT invoice, all 434 admissible existing public pivots fail the +paired support test. The census checks 9,116 changed chart banks and +9,314 boundary-group contexts. The maximum compatible savings for +this scope is zero. At κ = 10018846261809/2500000000000000, the complete +margin upper remains approximately −60.10389921914735 raw units. +The complete comparable benchmark is #7277, κ = 0.003645669928698. + +## Exact scope and proof + +Keep every paid child, scalar word, lifetime and caller fixed. A new +independent rank-preserving split must use an old public helper pivot +with its original owner at a strict nested intermediate chart. Allow +arbitrary coframed scalar mixing in its actual live bank and boundary +corrections within the corresponding initial/final helper chart group. + +At a cut let P and S be the literal scalar prefix and suffix. Restrict +the row multipliers a and column directions b to the coframed bank. +The exterior projection vanishes for both c=aP and d=Sb. A feasible +pair must also satisfy a·b=c·d=1 over F₂. Compute the two projected +kernels by exact elimination. For any fixed a, both pairings as forms +on the b kernel must be nonzero, and this suffices for a simultaneous +unit pair: if their witnessing vectors differ, use their sum. In the +a kernel, two nonzero linear maps have a joint nonzero on a basis +vector or a sum of two basis vectors. Checking these cases exhausts +both forms without random sampling. + +The chart, ownership and scalar state of a bank can only change +when an event touches it. Checking affected banks after every event +covers each possible bank state during the declared strict-interior +pivot interval. A reverse replay independently reconstructs the +coverage counts and support and all 62,474 literal lineage edges, +rebuilds the complete old signed price and rejects an omitted MOVE. +Its positive support and contaminated support controls exercise both +outcomes. This proves the scoped zero-stock result with new ordinary +costs granted free. There is no physical build, changed invoice, +full supplier replay or selected-record change. + +## Reproduction + +Use CPython 3.12 with assertions. From a clean checkout: + + python3.12 -B scripts/research_package.py --package research/bit-fixed-bank-split-bound + python3.12 -B scripts/check_research_commit.py --package research/bit-fixed-bank-split-bound --check-modes --check-source-history + +From the official Git-free export root: + + python3.12 -I -B research/bit-fixed-bank-split-bound/replay_package.py --root . + +The two canonical source paths in SOURCES.json are pinned by Git blob +and SHA-256. The replay authenticates the full literal word and invoice, +materializes the path-pinned predecessor closures inside a fresh +temporary directory, checks deterministic PRICE.json and RESULT.json, +and rejects duplicate manifest keys and duplicate source paths. +No prior temporary state, network or Git process is needed. + +## Credit + +#5599 and #5679 supply the cocharted paired-support identity and an +older emitted G20 split. #7271–#7273 study terminal ingress, protected +paid payloads and late exterior correction on the retained word. +This census instead tests independent productive splits with the paid +word fixed. Credit #6726/#7001 for the retained source and signed +invoice, #7294 for exact tariff and replay code, and #7277 for the +complete comparison. OpenAI Codex and subagents materially assisted. + +## Open next questions + +Alternative pivot ownership or a changed native boundary remains open. +First inventory one such bounded scope and price its whole compatible +stock. A survivor needs literal signed action, restoration and the +complete paid and caller invoice. diff --git a/research/bit-fixed-bank-split-bound/RESULT.json b/research/bit-fixed-bank-split-bound/RESULT.json new file mode 100644 index 0000000000..21fc4d2e45 --- /dev/null +++ b/research/bit-fixed-bank-split-bound/RESULT.json @@ -0,0 +1,13 @@ +{ + "bank_census": { + "chart_banks": 9116, + "group_contexts": 9314 + }, + "lineage_edges": 62474, + "omitted_paid_move_rejected": true, + "pivots": 434, + "saving_upper": "0", + "status": "PASS_INDEPENDENT_REVERSE_BANK_STOCK", + "target": "10018846261809/2500000000000000", + "target_margin_upper": "-150259748047868384659982093203238820648182213480307/2500000000000000000000000000000000000000000000000" +} diff --git a/research/bit-fixed-bank-split-bound/SOURCES.json b/research/bit-fixed-bank-split-bound/SOURCES.json new file mode 100644 index 0000000000..64f01435ff --- /dev/null +++ b/research/bit-fixed-bank-split-bound/SOURCES.json @@ -0,0 +1,30 @@ +{ + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "files": [ + { + "git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8", + "path": "certificates/selected-result.json", + "sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1", + "usage": "provenance" + }, + { + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "path": "docs/research/agent-task-catalog.json", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81", + "usage": "provenance" + }, + { + "git_blob": "b718d6b2848215ad785022106dfa9f871a3d1c0c", + "path": "research/paired-query-only-bit/retained/inputs/BIT-NATIVE-WORD.json.gz", + "sha256": "51203e7fc75ba10bd3ac3f8e675759f47e13d262bea66b6600d1e515095cad78", + "usage": "input" + }, + { + "git_blob": "575f76487f9999ecc3e7b1b70f9f71bc582ef8a8", + "path": "research/paired-query-only-bit/EFREE-RESULT.json", + "sha256": "a46b6c6040f75184cab5467656811ad988c216e3bc8e44d595a5015b6e49620b", + "usage": "input" + } + ], + "schema_version": 1 +} diff --git a/research/bit-fixed-bank-split-bound/TASK.json b/research/bit-fixed-bank-split-bound/TASK.json new file mode 100644 index 0000000000..330fd2e758 --- /dev/null +++ b/research/bit-fixed-bank-split-bound/TASK.json @@ -0,0 +1,77 @@ +{ + "actual_scope": "Rank-preserving two-way splits of one independent retained BIT helper using its old public pivot and strictly intermediate existing chart, with the complete caller and paid word fixed.", + "ai_assistance": "OpenAI Codex and subagents materially assisted proof, implementation, independent audit and packaging.", + "author": "Round 37 research campaign", + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "bottleneck_link": "Test the exact support of an optimistic target-clearing helper-stock relaxation before physical implementation.", + "budget_minutes": 2, + "evidence": "Independent reverse census, complete literal 36-copy invoice, exact zero stock, paired support and omitted paid MOVE controls.", + "open_questions": [ + { + "blocked_by": "The new pivot would need exact signed action, returned ownership and restoration with all paid children and caller costs included.", + "first_step": "Group alternative live pivots by nested charts and ownership, then compute a compatible directed whole-stock price before one bounded physical test.", + "question": "Can a different physical pivot or a changed boundary contract restore paired support?", + "why_it_matters": "The existing-pivot stock is empty even with free coframed mixing." + } + ], + "original_card": { + "acceptance_gate": "A full boundary contract and paid profile; unchanged scalar counts alone are insufficient. 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.", + "allowed_variations": [ + "One exact source head, helper/cut region or quantified proposition and changed hypothesis; check live handoffs first. Different seeds are not different scopes." + ], + "bottleneck_link": "Judge the actual current supplier contract and complete signed target/paid bill; frozen-profile ceilings require an applicability proof.", + "existing_checks": [ + { + "evidence": "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "remaining": "The next experiment must identify uncovered source-specific work. Successor archive intake does not transfer this admission.", + "scope": "Selected PR5599: complete helper-subspace construction and independent caller replay; five framework assumptions remain.", + "selected_record_sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5", + "source_commit": "09dd0965711ca7eeb169057a420abab1c9052137", + "status": "reviewed" + } + ], + "first_experiment": "First read #5679/#5708 and their audits as pending component proposals. Choose one uncovered helper group/cut on an exact word; compare arbitrary-input native action, targets, owned storage, both orientations and full signed bill. Stop if the gain is only a scalar count or repaid by lost targets. Do not rerun the frozen #5609 common-frame domain without changing its hypothesis.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read revision 8, the selected review and live exact-source handoffs. Then follow this card's bounded first_experiment.", + "scope": "Source-bound orientation only, not a supplier replay or theorem proof." + }, + "id": "bit-helper-contract", + "methods": [ + "Construct and independently check one source-bound instance of the stated first experiment.", + "Seek an exact counterexample or target-specific complete-budget obstruction to that same proposed change." + ], + "overlap_terms": [ + "G20", + "helper split", + "5679", + "5708", + "independent target" + ], + "question": "Can a changed G20 helper path or independent-target split improve the complete BIT moment without losing its physical endpoint?", + "scope_change_triggers": [ + "Changing source head, helper/cut domain, operation alphabet or caller boundary without recording the new scope.", + "Treating an archived proposal or local numerical pass as complete supplier admission." + ], + "starting_points": [ + "docs/research/current-priorities.md", + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "research/g20-helper-split/README.md", + "research/g20-conjugation-admission/README.md" + ] + }, + "outcome": "negative-result", + "priority_revision": 8, + "schema_version": 1, + "scope_change_reason": "The fixed chart and paid chronology are retained while prospective independent productive outputs change.", + "scope_status": "changed", + "stop_rule": "Census all changed banks or stop at the hard 120-second runner deadline with unresolved stock. Stop without a build if no paired support survives.", + "task_id": "bit-helper-contract" +} diff --git a/research/bit-fixed-bank-split-bound/VERIFY.json b/research/bit-fixed-bank-split-bound/VERIFY.json new file mode 100644 index 0000000000..f46e4fe2e4 --- /dev/null +++ b/research/bit-fixed-bank-split-bound/VERIFY.json @@ -0,0 +1,24 @@ +{ + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/replay_package.py", + "--root", + "." + ], + "checks": "Authenticate the retained BIT source, rebuild and independently replay all cocharted banks, and verify complete signed price and an omitted paid MOVE control.", + "timeout_seconds": 125 + } + ], + "inputs": [ + "research/paired-query-only-bit/retained/inputs/BIT-NATIVE-WORD.json.gz", + "research/paired-query-only-bit/EFREE-RESULT.json" + ], + "python": "3.12", + "requirements": [], + "schema_version": 1, + "status": "ready" +} diff --git a/research/bit-fixed-bank-split-bound/adapter/frozen/INVENTORY.json.gz b/research/bit-fixed-bank-split-bound/adapter/frozen/INVENTORY.json.gz new file mode 100644 index 0000000000..b4e8780280 Binary files /dev/null and b/research/bit-fixed-bank-split-bound/adapter/frozen/INVENTORY.json.gz differ diff --git a/research/bit-fixed-bank-split-bound/adapter/frozen/PRICE.json b/research/bit-fixed-bank-split-bound/adapter/frozen/PRICE.json new file mode 100644 index 0000000000..42c67ae564 --- /dev/null +++ b/research/bit-fixed-bank-split-bound/adapter/frozen/PRICE.json @@ -0,0 +1,23 @@ +{ + "broad_complete_margin_upper": "690963397363603017961423149447292796719482364198299/2500000000000000000000000000000000000000000000000", + "broad_saving_upper": "420611572705735701310702621325265808683832288839303/1250000000000000000000000000000000000000000000000", + "copies": 36, + "eligible_landings": 1665, + "fixed_route_complete_margin_upper": "335574387492769730746168348531919778123315251920731/1250000000000000000000000000000000000000000000000", + "fixed_route_pivots": 434, + "fixed_route_saving_upper": "821408523033407846152318790267078376894812717321769/2500000000000000000000000000000000000000000000000", + "native_helper_histogram": { + "2": 1, + "4": 25, + "6": 1, + "8": 410 + }, + "shortfall": "150259748047868384659982093203238820648182213480307/2500000000000000000000000000000000000000000000000", + "signed_baseline_interval": [ + "-300519496095736769319964186406477641296364427008833/5000000000000000000000000000000000000000000000000", + "-150259748047868384659982093203238820648182213480307/2500000000000000000000000000000000000000000000000" + ], + "status": "PASS_COMPLETE_TERMINAL_SPLIT_STOCK_UPPER", + "target": "10018846261809/2500000000000000", + "total_native_helpers": 437 +} diff --git a/research/bit-fixed-bank-split-bound/adapter/frozen/SUPPORT.json b/research/bit-fixed-bank-split-bound/adapter/frozen/SUPPORT.json new file mode 100644 index 0000000000..c2080daabb --- /dev/null +++ b/research/bit-fixed-bank-split-bound/adapter/frozen/SUPPORT.json @@ -0,0 +1,433 @@ +{ + "bank": [ + 223 + ], + "boundary_group": [ + 222, + 223, + 224, + 225, + 226, + 227, + 228, + 229, + 230, + 231, + 232, + 233, + 234, + 235, + 236, + 237, + 238, + 239, + 240, + 241, + 242, + 243, + 244, + 245, + 246, + 247, + 248, + 249, + 250, + 251, + 252, + 253, + 254, + 255, + 256, + 257, + 258, + 259, + 260, + 261, + 262, + 263, + 264, + 265, + 266, + 267, + 268, + 269, + 270, + 271, + 272, + 273, + 274, + 275, + 276, + 277, + 278, + 279, + 280, + 281, + 282, + 283, + 284, + 285, + 286, + 287, + 288, + 289, + 290, + 291, + 292, + 293, + 294, + 295, + 296, + 297, + 298, + 299, + 300, + 301, + 302, + 303, + 304, + 305, + 306, + 307, + 308, + 309, + 310, + 311, + 312, + 313, + 314, + 315, + 316, + 317, + 318, + 319, + 320, + 321, + 322, + 323, + 324, + 325, + 326, + 327, + 328, + 329, + 330, + 332, + 333, + 335, + 336, + 337, + 338, + 339, + 340, + 342, + 343, + 344, + 345, + 346, + 347, + 348, + 349, + 350, + 351, + 352, + 353, + 354, + 355, + 356, + 357, + 358, + 359, + 360, + 361, + 362, + 363, + 364, + 365, + 366, + 367, + 368, + 369, + 370, + 371, + 372, + 373, + 374, + 375, + 376, + 377, + 378, + 379, + 380, + 381, + 382, + 383, + 384, + 385, + 386, + 387, + 388, + 389, + 390, + 391, + 392, + 393, + 394, + 395, + 396, + 397, + 398, + 399, + 400, + 401, + 402, + 403, + 404, + 405, + 406, + 407, + 408, + 409, + 410, + 411, + 412, + 413, + 414, + 415, + 416, + 417, + 418, + 419, + 420, + 421, + 422, + 423, + 424, + 425, + 426, + 427, + 428, + 429, + 430, + 431, + 432, + 433, + 434, + 435, + 436, + 437, + 438, + 439, + 440, + 441, + 442, + 443, + 444, + 445, + 446, + 447, + 448, + 449, + 450, + 451, + 452, + 453, + 454, + 455, + 456, + 457, + 458, + 459, + 460, + 461, + 462, + 463, + 464, + 465, + 466, + 467, + 468, + 469, + 470, + 471, + 472, + 473, + 474, + 475, + 476, + 477, + 478, + 479, + 480, + 481, + 482, + 483, + 484, + 485, + 486, + 487, + 488, + 489, + 490, + 491, + 492, + 493, + 494, + 495, + 496, + 497, + 498, + 499, + 500, + 501, + 502, + 503, + 504, + 505, + 506, + 507, + 508, + 509, + 510, + 511, + 512, + 513, + 514, + 515, + 516, + 517, + 518, + 519, + 520, + 521, + 522, + 523, + 524, + 525, + 526, + 527, + 528, + 529, + 530, + 531, + 532, + 533, + 534, + 535, + 536, + 537, + 538, + 539, + 540, + 541, + 542, + 543, + 544, + 545, + 546, + 547, + 548, + 549, + 550, + 551, + 552, + 553, + 554, + 555, + 556, + 557, + 558, + 559, + 560, + 561, + 562, + 563, + 564, + 565, + 566, + 567, + 568, + 569, + 570, + 571, + 572, + 573, + 574, + 575, + 576, + 577, + 578, + 579, + 580, + 581, + 582, + 583, + 584, + 585, + 586, + 587, + 588, + 589, + 590, + 591, + 592, + 593, + 594, + 595, + 596, + 597, + 598, + 599, + 600, + 601, + 602, + 603, + 604, + 605, + 606, + 607, + 608, + 609, + 610, + 611, + 612, + 613, + 614, + 615, + 616, + 617, + 618, + 619, + 620, + 621, + 622, + 623, + 624, + 625, + 626, + 627, + 628, + 629, + 630, + 631, + 632, + 644, + 653 + ], + "clock": 19154, + "cut_chart": 270, + "decision": "NO_PAIRED_UNIT_SUPPORT_IN_ONE_BANK", + "left_cases": 0, + "left_dimension": 0, + "per_copy_credit_interval": [ + "110343644124803735641520229225968828347701519193/5000000000000000000000000000000000000000000000000", + "22068728824960747128304045845193765669540303839/1000000000000000000000000000000000000000000000000" + ], + "pivot": 223, + "right_dimension": 0, + "split_ranks": [ + 4, + 4 + ], + "witness": null +} diff --git a/research/bit-fixed-bank-split-bound/adapter/verify.py b/research/bit-fixed-bank-split-bound/adapter/verify.py new file mode 100644 index 0000000000..046b6db6af --- /dev/null +++ b/research/bit-fixed-bank-split-bound/adapter/verify.py @@ -0,0 +1,220 @@ +"""Independently reconstruct terminal inventory backward and the singleton obstruction.""" +from argparse import ArgumentParser +from collections import Counter, defaultdict +from fractions import Fraction as F +from functools import cache +import gzip +from hashlib import sha256 +import json +from pathlib import Path +import runpy +from signal import alarm + +HERE = Path(__file__).resolve().parent + + +def reverse(word): + n = word['public'] + program = word['program'] + order = list(range(n+word['owned_fields'])) + for op,d,*args in program: + if op == 'SWAP': + s = args[0] + order[d],order[s] = order[s],order[d] + assert set(order[:n]) == set(range(n)) + owner = order[:n]+[None]*word['owned_fields'] + chart = word['final']+[None]*word['owned_fields'] + landings = defaultdict(list) + moves = Counter() + + def landing(i,t): + if 222<=i=n + owner[d],chart[d] = n+t,args[0] + elif op == 'INIT': + assert owner[d]>=n and chart[d]==args[0] + owner[d] = chart[d] = None + else: + assert op=='ADD' and chart[d]==chart[args[0]]==args[1] + assert owner == list(range(n))+[None]*word['owned_fields'] + assert chart == word['start']+[None]*word['owned_fields'] + return moves, landings + + +def rank(rows): + pivots = {} + for raw in rows: + row = list(raw) + for col in range(len(row)): + if not row[col]: + continue + if col not in pivots: + pivots[col] = [x/row[col] for x in row] + break + p = row[col] + row = [x-p*y for x,y in zip(row,pivots[col],strict=True)] + return len(pivots) + + +def support_column(rows, pivot, adjoint): + x = 1<>s&1: + x ^= 1<>d)^(x>>s))&1: + x ^= (1<0 + + chosen = json.loads((receipt/'SUPPORT.json').read_bytes()) + _,t,pivot,frame,left,r = min(ranked) + assert (chosen['clock'],chosen['pivot'],chosen['cut_chart'],chosen['split_ranks'])==(t,pivot,frame,[left,r-left]) + chart = word['start']+[None]*word['owned_fields'] + program = word['program'] + for op,d,*args in program[:t+1]: + if op == 'SWAP': + s = args[0] + chart[d],chart[s] = chart[s],chart[d] + elif op in ('MOVE','INIT'): + chart[d] = args[-1] + elif op == 'CLEAR': + chart[d] = None + assert [i for i,f in enumerate(chart) if f==frame] == chosen['bank'] == [pivot] + group = [i for i in range(222,word['public']) if (word['start'][i],word['final'][i]) == + (word['start'][pivot],word['final'][pivot])] + assert group == chosen['boundary_group'] + other = ((1<>i&1], + 'right_contaminating_boundary_outputs':[i for i in range(word['public']) if right>>i&1], + 'fixed_route_support_unresolved_landings':count-1, + 'fixed_route_support_unresolved_pivots':len(ranked)-int(sum(x['helper']==pivot and len(x['interior_landings'])==1 for x in inv['helpers']))} + + +if __name__=='__main__': + assert __debug__ + p = ArgumentParser(description=__doc__) + p.add_argument('dependency_root',type=Path) + p.add_argument('receipt',type=Path) + a = p.parse_args() + alarm(60) + print(json.dumps(verify(a.dependency_root,a.receipt),sort_keys=True,indent=2)) + alarm(0) diff --git a/research/bit-fixed-bank-split-bound/adapter/worker.py b/research/bit-fixed-bank-split-bound/adapter/worker.py new file mode 100644 index 0000000000..e2cbb66288 --- /dev/null +++ b/research/bit-fixed-bank-split-bound/adapter/worker.py @@ -0,0 +1,257 @@ +"""Bound productive splits on the retained BIT terminal stock.""" +from collections import Counter, defaultdict +from fractions import Fraction as F +from functools import cache +import gzip +from hashlib import sha256 +from itertools import combinations +import json +from pathlib import Path +import runpy +import sys +from time import monotonic + +PINS = { + 'replay.py': '7be49a2c71ffb76a27229f0e307043d37a2da10d707ba4fe3cebbe100392d557', + 'audit.py': '3aec134ceb6da7e6cf42ff8134ce3d7de62c06aa2f168fae95623d0fdb79f0c3', + 'price.py': '6a33aac4c7032de9bb3881da248f5371b69c6b9af0893220825727f3d4878fae', + 'CONTINUATION.json': '1b99adc18dc7bb1839cc98d17b3be022bae939dd16d0f7d6bcea8fc24cd1f678', + 'inputs/INVOICE.json': 'a46b6c6040f75184cab5467656811ad988c216e3bc8e44d595a5015b6e49620b', + 'inputs/WORD.json.gz': '51203e7fc75ba10bd3ac3f8e675759f47e13d262bea66b6600d1e515095cad78', +} +TARGET = F(10018846261809, 2500000000000000) + + +def load(root): + raw = {} + for name, expected in PINS.items(): + data = (root/name).read_bytes() + assert sha256(data).hexdigest() == expected, name + raw[name] = data + return json.loads(gzip.decompress(raw['inputs/WORD.json.gz'])), json.loads(raw['inputs/INVOICE.json']), raw + + +def save(root, name, value): + target = root/name + temp = target.with_suffix('.tmp') + temp.write_text(json.dumps(value, indent=2, sort_keys=True)+'\n') + temp.replace(target) + + +def moves_and_contacts(word, clock): + public = word['public'] + owners = list(range(public))+[None]*word['owned_fields'] + charts = list(word['start'])+[None]*word['owned_fields'] + visits = defaultdict(list) + moves = Counter() + for t,(op,dst,*args) in enumerate(word['program']): + if t%512 == 0: + clock() + owner = owners[dst] + if op == 'SWAP': + src = args[0] + owners[src],owners[dst] = owners[dst],owners[src] + charts[src],charts[dst] = charts[dst],charts[src] + for slot in (src,dst): + if 222 <= slot < public and owners[slot] == slot: + visits[slot].append((t,charts[slot])) + elif op == 'INIT': + assert owner is charts[dst] is None and dst>=public + owners[dst],charts[dst] = public+t,args[0] + elif op == 'CLEAR': + assert owner >= public and charts[dst] == args[0] and dst>=public + owners[dst] = charts[dst] = None + elif op == 'MOVE': + a,b = args + assert a == charts[dst] and a != b and owner is not None + moves[a,b] += 1 + charts[dst] = b + if 222 <= owner < public and dst == owner: + visits[owner].append((t,b)) + else: + assert op == 'ADD' and charts[dst] == charts[args[0]] == args[1] + assert owner is not None and owners[args[0]] is not None + assert set(owners[:public]) == set(range(public)) + assert owners[public:] == [None]*word['owned_fields'] + assert charts == word['final']+[None]*word['owned_fields'] + return moves,visits + + +def fold(rows, selection): + value = 0 + while selection: + bit = selection & -selection + value ^= rows[bit.bit_length()-1] + selection ^= bit + return value + + +def kernel(rows): + pivots = {} + basis = [] + for i,row in enumerate(rows): + witness = 1<= deadline: + raise TimeoutError('BIT round deadline') + word,invoice,raw = load(root) + math = runpy.run_path(str(root/'price.py')) + moves,visits = moves_and_contacts(word,clock) + baseline_moves,_,_ = math['walk'](word) + assert moves == Counter((a,b) for a,b,_ in baseline_moves.values()) + dims = {int(f):row['dim'] for f,row in word['frames'].items()} + bases = {int(f):[tuple(map(F,b)) for b in row['B']] for f,row in word['frames'].items()} + + @cache + def normals(frame): + return math['annihilator'](bases[frame]) + + @cache + def contains(low,high): + return all(not sum(a*b for a,b in zip(row,n,strict=True)) + for row in bases[low] for n in normals(high)) + + native = Counter() + for (a,b),count in moves.items(): + low,high = sorted((a,b),key=dims.__getitem__) + assert dims[high]>dims[low] and contains(low,high) + native[dims[high]-dims[low]] += count + signed,copies = math['profile'](invoice,native,word,dims) + baseline = math['cost'](signed,TARGET) + assert baseline == tuple(map(F,json.loads(raw['CONTINUATION.json'])['signed_original_net'])) + + @cache + def price(rank,left): + hist = Counter((left,rank-left)) + hist[rank] -= 1 + return math['cost'](hist,TARGET) + + inventory = [] + order = [] + broad = fixed = F(0) + for role in range(222,word['public']): + clock() + lo,hi = word['start'][role],word['final'][role] + rank = dims[hi]-dims[lo] + assert rank>=2 and contains(lo,hi) + best = price(rank,rank//2)[1] + assert all(price(rank,k)[1]<=best for k in range(1,rank)) + broad += best + choices = [] + for t,f in visits[role]: + if dims[lo] < dims[f] < dims[hi] and contains(lo,f) and contains(f,hi): + left = dims[f]-dims[lo] + choices.append([t,f,left]) + if choices: + t,f,left = min(choices,key=lambda x:(-price(rank,x[2])[1],x)) + gain = price(rank,left)[1] + fixed += gain + order.append((-gain,t,role,f,left,rank)) + inventory.append({'helper':role,'initial_chart':lo,'final_chart':hi,'rank':rank, + 'observed_chart_landings':len(visits[role]),'interior_landings':choices}) + save(out,'INVENTORY.json',{'relative_pins':PINS,'helpers':inventory,'paid_moves':sum(native.values()), + 'paid_histogram':dict(native),'copies':copies}) + broad *= copies + fixed *= copies + receipt = {'status':'PASS_COMPLETE_TERMINAL_SPLIT_STOCK_UPPER','target':str(TARGET),'copies':copies, + 'shortfall':str(-baseline[1]),'signed_baseline_interval':list(map(str,baseline)), + 'native_helper_histogram':dict(Counter(row['rank'] for row in inventory)), + 'total_native_helpers':len(inventory),'fixed_route_pivots':len(order), + 'eligible_landings':sum(len(r['interior_landings']) for r in inventory), + 'broad_saving_upper':str(broad),'fixed_route_saving_upper':str(fixed), + 'broad_complete_margin_upper':str(baseline[1]+broad), + 'fixed_route_complete_margin_upper':str(baseline[1]+fixed)} + save(out,'PRICE.json',receipt) + if baseline[1]+fixed >= 0: + _,t,role,f,left,rank = min(order) + result = support(word,role,t,f,clock) + result['split_ranks'] = [left,rank-left] + result['per_copy_credit_interval'] = list(map(str,price(rank,left))) + save(out,'SUPPORT.json',result) + save(out,'DONE.json',{'support_tests':int((out/'SUPPORT.json').exists()),'status':'COMPLETE'}) + + +if __name__ == '__main__': + assert __debug__ + run(Path(sys.argv[1]),Path(sys.argv[2]),float(sys.argv[3])) diff --git a/research/bit-fixed-bank-split-bound/deps/CONTINUATION.json.gz b/research/bit-fixed-bank-split-bound/deps/CONTINUATION.json.gz new file mode 100644 index 0000000000..352274d35a Binary files /dev/null and b/research/bit-fixed-bank-split-bound/deps/CONTINUATION.json.gz differ diff --git a/research/bit-fixed-bank-split-bound/deps/audit.py b/research/bit-fixed-bank-split-bound/deps/audit.py new file mode 100644 index 0000000000..914e8ef86a --- /dev/null +++ b/research/bit-fixed-bank-split-bound/deps/audit.py @@ -0,0 +1,201 @@ +"""Independently check every BIT label flow/cut and its complete invoice.""" +from collections import Counter, defaultdict +from fractions import Fraction as F +from functools import cache +import gzip +from hashlib import sha256 +from itertools import pairwise +import json +from pathlib import Path +import runpy +from time import monotonic + +ROOT=Path(__file__).resolve().parent + + +def incidence(word): + n=word['public'] + slots=list(range(n))+[None]*word['owned_fields'] + attr=[(f,False,-1) for f in word['start']] + visits={i:[i] for i in range(n)} + paid=[] + for t,(op,i,*a) in enumerate(word['program']): + if op=='SWAP': + j=a[0] + slots[i],slots[j]=slots[j],slots[i] + elif op=='MOVE': + paid.append(tuple(a)) + else: + v=len(attr) + attr.append((a[-1],True,t)) + if op=='INIT': + assert slots[i] is None + slots[i]=n+t + visits[n+t]=[v] + else: + visits[slots[i]].append(v) + if op=='ADD' and a[0]!=i: + visits[slots[a[0]]].append(v) + if op=='CLEAR': + slots[i]=None + assert all(v is None for v in slots[n:]) + for i,f in enumerate(word['final']): + visits[slots[i]].append(len(attr)) + attr.append((f,False,len(word['program']))) + assert len(visits)==n+237 + edges=[edge for seq in visits.values() for edge in pairwise(seq)] + assert Counter((attr[u][0],attr[v][0]) for u,v in edges if attr[u][0]!=attr[v][0])==Counter(paid) + return attr,edges,paid + + +def linrank(rows): + pivot={} + for row in rows: + r=list(row) + for j in range(len(r)): + x=r[j] + if not x: + continue + if j in pivot: + r=[a-x*b for a,b in zip(r,pivot[j],strict=True)] + else: + pivot[j]=[a/x for a in r] + break + return len(pivot) + + +def add(cap,u,v,w): + if u!=v and w: + cap[u,v]+=w + + +def certify(caps, flow, side, source, sink, n): + balance=[0]*n + used=set() + for u,v,f in flow: + if (u,v) in used or not 0= public and slots[i] == (None, None, 0) + slots[i] = (public + clock, f, 0) + ownership["init"] += 1 + continue + assert owner is not None + history[owner].append((clock, op)) + if op == "MOVE": + src, dst = args + assert src == frame and src != dst + if observe_move is not None: + observe_move(clock, i, src, dst, row, slots) + moves[clock] = (src, dst, row) + slots[i] = (owner, dst, row) + elif op == "ADD": + j, f = args + other, other_frame, other_row = slots[j] + assert other is not None and frame == f == other_frame + if other != owner: + history[other].append((clock, op)) + slots[i] = (owner, frame, row ^ other_row) + else: + assert op == "CLEAR" and i >= public and args == [frame] + ownership["clear"] += 1 + slots[i] = (None, None, 0) + assert [x[1] for x in slots] == word["final"] + [None] * word["owned_fields"] + expected = [1 << j if j < public else 0 for j in range(len(slots))] + for j in range(111): + expected[j + 111] ^= 1 << j + assert [x[2] for x in slots] == expected + + runs = [] + for records in history.values(): + chain = [] + for clock, op in records: + if op == "MOVE": + chain.append(clock) + elif chain: + runs.append(tuple(chain)) + chain.clear() + if chain: + runs.append(tuple(chain)) + runs.sort() + covered = [t for run in runs for t in run] + assert len(covered) == len(set(covered)) == len(moves) and set(covered) == set(moves) + assert all(moves[i][1] == moves[j][0] for run in runs for i, j in zip(run, run[1:])) + return moves, runs, ownership + + +def annihilator(rows): + """Exact RREF, then a basis of the right nullspace of each chart.""" + matrix = [list(map(Fraction, row)) for row in rows] + pivots = [] + for col in range(8): + pivot = len(pivots) + hit = next((i for i in range(pivot, len(matrix)) if matrix[i][col]), None) + if hit is None: + continue + matrix[hit], matrix[pivot] = matrix[pivot], matrix[hit] + a = matrix[pivot] + p = a[col] + matrix[pivot] = [x / p for x in a] + for i, row in enumerate(matrix): + if i != pivot and row[col]: + b = row[col] + matrix[i] = [x - b*y for x, y in zip(row, matrix[pivot], strict=True)] + pivots.append(col) + assert len(pivots) == len(rows) + normals = [] + for f in set(range(8)) - set(pivots): + v = [Fraction(0)] * 8 + v[f] = Fraction(1) + for i, p in enumerate(pivots): + v[p] = -matrix[i][f] + normals.append(v) + return normals + + +def verify_incidence(word, moves, runs): + ranks = {int(f): v["dim"] for f, v in word["frames"].items()} + bases = {int(f): [[Fraction(x) for x in row] for row in v["B"]] + for f, v in word["frames"].items()} + assert all(len(bases[f]) == r for f, r in ranks.items()) + + @cache + def normals(frame): + return annihilator(bases[frame]) + + @cache + def endpoint_type(src, dst): + if src == dst: + return "identical" + if ranks[src] == ranks[dst]: + return "equal_rank_distinct" + low, high = sorted((src, dst), key=ranks.__getitem__) + if any(sum(a*b for a, b in zip(row, normal, strict=True)) + for row in bases[low] for normal in normals(high)): + return "nonnested" + return "nested" + + total = Counter() + domains = [] + for chain in runs: + starting = defaultdict(list) + for i, a in enumerate(chain): + for j in range(i + 1, len(chain)): + b = chain[j] + src, dst = moves[a][0], moves[b][1] + kind = endpoint_type(src, dst) + total[kind] += 1 + if kind in ("identical", "nested"): + delta = Counter(abs(ranks[moves[t][0]] - ranks[moves[t][1]]) + for t in chain[i:j+1]) + if src != dst: + delta[abs(ranks[src] - ranks[dst])] -= 1 + starting[i].append((j+1, (a, b, src, dst), delta)) + domains.append((len(chain), starting)) + old = Counter(abs(ranks[src] - ranks[dst]) for src, dst, _ in moves.values()) + return total, domains, old, ranks + + +def rounded(x, upper): + scaled = SCALE*x + if upper: + return Fraction(-((-scaled.numerator) // scaled.denominator), SCALE) + return Fraction(scaled.numerator // scaled.denominator, SCALE) + + +@cache +def log_bounds(x): + z = (x-1)/(x+1) + terms = 60 + exact_partial = 2*sum(z**(2*i+1)/(2*i+1) for i in range(terms)) + tail = 2*z**(2*terms+1)/((2*terms+1)*(1-z*z)) + return rounded(exact_partial, False), rounded(exact_partial+tail, True) + + +@cache +def power_bounds(rank, k): + binary = 2**(rank.bit_length()-1) + shift = binary.bit_length()-1 + l2, u2 = log_bounds(Fraction(2)) + lo, hi = log_bounds(Fraction(rank, binary)) + lo, hi = k*(lo+shift*l2), k*(hi+shift*u2) + assert 0 <= lo <= hi < 1 + + def exponential(z, terms): + total = term = Fraction(1) + for i in range(1, terms+1): + term *= -z/i + total += term + return total + + return rounded(rank*exponential(hi, 35), False), rounded(rank*exponential(lo, 34), True) + + +def cost(hist, k): + lower = upper = Fraction(0) + for r, n in hist.items(): + a, b = (n*x for x in power_bounds(r, k)) + lower += min(a, b) + upper += max(a, b) + return lower, upper + + +def optimize(domains, copies, k, declared): + valid = {} + totals = [Fraction(0), Fraction(0)] + for chain, (n, starts) in enumerate(domains): + def extreme(side): + suffix = [Fraction(0)] * (n+1) + for i in range(n-1, -1, -1): + suffix[i] = max( + [suffix[i+1]] + + [suffix[j] + cost(delta, k)[side] for j, _, delta in starts[i]] + ) + return suffix[0] + for side in (0, 1): + totals[side] += copies*extreme(side) + for i, intervals in starts.items(): + for j, key, delta in intervals: + assert key not in valid + valid[key] = (chain, i, j, delta) + seen = set() + chosen = Counter() + for item in declared: + key = tuple(item) + if key not in valid: + raise ValueError(f"invalid chosen interval {item}") + chain, i, j, delta = valid[key] + paid = {(chain, x) for x in range(i, j)} + if seen & paid: + raise ValueError(f"overlapping chosen interval {item}") + seen.update(paid) + chosen.update(delta) + return totals, cost({r: copies*n for r, n in chosen.items()}, k) + + +def intersect(a, b): + return max(a[0], b[0]) <= min(a[1], b[1]) + + +def profile(invoice, native, word, ranks): + copies = invoice["native_calls"] + assert copies == len(invoice["native_instances"]) == 36 + assert {tuple((r["stage"], r["copy"])) for r in invoice["native_instances"]} == { + (stage, which) for stage in range(1, 19) for which in (0, 1) + } + assert all(r["ports"] == 111 for r in invoice["native_instances"]) + assert native == Counter({int(r): n for r, n in invoice["native_paid"].items()}) + assert sum(native.values()) == 2871 + caller_paid = {1: 444, **{r: 444 for r in range(7, 57, 7)}} + assert invoice["event_counts"]["QUERY"]*111 == caller_paid[1] + assert invoice["event_counts"]["IDLE_ONE"]*111 == 8*444 + full_paid = Counter({r: copies*n for r, n in native.items()}) + full_paid.update(caller_paid) + + helpers = Counter(ranks[word["final"][j]]-ranks[word["start"][j]] + for j in range(222, word["public"])) + assert helpers == Counter({int(r): n for r, n in invoice["native_helpers"].items()}) + caller_targets = {**{r: 444 for r in range(8, 65, 7)}, 127: 222} + full_targets = Counter({r: copies*n for r, n in helpers.items()}) + full_targets.update(caller_targets) + assert full_paid == Counter({int(r): n for r, n in invoice["paid"].items()}) + assert full_targets == Counter({int(r): n for r, n in invoice["targets"].items()}) + assert sum(full_paid.values()) == invoice["paid_jobs"] + assert sum(full_targets.values()) == invoice["productive_fields"] + signed = full_targets.copy() + signed.subtract(full_paid) + assert sum(r*n for r, n in signed.items()) == invoice["rank_surplus"] + return signed, copies + + +def audit(root, receipt): + word, invoice, pins = read_inputs(root) + assert receipt["status"] == "PASS_WHOLE_WORD_FUSION_UPPER" + assert receipt["pins"] == pins + assert invoice["native_source_sha256"] == pins[WORD] + moves, runs, ownership = walk(word) + counts, domains, old, ranks = verify_incidence(word, moves, runs) + signed, copies = profile(invoice, old, word, ranks) + path_lengths = Counter(map(len, runs)) + assert {str(r): n for r, n in path_lengths.items()} == receipt["path_length_histogram"] + assert {str(r): n for r, n in old.items()} == receipt["charged_ranks"] + assert receipt["native_paid_moves"] == sum(old.values()) and receipt["native_instances"] == copies + assert receipt["physical_sites"] == 0 + audit_result = {} + for trial, declared in receipt["result"].items(): + k = Fraction(trial) + expected_case_count = sum(counts.values()) + expected_eligible_count = counts["nested"] + counts["identical"] + if declared["cases_visited"] != expected_case_count or declared["eligible_intervals"] != expected_eligible_count: + raise ValueError("incorrect exhaustive incidence counters") + savings, chosen = optimize(domains, copies, k, declared["optimistic_argmax"]) + baseline = cost(signed, k) + net = [a+b for a,b in zip(baseline, savings, strict=True)] + for field, v in (("saving_interval", savings), ("raw_comparator_net", baseline), + ("net_after_free_fusion", net)): + if not intersect(v, list(map(Fraction, declared[field]))): + raise ValueError(f"forged {field}") + if not intersect(chosen, list(map(Fraction, declared["saving_interval"]))): + raise ValueError("selected intervals fail to realize claimed upper at price precision") + audit_result[trial] = { + "baseline": list(map(str, baseline)), + "saving": list(map(str, savings)), + "net": list(map(str, net)), + "selected_interval_saving": list(map(str, chosen)), + } + assert TARGET in audit_result + if Fraction(audit_result[TARGET]["net"][1]) < 0: + assert set(audit_result) == {TARGET} + return { + "status": "PASS_INDEPENDENT_FUSION_AUDIT", + "paid_moves": len(moves), + "ownership": dict(ownership), + "paths": len(runs), + "incidence_by_endpoint": dict(counts), + "source_sha256": pins[WORD], + "invoice_sha256": pins[INVOICE], + "independent_result": audit_result, + } + + +def control(): + e1 = [1, 0, 0, 0, 0, 0, 0, 0] + e2 = [0, 1, 0, 0, 0, 0, 0, 0] + frames = {"0": {"dim": 0, "B": []}, "1": {"dim": 1, "B": [e1]}, + "2": {"dim": 2, "B": [e1, e2]}} + moves = {0: (0, 1, 0), 2: (1, 2, 0), 4: (2, 0, 0)} + counts, domains, _, _ = verify_incidence({"frames": frames}, moves, [(0, 2, 4)]) + assert counts == {"nested": 2, "identical": 1} + savings, selected = optimize(domains, 36, Fraction(TARGET), [(0, 4, 0, 0)]) + assert tuple(savings) == selected and savings[0] > 0 + try: + optimize(domains, 36, Fraction(TARGET), [(0, 2, 0, 2), (0, 4, 0, 0)]) + except ValueError as error: + assert "overlapping" in str(error) + else: + raise AssertionError("overlap control accepted a double-spent paid MOVE") + + +def main(): + parser = ArgumentParser(description=__doc__) + parser.add_argument("input_root", type=Path) + parser.add_argument("receipt", type=Path) + args = parser.parse_args() + assert __debug__ + control() + receipt = json.loads(args.receipt.read_bytes()) + print(json.dumps(audit(args.input_root, receipt), indent=2, sort_keys=True)) + + +if __name__ == "__main__": + main() diff --git a/research/bit-fixed-bank-split-bound/deps/replay.py b/research/bit-fixed-bank-split-bound/deps/replay.py new file mode 100644 index 0000000000..850edf466e --- /dev/null +++ b/research/bit-fixed-bank-split-bound/deps/replay.py @@ -0,0 +1,240 @@ +"""Price coupled fixed-order BIT chart labels over one nested pair at a time.""" +from argparse import ArgumentParser +from collections import Counter, defaultdict +from fractions import Fraction as F +from functools import cache +import gzip +from hashlib import sha256 +import json +from pathlib import Path +import runpy +from time import monotonic + +ROOT=Path(__file__).resolve().parent +PINS={ + 'mincut.py':'c6b09de3e6c1f343d53dc099ca23c9bcace150517b1428e0b3bc1e3857bd6a5a', + 'price.py':'6a33aac4c7032de9bb3881da248f5371b69c6b9af0893220825727f3d4878fae', + 'inputs/INVOICE.json':'a46b6c6040f75184cab5467656811ad988c216e3bc8e44d595a5015b6e49620b', + 'inputs/WORD.json.gz':'51203e7fc75ba10bd3ac3f8e675759f47e13d262bea66b6600d1e515095cad78', +} + + +def graph(w): + charts=w['start']+[None]*w['owned_fields'] + previous=list(range(w['public']))+[None]*w['owned_fields'] + due=[None]*len(previous) + vertices=[(f,False,-1) for f in w['start']] + edges=[] + old=[] + events=Counter() + + def append(r,v): + a,b=vertices[previous[r]][0],vertices[v][0] + assert (due[r] is None and a==b) or due[r]==(a,b) + edges.append((previous[r],v)) + due[r]=None + previous[r]=v + + for t,(op,r,*a) in enumerate(w['program']): + events[op]+=1 + if op=='SWAP': + other=a[0] + for arr in (charts,previous,due): + arr[r],arr[other]=arr[other],arr[r] + continue + if op=='MOVE': + before,after=a + assert charts[r]==before and previous[r] is not None and due[r] is None + due[r]=before,after + charts[r]=after + old.append((before,after)) + continue + v=len(vertices) + f=a[-1] + vertices.append((f,True,t)) + if op=='INIT': + assert charts[r] is previous[r] is due[r] is None + charts[r]=f + previous[r]=v + else: + assert charts[r]==f and previous[r] is not None + append(r,v) + if op=='ADD': + other=a[0] + if other!=r: + assert charts[other]==f and previous[other] is not None + append(other,v) + else: + assert op=='CLEAR' + charts[r]=previous[r]=None + assert charts==w['final']+[None]*w['owned_fields'] + for r,f in enumerate(w['final']): + v=len(vertices) + vertices.append((f,False,len(w['program']))) + append(r,v) + assert all(x is None for x in due) + assert events=={'ADD':30789,'MOVE':2871,'INIT':237,'CLEAR':237,'SWAP':3} + observed=Counter((vertices[u][0],vertices[v][0]) for u,v in edges if vertices[u][0]!=vertices[v][0]) + assert observed==Counter(old) + return vertices,edges,old + + +def run(retry=False,remaining=False): + retry=retry or remaining + start=monotonic() + blobs={} + assert __debug__ + for f,d in PINS.items(): + raw=(ROOT/f).read_bytes() + if sha256(raw).hexdigest()!=d: + raise ValueError(f'changed source {f}') + blobs[f]=raw + word=json.loads(gzip.decompress(blobs['inputs/WORD.json.gz'])) + invoice=json.loads(blobs['inputs/INVOICE.json']) + p=runpy.run_path(str(ROOT/'price.py')) + flow=runpy.run_path(str(ROOT/'mincut.py')) + flow['controls']() + verts,edges,old=graph(word) + dims={int(j):f['dim'] for j,f in word['frames'].items()} + bases={int(j):[list(map(F,row)) for row in f['B']] for j,f in word['frames'].items()} + norms={i:p['annihilator'](rows) for i,rows in bases.items()} + scope=sorted({(a,b) if dims[a]=180: + return {'status':'INCOMPLETE_EDGE_SCREEN','checked':len(results), + 'unvisited':scope[len(results):], 'results':results,'pins':PINS} + assert rank(a,b)==1 + ids=incident[a]|incident[b] + total=0 + for i in ids: + opts=[(a,b) if verts[v][1] and verts[v][0] in (a,b) else (verts[v][0],) for v in edges[i]] + admissible=[tariffs[r][0] for x in opts[0] for y in opts[1] if (r:=rank(x,y)) is not None] + total+=tariffs[old_edges[i]][1]-min(admissible) + bound=base[1]+copies*F(total,grid) + results.append([a,b,str(bound)]) + if bound>=0: + ranked.append((bound,a,b)) + + if retry: + prior=json.loads((ROOT/'RESULT.json').read_bytes()) + assert prior['edgewise']==results and not prior['exact_cuts'] + assert sha256((ROOT/'flow.py').read_bytes()).hexdigest()=='41238bd85a516550c3eace6891baf6d8ceb67625940758c7001ad26ba2f6c58b' + solve=runpy.run_path(str(ROOT/'flow.py'))['dinic'] + exact=[] + if remaining: + raw=(ROOT/'RETRY.json').read_bytes() + assert sha256(raw).hexdigest()=='f52158e2ffabb4d9499d99f374586307008d37e9df4f1fbefb279f7f0f8f010c' + certified=json.loads(raw) + assert certified['edgewise']==results and len(certified['exact_cuts'])==16 + exact=certified['exact_cuts'] + done={tuple(x['pair']) for x in exact} + cut_start=monotonic() + inf=sum(tariffs[old_edges[i]][1] for i in range(len(edges)))+1 + ordered=sorted(ranked,key=lambda x:(-x[0],x[1],x[2])) + for _,a,b in ordered[:len(ordered) if remaining else 16]: + if (a,b) in done: + continue + def clock(): + if monotonic()-cut_start>=(180 if remaining else 90): + raise TimeoutError + try: + clock() + ids=incident[a]|incident[b] + variables=sorted({v for i in ids for v in edges[i] if verts[v][1] and verts[v][0] in (a,b)}) + ids_of={v:i for i,v in enumerate(variables)} + unary=[[0,0] for _ in variables] + arcs=[] + for i in sorted(ids): + u,v=edges[i] + mutable=(u in ids_of,v in ids_of) + if all(mutable): + arcs.extend(((ids_of[u],ids_of[v],tariffs[1][0]),(ids_of[v],ids_of[u],tariffs[1][0]))) + else: + j,k=(u,v) if mutable[0] else (v,u) + assert j in ids_of and k not in ids_of + for bit,f in enumerate((a,b)): + rr=rank(f,verts[k][0]) + unary[ids_of[j]][bit]+=inf if rr is None else tariffs[rr][0] + certificate=None + if retry: + source,sink=len(unary),len(unary)+1 + cap=defaultdict(int) + shift=0 + for j,(lower,higher) in enumerate(unary): + m=min(lower,higher) + shift+=m + cap[source,j]+=higher-m + cap[j,sink]+=lower-m + for u,v,w in arcs: + if u!=v: + cap[u,v]+=w + flow_value,certificate,cut=solve(len(unary)+2,source,sink,cap,clock) + reachable=set(cut) + assign=[int(j not in reachable) for j in range(len(unary))] + value=flow_value+shift + else: + value,assign=flow['mincut'](unary,arcs,clock) + labels={v:(a,b)[c] for v,c in zip(variables,assign,strict=True)} + old_hi=sum(tariffs[old_edges[i]][1] for i in ids) + replacement=Counter() + original=Counter(old_edges[i] for i in ids) + for i in ids: + u,v=edges[i] + rr=rank(labels.get(u,verts[u][0]),labels.get(v,verts[v][0])) + assert rr is not None + replacement[rr]+=1 + assert value==sum(n*tariffs[r][0] for r,n in replacement.items()) + delta=Counter({r:copies*(original[r]-replacement[r]) for r in set(original)|set(replacement) if r}) + actual=p['cost'](delta,F(p['TARGET'])) + upper=base[1]+copies*F(old_hi-value,grid) + exact.append({'pair':[a,b],'signed_paid_saving_hist':dict(delta),'flow_certificate':certificate,'affected_edges':len(ids), + 'variables':len(variables),'signed_saving_interval':list(map(str,actual)), + 'directed_whole_upper':str(upper), + 'changed_contacts':[[v,verts[v][2],f] for v,f in labels.items() if f!=verts[v][0]]}) + if upper>=0: + break + except TimeoutError: + break + unresolved=[[a,b] for _,a,b in sorted(ranked,key=lambda x:(-x[0],x[1],x[2])) if [a,b] not in [x['pair'] for x in exact]] + return {'status':'PASS_COUPLED_BIT_CHART_SCREEN','pins':PINS,'vertices':len(verts),'edges':len(edges), + 'scoped_pairs':len(scope),'pruned_edgewise':len(scope)-len(ranked),'edgewise':results, + 'signed_original_net':list(map(str,base)),'exact_cuts':exact,'unresolved':unresolved, + 'physical_sites':0} + + +if __name__=='__main__': + cli=ArgumentParser() + cli.add_argument('--retry',action='store_true') + cli.add_argument('--remaining',action='store_true') + print(json.dumps(run(**vars(cli.parse_args())),indent=2,sort_keys=True)) diff --git a/research/bit-fixed-bank-split-bound/replay_package.py b/research/bit-fixed-bank-split-bound/replay_package.py new file mode 100644 index 0000000000..af71af14cf --- /dev/null +++ b/research/bit-fixed-bank-split-bound/replay_package.py @@ -0,0 +1,70 @@ +"""Replay the retained BIT support census from clean pinned inputs.""" +from argparse import ArgumentParser +from hashlib import sha1, sha256 +import gzip +import json +from pathlib import Path +import runpy +import shutil +import subprocess +import sys +from tempfile import TemporaryDirectory + +HERE = Path(__file__).resolve().parent +BIT = 'research/paired-query-only-bit/' + + +def unique(raw): + def keyed(pairs): + value = dict(pairs) + assert len(value) == len(pairs), 'Duplicate JSON key' + return value + return json.loads(raw, object_pairs_hook=keyed) + + +def materialize(folder, target): + for path in folder.rglob('*'): + if path.is_file(): + out = target / path.relative_to(folder) + out.parent.mkdir(parents=True, exist_ok=True) + if path.suffix == '.gz': + raw = gzip.decompress(path.read_bytes()) + unique(raw) + out.with_suffix('').write_bytes(raw) + else: + if path.suffix == '.json': + unique(path.read_bytes()) + shutil.copyfile(path, out) + + +def replay(root): + manifest = unique((HERE/'SOURCES.json').read_bytes())['files'] + pins = {p['path']:p for p in manifest} + assert len(pins) == len(manifest), 'Duplicate source path' + with TemporaryDirectory(prefix='bit-bank-replay-') as scratch: + temp = Path(scratch) + deps, adapter, output = [temp/p for p in ('deps','adapter','output')] + materialize(HERE/'deps', deps) + materialize(HERE/'adapter', adapter) + (deps/'inputs').mkdir() + for src,dst in (('retained/inputs/BIT-NATIVE-WORD.json.gz','WORD.json.gz'), + ('EFREE-RESULT.json','INVOICE.json')): + path = BIT + src + raw = (root/path).read_bytes() + assert sha256(raw).hexdigest() == pins[path]['sha256'] + assert sha1(f'blob {len(raw)}\0'.encode()+raw).hexdigest() == pins[path]['git_blob'] + unique(gzip.decompress(raw) if dst.endswith('.gz') else raw) + (deps/'inputs'/dst).write_bytes(raw) + subprocess.run([sys.executable,'-I','-B',str(HERE/'run.py'),str(deps),str(output), + '--adapter-root',str(adapter),'--seconds','120'], check=True, capture_output=True) + assert unique((output/'PRICE.json').read_bytes()) == unique((HERE/'PRICE.json').read_bytes()) + result = runpy.run_path(str(HERE/'verify.py'))['verify'](deps,adapter,output) + assert result == unique((HERE/'RESULT.json').read_bytes()) + return result + + +if __name__=='__main__': + assert __debug__ + parser=ArgumentParser(description=__doc__) + parser.add_argument('--root',type=Path,default=Path.cwd()) + print(json.dumps(replay(parser.parse_args().root),sort_keys=True,indent=2)) diff --git a/research/bit-fixed-bank-split-bound/run.py b/research/bit-fixed-bank-split-bound/run.py new file mode 100644 index 0000000000..a4201e53be --- /dev/null +++ b/research/bit-fixed-bank-split-bound/run.py @@ -0,0 +1,52 @@ +"""Run the checkpointed BIT experiment under a subprocess watchdog.""" +import argparse +import json +from pathlib import Path +import subprocess +import sys +from time import monotonic + +ROOT = Path(__file__).resolve().parent + + +def main(): + assert __debug__ + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('dependency_root', type=Path) + parser.add_argument('output_dir', type=Path) + parser.add_argument('--adapter-root', type=Path, required=True) + parser.add_argument('--seconds', type=int, default=120, choices=range(10, 121)) + args = parser.parse_args() + start = monotonic() + args.output_dir.mkdir() + # Reserve two seconds for terminating the worker and recording status. + soft_deadline = start + args.seconds - 2 + command = [ + sys.executable, '-I', '-B', str(ROOT/'worker.py'), + str(args.dependency_root.resolve()), str(args.adapter_root.resolve()), + str(args.output_dir.resolve()), str(soft_deadline-1), + ] + with (args.output_dir/'WORKER.stderr').open('wb') as err, (args.output_dir/'WORKER.stdout').open('wb') as out: + try: + exit_code = subprocess.run( + command, stdout=out, stderr=err, timeout=max(0.01, soft_deadline-monotonic()), + ).returncode + except subprocess.TimeoutExpired: + exit_code = 124 + elapsed = monotonic()-start + result = { + 'elapsed_seconds': round(elapsed, 3), 'hard_cap_seconds': args.seconds, + 'worker_exit_code': exit_code, 'watchdog_triggered': exit_code == 124, + 'inventory_checkpoint': (args.output_dir/'INVENTORY.json').is_file(), + 'price_checkpoint': (args.output_dir/'PRICE.json').is_file(), + 'assignment_checkpoint': (args.output_dir/'SUPPORT.json').is_file(), + 'worker_summary': (args.output_dir/'DONE.json').is_file(), + } + assert elapsed < args.seconds, result + (args.output_dir/'WATCHDOG.json').write_text(json.dumps(result, sort_keys=True, indent=2)+'\n') + print(json.dumps(result, sort_keys=True)) + return exit_code + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/research/bit-fixed-bank-split-bound/verify.py b/research/bit-fixed-bank-split-bound/verify.py new file mode 100644 index 0000000000..40007378cf --- /dev/null +++ b/research/bit-fixed-bank-split-bound/verify.py @@ -0,0 +1,179 @@ +"""Reverse the support census and independently verify the complete paid invoice.""" +from argparse import ArgumentParser +from collections import Counter, defaultdict +from fractions import Fraction as F +from hashlib import sha256 +from itertools import combinations +import json +from pathlib import Path +import runpy +from signal import alarm + +HERE = Path(__file__).resolve().parent + + +def dependencies(matrix): + rows = [[x,1<>bit&1),None) + if q is None: + continue + rows[pivot],rows[q] = rows[q],rows[pivot] + x,y = rows[pivot] + for i in range(pivot+1,len(rows)): + if rows[i][0]>>bit&1: + rows[i][0] ^= x + rows[i][1] ^= y + pivot += 1 + return [m for x,m in rows[pivot:]] + + +def action(rows,mask): + y=0 + for i,x in enumerate(rows): + if mask>>i&1: + y^=x + return y + + +def support(rows,cols,exterior): + left = dependencies([x&exterior for x in rows]) + if not left: + return False + right = dependencies([x&exterior for x in cols]) + if not right: + return False + for a in left+[x^y for x,y in combinations(left,2)]: + c = action(rows,a) + first = any((a&b).bit_count()%2 for b in right) + second = any((c&action(cols,b)).bit_count()%2 for b in right) + if first and second: + return True + return False + + +def census(word, inv): + n=word['public'] + m=n+word['owned_fields'] + prog=word['program'] + identity = [1<=n + right[d]=0 + frame[d]=owner[d]=None + else: + assert op=='CLEAR' and owner[d] is frame[d] is None + frame[d],owner[d]=args[0],n+t + left[d]=erased[t] + right[d]=0 + assert left==identity and frame==word['start']+[None]*(m-n) + assert owner==list(range(n))+[None]*(m-n) + return totals,coverage,checked_last + + +def verify(deps,adapter,receipt): + own=runpy.run_path(str(HERE/'worker.py')) + old,word,_,inventory,price=own['authenticate'](deps,adapter) + support_path=adapter/'frozen/SUPPORT.json' + assert sha256(support_path.read_bytes()).hexdigest()=='f6be6685471957d4e2bece0b05fa3f433518972325400ed761af00b341f6131c' + verification=adapter/'verify.py' + assert sha256(verification.read_bytes()).hexdigest()=='baa4ee28218820e7f5cf3b4f056fc0a7db4a033b80cb62241b9f91aa4febea3c' + separate=runpy.run_path(str(verification)) + prior=separate['verify'](deps,adapter/'frozen') + assert prior['paid_lineage_edges']==62474 and prior['rejected_omitted_paid_move'] + totals,coverage,clock=census(word,inventory) + proof=json.loads((receipt/'PRICE.json').read_bytes()) + assert proof['status']=='COMPLETE' and proof['copies']==36 + assert proof['adapter_relative_pins']==own['ADAPTER'] and proof['dependency_relative_pins']==old['PINS'] + assert proof['stats']==dict(totals) and proof['last_tested_clock']==clock + assert len(coverage)==proof['covered_pivots']==434 + assert proof['pivot_event_counts']=={str(i):v for i,v in coverage.items()} + assert not proof['positive_pivots'] and not proof['positive_pivot_credits'] and not proof['unresolved_pivots'] + assert proof['whole_signed_baseline']==price['signed_baseline_interval'] + assert F(proof['whole_stock_saving_upper'])==0 + assert F(proof['whole_target_margin_upper'])==F(price['signed_baseline_interval'][1])<0 + assert str(old['TARGET'])==proof['target'] and not (receipt/'SUPPORT.json').exists() + assert support([1],[1],0) and not support([1],[1],1) + return {'status':'PASS_INDEPENDENT_REVERSE_BANK_STOCK','lineage_edges':prior['paid_lineage_edges'], + 'omitted_paid_move_rejected':True,'bank_census':dict(totals), + 'pivots':len(coverage),'target':proof['target'], + 'target_margin_upper':proof['whole_target_margin_upper'],'saving_upper':'0'} + + +if __name__=='__main__': + assert __debug__ + p=ArgumentParser(description=__doc__) + p.add_argument('deps',type=Path) + p.add_argument('adapter',type=Path) + p.add_argument('receipt',type=Path) + a=p.parse_args() + alarm(60) + print(json.dumps(verify(a.deps,a.adapter,a.receipt),indent=2,sort_keys=True)) + alarm(0) diff --git a/research/bit-fixed-bank-split-bound/worker.py b/research/bit-fixed-bank-split-bound/worker.py new file mode 100644 index 0000000000..642d6b0271 --- /dev/null +++ b/research/bit-fixed-bank-split-bound/worker.py @@ -0,0 +1,227 @@ +"""Census all existing-pivot helper-support banks on the retained BIT word.""" +from collections import Counter, defaultdict +from fractions import Fraction as F +from functools import cache +from hashlib import sha256 +from itertools import chain, combinations +import json +from pathlib import Path +import runpy +import sys +from time import monotonic + +ADAPTER = { + 'worker.py': '278e2d1012db8c171c78c526681e3b2764da8f4b681f027a8682268a6efed2ea', + 'frozen/PRICE.json': '6706bb6225d5e41fa74eef932d92802dd48b722a6a9a6e3ea0040edd76e299f4', + 'frozen/INVENTORY.json': '8b9723cb93ce95163cf1aec8a830ba7e06f1a4274e50f5110ce09b8d6aa95472', +} + + +def authenticate(deps, adapter): + raw = {} + for name,digest in ADAPTER.items(): + blob = (adapter/name).read_bytes() + assert sha256(blob).hexdigest() == digest, name + raw[name] = blob + old = runpy.run_path(str(adapter/'worker.py')) + word,invoice,_ = old['load'](deps) + return old,word,invoice,json.loads(raw['frozen/INVENTORY.json']),json.loads(raw['frozen/PRICE.json']) + + +def banks(word, slots, observe, reverse=False): + """Yield only affected chart banks, including prefix rows and suffix columns.""" + n = word['public'] + program = word['program'] + left = [1<=n + owner[d] = None + left[d]=right[d]=0 + chart(d,None) + for f in changed-{None}: + roles = bank[f] & slots.get(f,set()) + if roles: + roles = sorted(i for i in roles if owner[i]==i) + if roles: + observe(t,f,roles,sorted(bank[f]),left,right) + assert frame==word['final']+[None]*word['owned_fields'] + assert right==[1<=deadline: + raise TimeoutError + last[0]=t + counters['chart_banks']+=1 + groups = defaultdict(list) + for i in pivots: + g,l = info[i,f] + groups[g].append((i,l)) + coverage[i]+=1 + rows = [left[i] for i in bank] + cols = [right[i] for i in bank] + for group,members in groups.items(): + counters['group_contexts']+=1 + result = paired(rows,cols,all_public^group_masks[group],old['kernel'],old['fold']) + if result is None: + continue + counters['positive_group_contexts']+=1 + for i,l in members: + u = credit(rank_of[i],l)[1] + if i not in best or u>best[i][0]: + best[i]=(u,t,f,l,bank,result) + + complete = True + try: + banks(word,slots,check) + except TimeoutError: + complete=False + charges = {i:data[0] for i,data in best.items()} if complete else roles_prior + upper = copies*sum(charges.values(),F(0)) + receipt = {'status':'COMPLETE' if complete else 'TIME_CAP_UNRESOLVED', + 'adapter_relative_pins':ADAPTER,'dependency_relative_pins':old['PINS'], + 'whole_signed_baseline':list(map(str,base)),'whole_stock_saving_upper':str(upper), + 'whole_target_margin_upper':str(base[1]+upper),'target':str(target),'copies':copies, + 'covered_pivots':len(coverage),'positive_pivots':len(best),'stats':dict(counters), + 'pivot_event_counts':dict(coverage),'positive_pivot_credits':{i:str(x[0]) for i,x in best.items()}, + 'unresolved_pivots':[] if complete else sorted(roles_prior), + 'last_tested_clock':last[0]} + old['save'](out,'PRICE.json',receipt) + if complete and base[1]+upper>=0 and best: + i,(_,t,f,l,bank,result) = min(best.items(),key=lambda x:(-x[1][0],x[1][1],x[0])) + old['save'](out,'SUPPORT.json',{'pivot':i,'clock':t,'chart':f,'bank':bank, + 'rank_parts':[l,rank_of[i]-l], 'pairing_masks':list(map(hex,result))}) + old['save'](out,'DONE.json',{'status':receipt['status']}) + + +if __name__=='__main__': + assert __debug__ + main(Path(sys.argv[1]),Path(sys.argv[2]),Path(sys.argv[3]),float(sys.argv[4])) diff --git a/research/historical-selected-replay-gap/README.md b/research/historical-selected-replay-gap/README.md index 55d8cc3b49..36d9a873ca 100644 --- a/research/historical-selected-replay-gap/README.md +++ b/research/historical-selected-replay-gap/README.md @@ -69,7 +69,11 @@ python3 -B scripts/research_package.py --package research/historical-selected-re The direct command prints `PASS_HISTORICAL_SELECTED_REPLAY_GAP`. A registered replay prints `PASS_REGISTERED_RESEARCH_PACKAGE`. Both require Git history -containing the two inspected commits. +containing the two inspected commits and the source and manifest objects at +`2485805a6d47f36ea83ddde6327d453ac82d44dc`. The verifier uses a temporary +sparse checkout of that commit, checks the declared source digests there, and +uses its planner and manifest inventory. The recorded rejections and selection +therefore remain reproducible after later changes to the live Makefile or CI guide. ## Open next questions diff --git a/research/historical-selected-replay-gap/SOURCES.json b/research/historical-selected-replay-gap/SOURCES.json index c1010eec95..62bb8b3950 100644 --- a/research/historical-selected-replay-gap/SOURCES.json +++ b/research/historical-selected-replay-gap/SOURCES.json @@ -4,13 +4,13 @@ "files": [ { "path": "Makefile", - "usage": "input", + "usage": "provenance", "git_blob": "0d683a06b9e7ee162496108ce9a7c5d2ee94fccf", "sha256": "4f2d4f2dcd15139ec82658a975f85ed300897385f85799218539f4c8d60567da" }, { "path": "certificates/partial-swap-network.json", - "usage": "input", + "usage": "provenance", "git_blob": "eccafa830c16170c36faf93045ddf1f638f7bcd4", "sha256": "4c0b9d37e1034b2076e30a70f8e514416298c462d9ee98bc87fe6556b14df786" }, @@ -22,7 +22,7 @@ }, { "path": "docs/ci-verification.md", - "usage": "input", + "usage": "provenance", "git_blob": "63ba3e9aa8bdc5e942b56e34244b92b16f854085", "sha256": "c7d3027e9ad8bcbff68f07aa9576b30fb2f3c76c44d876d40c7fdbf4a3e2228a" }, @@ -34,163 +34,163 @@ }, { "path": "research/clifford-state-performance/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "6f98a0061a5104dfab82c9e806f819b41811f684", "sha256": "396d0f08df24952248140d5c65c51b8c902ef1c580892ff7ea182890530f67ee" }, { "path": "research/community-batch1047-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "5e0f92af463ec12c5e1dcc3effd44081a88af647", "sha256": "07a9daeaf2bda308a92e9a4684f13d5fc766c7772d74801fceb7f4599fdab226" }, { "path": "research/community-batch1099-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "9e13266bf85e627f1b7dc225e9530ea69fd2c7f0", "sha256": "421e1211fb1897c45621dc6801c276e53f2e6f335583c9c9049e535f87c0a3b1" }, { "path": "research/community-batch932-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "cc4d03eb59b9ab3f952735f7e88ff18c2d15d7af", "sha256": "184629cac91a5cfaca50330a88596008b824221433867dcf8117539c913c284a" }, { "path": "research/community-batch970-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "8b9f4111badf7de5d97684799560b55110e9da79", "sha256": "23188ed920e38a54006cb883e181585620821c63bf7e8b5e05d32719417cc37e" }, { "path": "research/community-frontier741-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "a5300d4e7a5381a3f443fc54c768ca6f0f236d68", "sha256": "3c820fb30e1b4d9bcfc6a7ab524375e5b2abd66b940af2c509146104f0bcd79c" }, { "path": "research/community-frontier890-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "d7ff6d777b01d69b6ce84caf25d3b7e4a4d2f211", "sha256": "6b185a9902652f893f3ebd8ada92d2f11b6de6533a9a4d11718a8a4496101128" }, { "path": "research/community-hyperplane599-audit/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "546f37d326d10a99910ae8f908e71ef768524d98", "sha256": "65099d764bfcc39bda5e4d9966783611b094c3522dbdd1435cd498d657a8ef8e" }, { "path": "research/community-k492-audit/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "e538481e4cb16ed936d3195f2dfb5b5a9ca0a76b", "sha256": "2c0f4fa5bc150d05658af2e7c54c4d2c337dd52b7efd3d69530ae73bcbdf452a" }, { "path": "research/community-reconciliation92-audit/MANIFEST.json", - "usage": "input", + "usage": "provenance", "git_blob": "2a2e93685173d5f13cbb5abe740f5d90352e0228", "sha256": "5f501f3c118131e7d069f30ad77186eb2ad6961f9680a0ef105f4514ed41808a" }, { "path": "research/partial-swap-digest/baseline.py", - "usage": "input", + "usage": "provenance", "git_blob": "a2f0190704db83bd8ef48e46e723c49b925804fe", "sha256": "81e9af92cdf38243a540cdcff2062778e449467848d444da37a9553c12ca4c34" }, { "path": "research/r420-two-sided-basis/SOURCES.json", - "usage": "input", + "usage": "provenance", "git_blob": "5d718e11e62f4bcadecf1e02d6b61f87dbe190b0", "sha256": "d9810b0d139c5a1211fd2c1f0d142187cc1fca30026e1e7bc4f9ecfacf1596d1" }, { "path": "research/skip-clones/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "8d1bb3b9c8189e35e5d8bfdfa632d7473e8be0d5", "sha256": "0b68e63e35a97ce6b0cdb6e291b88ebaa8f2dd4afb70b2498f10ee89428258dc" }, { "path": "research/split-skip/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "2ab610b6ea2edd2865fda793ef2168b0c76afb4f", "sha256": "7c2b4646a3ecfef6f881da5c43e4bd0fa9a4d1b00548b8ab458d897e16735134" }, { "path": "scripts/historical-ci-inputs/Makefile", - "usage": "input", + "usage": "provenance", "git_blob": "aff68409021c9d401a6f8013b9dfd7dbcc30f2a8", "sha256": "ea8830dd79da493e2d75baf753d733ff7efbcf2b4794afe41fae0ac8f3055646" }, { "path": "scripts/historical-ci-inputs/ledger-batch932-run_isolated_tests.py", - "usage": "input", + "usage": "provenance", "git_blob": "65db599ab0b1dea0312c4ca048e0bd0f44c3736f", "sha256": "96ea543e6c707424afe247e77bd86c82152f90fc76a0773c4232145da5cdf8d1" }, { "path": "scripts/historical-ci-inputs/ledger-batch932-test_isolated_test_runner.py", - "usage": "input", + "usage": "provenance", "git_blob": "34820a8f24678f918f4d0e7a35380d8013fc3495", "sha256": "628391b6abfbc8674ceec1751867a4392f2cc0b5b66886243e139af86cf355ac" }, { "path": "scripts/historical-ci-inputs/ledger-batch970-verify_selected_result.py", - "usage": "input", + "usage": "provenance", "git_blob": "c755b76e0d44ba4917aa94440ebe54daefce5b2a", "sha256": "d7fd929726b326aeeaf0a3996475adec88eee9aac09ae0bebeeaa0bc1fc8f199" }, { "path": "scripts/historical-ci-inputs/ledger-frontier741-ci-verification.md", - "usage": "input", + "usage": "provenance", "git_blob": "7f3c012504187917a728b9fe87043f0fc8cd006a", "sha256": "a854022e0e1d5d4db4d60e586be3ea56005013ef14a1fc06d02bc06e8529c4b0" }, { "path": "scripts/historical-ci-inputs/partial-swap-context.json", - "usage": "input", + "usage": "provenance", "git_blob": "ad65114886bf34a4fd27e79f3be502389e689faa", "sha256": "833a9642f33aeab2ffea17ec9c6b82e0a953f90192b2c82e10bef21538dccba9" }, { "path": "scripts/historical-ci-inputs/partial-swap-network.json", - "usage": "input", + "usage": "provenance", "git_blob": "52075f2463f60af5e16571347f24274fce73a1ea", "sha256": "f3c4be597b2f2136da4ae2cc80c7454f63c90aa01f84e5b8131cee4dd55de815" }, { "path": "scripts/partial_swap/shared.py", - "usage": "input", + "usage": "provenance", "git_blob": "44a0e454c70f9c4b98e258b8443612e6a119904b", "sha256": "5a0646a50b9f3e8ea55168620a78e8853b0ab810517cefc8cfb8696aedee278a" }, { "path": "scripts/replay_historical_check.py", - "usage": "input", + "usage": "provenance", "git_blob": "1e92fff2782970ef71378f594f2350d245a4db26", "sha256": "5467619c78183d3adc82b0cb55af28e5c1a01fca2b0588677816244b53e2bafd" }, { "path": "scripts/research_package.py", - "usage": "input", + "usage": "provenance", "git_blob": "091b4c8f58bac9a9580d76025b887dc5c873d05f", "sha256": "e1256016e7f51827d04fa2179255989f639ae1d97afaa9c16265f85a0c6abd70" }, { "path": "scripts/run_isolated_tests.py", - "usage": "input", + "usage": "provenance", "git_blob": "a96ab35b315ce492e7fbbfd6c5ae211aa066b541", "sha256": "49eb56dd0fc0d8d8ffdb209970a7adf2176223580646f575d5c22e59543b381c" }, { "path": "scripts/verify_selected_result.py", - "usage": "input", + "usage": "provenance", "git_blob": "6882a4700e410dec569b51ae2eaf1a19cc019195", "sha256": "d6b305eac5b9bdb8172c469ad30a1655a60fa0aceac8b1bf610e1b73f51babd8" }, { "path": "tests/test_isolated_test_runner.py", - "usage": "input", + "usage": "provenance", "git_blob": "343b24abf6719b81805eba5a84c74e57634c8288", "sha256": "3a5470d0b139828b90e19bf9583ddeafcd69f8e34f2824664eb3a2958a52e34d" } diff --git a/research/historical-selected-replay-gap/VERIFY.json b/research/historical-selected-replay-gap/VERIFY.json index 98553e72ed..ab7efa3471 100644 --- a/research/historical-selected-replay-gap/VERIFY.json +++ b/research/historical-selected-replay-gap/VERIFY.json @@ -4,36 +4,7 @@ "python": "3.12", "requirements": [], "inputs": [ - "Makefile", - "certificates/partial-swap-network.json", - "docs/ci-verification.md", - "research/clifford-state-performance/SOURCE.json", - "research/community-batch1047-audit/CONTENT-COVERAGE.json", - "research/community-batch1099-audit/CONTENT-COVERAGE.json", - "research/community-batch932-audit/CONTENT-COVERAGE.json", - "research/community-batch970-audit/CONTENT-COVERAGE.json", - "research/community-frontier741-audit/CONTENT-COVERAGE.json", - "research/community-frontier890-audit/CONTENT-COVERAGE.json", - "research/community-hyperplane599-audit/SOURCE.json", - "research/community-k492-audit/SOURCE.json", - "research/community-reconciliation92-audit/MANIFEST.json", - "research/partial-swap-digest/baseline.py", - "research/r420-two-sided-basis/SOURCES.json", - "research/skip-clones/SOURCE.json", - "research/split-skip/SOURCE.json", - "scripts/historical-ci-inputs/Makefile", - "scripts/historical-ci-inputs/ledger-batch932-run_isolated_tests.py", - "scripts/historical-ci-inputs/ledger-batch932-test_isolated_test_runner.py", - "scripts/historical-ci-inputs/ledger-batch970-verify_selected_result.py", - "scripts/historical-ci-inputs/ledger-frontier741-ci-verification.md", - "scripts/historical-ci-inputs/partial-swap-context.json", - "scripts/historical-ci-inputs/partial-swap-network.json", - "scripts/partial_swap/shared.py", - "scripts/replay_historical_check.py", - "scripts/research_package.py", - "scripts/run_isolated_tests.py", - "scripts/verify_selected_result.py", - "tests/test_isolated_test_runner.py" + "scripts/research_package.py" ], "commands": [ { diff --git a/research/historical-selected-replay-gap/verify.py b/research/historical-selected-replay-gap/verify.py index 83b995941a..9d266c5a4e 100644 --- a/research/historical-selected-replay-gap/verify.py +++ b/research/historical-selected-replay-gap/verify.py @@ -6,8 +6,10 @@ """ import hashlib import importlib.util +import json import subprocess import sys +import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parents[2] @@ -61,31 +63,47 @@ def require(ok, message): raise SystemExit(message) -def load_checker(): - path = ROOT / "scripts/replay_historical_check.py" - spec = importlib.util.spec_from_file_location("historical_selected_replay_gap_checker", path) +def load_module(path): + spec = importlib.util.spec_from_file_location(path.stem, path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module +def checkout_snapshot(snapshot, sources, runner, env): + paths = [runner.canonical_relative_path(row["path"]) for row in sources["files"]] + git = ["git", "-c", "maintenance.auto=false", "-c", "gc.auto=0", + "-c", "core.autocrlf=false"] + subprocess.run([*git, "clone", "--quiet", "--shared", "--no-tags", "--no-checkout", + "--", str(ROOT), str(snapshot)], cwd=ROOT, env=env, check=True) + subprocess.run([*git, "update-ref", "--no-deref", "HEAD", INSPECTED], + cwd=snapshot, env=env, check=True) + # The pinned planner reads omitted manifests from the sparse HEAD/index. + patterns = "".join(f"/{path.as_posix()}\n" for path in paths) + subprocess.run([*git, "sparse-checkout", "set", "--no-cone", "--stdin"], + cwd=snapshot, env=env, input=patterns.encode("utf-8"), check=True) + subprocess.run([*git, "read-tree", "-mu", "HEAD"], cwd=snapshot, env=env, check=True) + for path, row in zip(paths, sources["files"], strict=True): + require(hashlib.sha256((snapshot / path).read_bytes()).hexdigest() == row["sha256"], + "historical checkout source digest changed: " + path.as_posix()) + + def entries(checker): for name, config in checker.CONFIG.items(): for entry in [config, *config.get("additional_inputs", [])]: yield name, entry -def reject(checker, entry): +def reject(root, checker, entry): try: - checker.authenticated_input(ROOT, entry) + checker.authenticated_input(root, entry) except ValueError as exc: return str(exc) raise SystemExit("historical input was admitted: " + entry["path"]) -def main(): - require(not sys.flags.optimize, "assertions must stay enabled") - checker = load_checker() +def check_snapshot(root, env): + checker = load_module(root / "scripts/replay_historical_check.py") selected = [entry for name, entry in entries(checker) if name == "tooling-ledger" and entry["path"] == SELECTED_PATH] require(len(selected) == 1, "selected-result checker overlay is not unique") @@ -94,7 +112,7 @@ def main(): require(entry["accepted_live_sha256"] == [SELECTED_ACCEPTED], "accepted selected-checker successors changed") frozen = (checker.INPUTS / entry["input"]).read_bytes() - live = (ROOT / SELECTED_PATH).read_bytes() + live = (root / SELECTED_PATH).read_bytes() require(hashlib.sha256(frozen).hexdigest() == SELECTED_PIN, "frozen selected checker bytes changed") require(hashlib.sha256(live).hexdigest() == SELECTED_LIVE, "live selected checker digest changed") require(SELECTED_LIVE not in (SELECTED_PIN, SELECTED_ACCEPTED), "live checker was already admitted") @@ -102,7 +120,7 @@ def main(): # live successor, not a broken comparison. require(SELECTED_PIN in (SELECTED_PIN, *entry["accepted_live_sha256"]), "pin membership control failed") - require(reject(checker, entry) == REJECTIONS[SELECTED_PATH][1], + require(reject(root, checker, entry) == REJECTIONS[SELECTED_PATH][1], "selected checker rejection text changed") counts = {path: 0 for path in REJECTIONS} @@ -110,7 +128,7 @@ def main(): for _name, item in entries(checker): if item["path"] not in REJECTIONS: continue - message = reject(checker, item) + message = reject(root, checker, item) counts[item["path"]] += 1 messages.setdefault(item["path"], message) for path, (count, message) in REJECTIONS.items(): @@ -118,20 +136,31 @@ def main(): require(messages[path] == message, "rejection text changed for " + path) require(sum(counts.values()) == 19, "rejection total changed") ci = [item for _name, item in entries(checker) if item["path"] == CI_PATH] - require(len(ci) == 1 and hashlib.sha256((ROOT / CI_PATH).read_bytes()).hexdigest() == CI_LIVE, + require(len(ci) == 1 and hashlib.sha256((root / CI_PATH).read_bytes()).hexdigest() == CI_LIVE, "selected CI note digest changed") diff = subprocess.check_output( - ["git", "diff", "--name-only", PARENT, INSPECTED], cwd=ROOT, text=True) + ["git", "diff", "--name-only", PARENT, INSPECTED], cwd=root, env=env, text=True) changed = sorted(name for name in diff.splitlines() if name) require(changed == CHANGED, "inspected commit diff changed") - sys.path.insert(0, str(ROOT / "scripts")) - from research_package import plan_details - details = plan_details(ROOT, set(changed)) + planner = load_module(root / "scripts/research_package.py") + details = planner.plan_details(root, set(changed)) require([row["package"] for row in details] == PLAN_PACKAGES, "helper plan selection changed") matched = {name for row in details for names in row["causes"].values() for name in names} require(sorted(set(changed) - matched) == UNMATCHED, "unmatched plan paths changed") - require(plan_details(ROOT, set()) == [], "empty change set selected a package") + require(planner.plan_details(root, set()) == [], "empty change set selected a package") + + +def main(): + require(not sys.flags.optimize, "assertions must stay enabled") + sources = json.loads(Path(__file__).with_name("SOURCES.json").read_bytes()) + require(sources["base_commit"] == INSPECTED, "historical checkout base changed") + runner = load_module(ROOT / "scripts/research_package.py") + env = runner.git_source_env() + with tempfile.TemporaryDirectory(prefix="historical-selected-replay-") as temporary: + snapshot = Path(temporary) / "snapshot" + checkout_snapshot(snapshot, sources, runner, env) + check_snapshot(snapshot, env) print("PASS_HISTORICAL_SELECTED_REPLAY_GAP") print("selected_checker_live=" + SELECTED_LIVE) print("rejections=19 distinct_paths=7 plan_packages=9")