Repository navigation
perf(research): reuse exact inverses in the downset block-solve replay (3.4x, identical finite evidence) - #4947
Merged
Mister-Meeseeks merged 3 commits intoOct 23, 2026
Conversation
Controls that a returned inverse is a private copy, that inverses are keyed by the exact input matrix, and that a singular matrix of a seen shape still rejects. They pass on the unmodified elimination and guard the memoization that follows. Printed finite_evidence is unchanged.
The replay calls the exact Fraction Gauss-Jordan inverse 33,409 times on only 808 distinct matrices (about 88% of the runtime under cProfile). Memoize the residual-checked inverse by its exact input and return a fresh copy. Each distinct matrix is still eliminated and residual-checked once; printed finite_evidence and the status token are unchanged under both registered commands. Local best-of-3: 23.44s -> 6.95s (-W error), 24.16s -> 6.71s (-O).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Result
The registered replay of
research/downset-block-solve-boundruns about 3.4x faster with identical printed evidence. One change in that package's ownverify.py:invreuses the residual-checked exact inverse of an identical input matrix and returns a fresh copy.python3.12 -I -W error -B verify.pypython3.12 -I -O -W error -B verify.pyscripts/research_package.py --package …(both commands)Timing method: wall time from
time.perf_counter()around asubprocess.runof the exact registered argv, on the same fixture and the same machine (Apple Silicon, macOS, CPython 3.12). Other agents were running CPU work on the machine at the same time, so treat the absolute numbers as approximate. The ratio held in every run.Bottleneck. cProfile of the unmodified verifier:
invtakes 52.8 s of 59.8 s profiled (88%), through 33,409 calls. Instrumentation shows only 808 distinct input matrices (leading sectionst[:k,:k]and the same factors recur for every downset). After the change, the remaining time is mostlymul. A trial that also memoizedmulsaved about another 15%. I left that out because it doesn't pay for the extra code.Equivalence evidence
status(PASS_DOWNSET_BLOCK_SOLVE),claim_type,no_new_kappaand the identicalfinite_evidenceobject. I diffed the JSON key by key against the pre-change output. The counts are 10 fixtures, 46 trees, 2,380 states, 9,520 matrix identities, 9,372 partition blocks, the spectral-certificate count, 11 controls, and 2,244 / 2,160 / 1,940 wrong-order / missing-endpoint / wrong-sign witnesses. The only differing fields aresource_sha256["verify.py"]andsource_sha256["README.md"], which hash the edited files. The package has no frozen receipt file.A·A⁻¹ = A⁻¹·A = I) once. A singular input raises before anything is stored. The witness counts above prove that all identity and spectral checks still run on every state. They also show the three distinguishing controls (wrong order, omitted endpoint, inverse sign) still fire the same number of times.inverse_reuse_controls()requires three things. A caller's mutation of a returned inverse must not affect a later call. A different matrix of the same shape must get its own inverse. A singular matrix of a seen shape must still reject. It passed on the unmodified code too, with identical counts. Scratch mutation run against the new code:inverse is keyed by the exact input)returned inverse is a private copy)ZeroDivisionError)controls(): singular inverse, invalid partitions, PSD/spectral and leading-premise controls) are unchanged and still pass.Task and overlap
Card
replay-runtime(track verifier-engineering): "Can one measured replay bottleneck be sped up without dropping coverage?" Basecef4b52f2a59009865bf8eabde1be3f159063703.Selection: I ranked registered packages by their longest recent
research-packages.ymlCI job, then timed the top candidates locally.downset-block-solve-bound(≈47 s locally, 197 s in CI) had a single dominant, self-contained bottleneck in a package-local verifier. That verifier has no frozen receipt and is not pinned by any otherSOURCES.json/VERIFY.json.python3 scripts/find_overlap.py --task replay-runtimeandfind_overlap.py 'downset-block-solve-bound'found no open PR touching this package. The precedent work is #4090 (P112 census popcnt) and #4547 (portable-replay repair), which touch other packages.Claim: #1166 (comment)
Test plan
python3.12 -I -W error -B research/downset-block-solve-bound/verify.py: PASS,finite_evidenceidentical to the basepython3.12 -I -O -W error -B research/downset-block-solve-bound/verify.py: PASS, identicalpython3 scripts/research_package.py --package research/downset-block-solve-bound --check-only:PASS_PACKAGE_METADATA_AND_PINSpython3.12 -B scripts/research_package.py --package research/downset-block-solve-bound:PASS_REGISTERED_RESEARCH_PACKAGE … outcome=completed(14.9 s)python3.12 -B scripts/check_research_commit.py --package research/downset-block-solve-bound --check-source-history:PASS_RESEARCH_COMMIT_BYTESpython3.12 -W error -B -m unittest discover -s tests -p 'test_research_onboarding.py': 26 tests OKNot run: the complete frontier replay, Lean and Docker (not affected). No other package or shared script was changed.
Commits
test(...): add the exact-input inverse reuse controls (pass on the unmodified code)perf(...): memoize the residual-checked inversedocs(...): README note on reuse, controls, timings and creditOpen next questions
mulbe made cheaper without memoizing it? It is now most of the remaining ~7 s. Why it matters: this would give another ~15–30%. First step: fraction-free integer products over a common denominator per fixture. Blocked by: nothing, but the gain is small relative to CI setup.invpattern (e.g.matrix-algebra-three-factortakes about 37 s locally). Why it matters: the same exact-input reuse could apply wherever the distinct-to-total call ratio is small. First step: instrument distinct vs total inputs before changing anything. Blocked by: per-package frozen receipts that hash their verifier.Credit
The mathematics, fixtures and all checks are Nick Petalas's (
research/downset-block-solve-bound). This PR changes only replay runtime and adds reuse controls. Precedent: kumagi's #4090 (popcnt census speedup) and pinterbanget's #4547 (portable-replay repair). Prepared by Brian (JoyboyBrian) with substantial Claude Code assistance. Apache-2.0.🤖 Generated with Claude Code