Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion certificates/partial-swap-network.json
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@
"scripts/partial_swap/match_positive_dag.cpp": "8a6d64e2d0ac2c69210fb0b8a5bd0d714ad40b3609f75a5fddfcba3291a3d552",
"scripts/partial_swap/paired.py": "ddcecace3a8e04d690914cbd64873ab8dde8c0c3477a255767b0ed6f639bb0c7",
"scripts/partial_swap/positive.py": "1dadf771226d6e4f3bf9ce3aae2e6a2ad7173f4d1c900299d0663fc4c432f3e8",
"scripts/partial_swap/shared.py": "81e9af92cdf38243a540cdcff2062778e449467848d444da37a9553c12ca4c34",
"scripts/partial_swap/shared.py": "7290bd639600aecff11941d3faf95c9ce95589125cc6a7f7440fb86af7a0f17c",
"scripts/partial_swap_network.py": "acdd81b4dea2815f8838a0c3ea8ac4968f2bc13fd7c99173473d865779096782",
"scripts/partial_swap_producer.py": "dba07d742c68e8e4aedd1d93fc4c47a0481778268f7480997463e2b269fdd0a0"
},
Expand Down
22 changes: 22 additions & 0 deletions research/partial-swap-digest/NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Notice

This package accelerates the historical partial-swap shared-point verify digest
in `scripts/partial_swap/shared.py:SharedPointCircuit.verify` while preserving
support checks and `circuit_sha256`.

Predecessor credit:

- Douglas R. Colkitt — shared-point / exclusion circuits and the historical
common-point motif.
- icekylinx — partial-swap producer adaptation of the shared-point circuit
(`scripts/partial_swap/shared.py`, Apache-2.0).
- Closest tooling priors on *different* objects: CrocSwap/integer-mult-bounds
PRs #756 (balanced-Fano packed replay), #1793 (inplace-side prefix), #1861
(parity-side basis/contains), #1922 (joint-frame cleared product), #1984
(mixed-point scalar digests), and #1994 (canonical
`scripts/shared_point_circuit.py` verify digests; this package applies the
same byte-identical formatter to the partial-swap fork).

Prepared by Wentao Li with substantial AI assistance under Apache-2.0.
This is not independent human peer review and is not a formal proof of the
multiplication theorem.
106 changes: 106 additions & 0 deletions research/partial-swap-digest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Faster exact partial-swap verify digests with identical receipts

**Tooling improvement; no new kappa.** At base
`0b1cccf86e2f5132ed286a26ef0a681a495740ea`, the partial-swap fork of
`SharedPointCircuit.verify` (`scripts/partial_swap/shared.py`) builds
`circuit_sha256` with per-active-node and per-partial-output
`json.dumps(..., separators=(',',':'))` updates. Profiling on the historical
full-size circuit (`h=46`, 501510 active nodes, 45540 partial outputs) shows
about half of verify wall time in that JSON encoder path. Open
[CrocSwap/integer-mult-bounds#1994](https://github.com/CrocSwap/integer-mult-bounds/pull/1994)
applied the same byte-identical formatter to the canonical
`scripts/shared_point_circuit.py`; this package applies it to the distinct
partial-swap producer copy, which still used `json.dumps`.

This change writes the same UTF-8 digest lines with an equivalent hand-rolled
formatter (`[node,null,null]`, `[node,[a,b],[common,local]]`,
`[common,[t0,t1,t2],node]`), keeps every support and topology assertion, and
leaves `circuit_sha256` unchanged. `certificates/partial-swap-network.json`
updates only the `scripts/partial_swap/shared.py` `source_sha256` pin.

## Reproduce

Python **3.12**, standard library only, from the repository root:

```sh
python3.12 -I -B research/partial-swap-digest/verify.py
python3.12 -I -O -B research/partial-swap-digest/verify.py
python3.12 -B scripts/research_package.py --package research/partial-swap-digest
python3.12 -I -B research/partial-swap-digest/benchmark.py --rounds 5
```

Expected:

```text
PASS_PARTIAL_SWAP_DIGEST verify_cases=5 encoding_cases=8 certs=1 no_new_kappa
PASS_REGISTERED_RESEARCH_PACKAGE research/partial-swap-digest outcome=completed
PASS_IDENTICAL_PARTIAL_SWAP_DIGEST_RECEIPTS
```

Default verify is read-only aside from the already-committed pin-only certificate
refresh. Full `make verify`, selected cold replay, Lean, and
multiplication-theorem obligations were not rerun for this isolated
historical-checker change.

## Result

On Linux / CPython 3.12.3 (Linux-6.12.94+-x86_64-with-glibc2.39), five
alternating fresh-process pairs timing only
`partial_swap.shared.SharedPointCircuit(46).verify` (construction excluded;
inlined local support checks included) gave median wall time
**2.176 → 1.050 seconds (2.07×)**. Timing is host-descriptive and is not a
correctness gate; all samples and environment pins are in
[RESULT.json](RESULT.json). Every verify receipt matches the baseline checker
fieldwise (`roles`, `additions`, `merged_additions`, `circuit_sha256`, flags).

## Equivalence

For each active node the historical encoder emitted

- `json.dumps((node, None, None), separators=(',',':'))+'\n'` → `[node,null,null]\n`
- `json.dumps((node, (a,b), (common,local)), separators=(',',':'))+'\n'` → `[node,[a,b],[common,local]]\n`

and for each partial output

- `json.dumps((common, (t0,t1,t2), node), separators=(',',':'))+'\n'` → `[common,[t0,t1,t2],node]\n`

with default JSON integer formatting (no whitespace). The hand-rolled writer
emits those exact byte strings. A `None` vs `null` spelling mutant and a flat
`[node,a,b,common,local]` mutant differ and are rejected by the package
controls. Support and topology checks remain the historical `assert` gates.

## Open next questions

1. **Question:** Should research packages that pin live
`scripts/partial_swap/shared.py` bytes refresh that one SHA-256 entry after
this equivalence-preserving digest rewrite?
**Why it matters:** Those provenance packages bind working-tree bytes;
leaving old pins keeps this tooling PR focused.
**First step:** Dedicated provenance follow-up that only rewrites that one
`SOURCES.json` entry after confirming `circuit_sha256` identity.
**Blocked by:** Pin repair outside `certificates/partial-swap-network.json`
is outside this tooling change.

2. **Answered in-tree:** `partial_swap.shared.SharedPointCircuit.__init__` merge/lookup rewrite lands in the same production file as `research/partial-swap-init/` (identical DAG/`circuit_sha256`; one re-pin).

## Overlap and credit

Closest priors (different objects):
[CrocSwap/integer-mult-bounds#756](https://github.com/CrocSwap/integer-mult-bounds/pull/756),
[CrocSwap/integer-mult-bounds#1793](https://github.com/CrocSwap/integer-mult-bounds/pull/1793),
[CrocSwap/integer-mult-bounds#1861](https://github.com/CrocSwap/integer-mult-bounds/pull/1861),
[CrocSwap/integer-mult-bounds#1922](https://github.com/CrocSwap/integer-mult-bounds/pull/1922),
[CrocSwap/integer-mult-bounds#1984](https://github.com/CrocSwap/integer-mult-bounds/pull/1984),
[CrocSwap/integer-mult-bounds#1994](https://github.com/CrocSwap/integer-mult-bounds/pull/1994)
(canonical `shared_point_circuit.py` verify digests; this package applies the
same formatter to the partial-swap fork),
[CrocSwap/integer-mult-bounds#1874](https://github.com/CrocSwap/integer-mult-bounds/pull/1874).
No competing open PR on the `partial_swap.shared` verify digest object at
refresh. #2001's ExclusionCircuit / DisjointTensor support-mask files are not
touched.

Douglas R. Colkitt authored the shared-point / exclusion circuits. icekylinx
adapted the partial-swap producer copy. Prepared by Wentao Li
([VictorLiwentao](https://github.com/VictorLiwentao),
[@Is__Victor](https://x.com/Is__Victor)) with substantial AI assistance, under
Apache-2.0.
50 changes: 50 additions & 0 deletions research/partial-swap-digest/RESULT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"environment": {
"executable": "/usr/bin/python3.12",
"platform": "Linux-6.12.94+-x86_64-with-glibc2.39",
"python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]"
},
"fixture": "partial_swap.shared.SharedPointCircuit(46).verify only (construction excluded); includes inlined local support checks",
"median_baseline_seconds": 2.176399500000116,
"median_optimized_seconds": 1.0500758960001804,
"median_ratio": 2.0726116162557284,
"no_new_kappa": true,
"rounds": 5,
"samples": [
{
"baseline_seconds": 2.1735980080002264,
"optimized_seconds": 1.0412321750000046,
"ratio": 2.0875248193326494,
"round": 0
},
{
"baseline_seconds": 2.176399500000116,
"optimized_seconds": 1.0671551489999729,
"ratio": 2.0394405649821508,
"round": 1
},
{
"baseline_seconds": 2.1539880980003545,
"optimized_seconds": 1.0212636050000583,
"ratio": 2.109140174441281,
"round": 2
},
{
"baseline_seconds": 2.3100297329997375,
"optimized_seconds": 1.0500758960001804,
"ratio": 2.1998693063985355,
"round": 3
},
{
"baseline_seconds": 2.2508478529998683,
"optimized_seconds": 1.0912254210002175,
"ratio": 2.0626790850755112,
"round": 4
}
],
"source_sha256": {
"baseline": "81e9af92cdf38243a540cdcff2062778e449467848d444da37a9553c12ca4c34",
"production": "7290bd639600aecff11941d3faf95c9ce95589125cc6a7f7440fb86af7a0f17c"
},
"status": "PASS_IDENTICAL_PARTIAL_SWAP_DIGEST_RECEIPTS"
}
60 changes: 60 additions & 0 deletions research/partial-swap-digest/SOURCES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"schema_version": 1,
"base_commit": "0b1cccf86e2f5132ed286a26ef0a681a495740ea",
"files": [
{
"path": "docs/research/agent-task-catalog.json",
"usage": "provenance",
"git_blob": "06c96f5579bb67ed1b86d334e78fbed7da6945f1",
"sha256": "6686ad58f1fbdbc87134a78901b60fd53a20d3984355e91defbbebc9e9fa8075"
},
{
"path": "certificates/selected-result.json",
"usage": "provenance",
"git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11",
"sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32"
},
{
"path": "certificates/partial-swap-network.json",
"usage": "provenance",
"git_blob": "52075f2463f60af5e16571347f24274fce73a1ea",
"sha256": "f3c4be597b2f2136da4ae2cc80c7454f63c90aa01f84e5b8131cee4dd55de815"
},
{
"path": "scripts/partial_swap/shared.py",
"usage": "provenance",
"git_blob": "a2f0190704db83bd8ef48e46e723c49b925804fe",
"sha256": "81e9af92cdf38243a540cdcff2062778e449467848d444da37a9553c12ca4c34"
},
{
"path": "scripts/exclusion_circuit.py",
"usage": "provenance",
"git_blob": "aaa99986c4b81c5d4fbe016fd216a4818940bb95",
"sha256": "b253f9d7318becda1c1f3b24e2287ed44a9c27fcea00cf9d531afb950d0457a0"
},
{
"path": "scripts/partial_swap_network.py",
"usage": "provenance",
"git_blob": "2e8a834886362b576ad8cff96a639e6e41a00af7",
"sha256": "acdd81b4dea2815f8838a0c3ea8ac4968f2bc13fd7c99173473d865779096782"
},
{
"path": "scripts/partial_swap_producer.py",
"usage": "provenance",
"git_blob": "9a450f15fba11c2ad49df346a3e0d3cdb25b1f5e",
"sha256": "dba07d742c68e8e4aedd1d93fc4c47a0481778268f7480997463e2b269fdd0a0"
},
{
"path": "scripts/partial_swap/README.md",
"usage": "provenance",
"git_blob": "3e753db831c6df9bdfb8885042f2aa464ce0d356",
"sha256": "a81a6a59b89f7db539bc317a7dce23ab84a75c7abebae105091de4e2aeb3f941"
},
{
"path": "notes/partial-swap-note.tex",
"usage": "provenance",
"git_blob": "5799f6a1fe7790b252d120e0c4f737c333a4773b",
"sha256": "bb9cc56d384973a8343a3789db7d7c1b353903ecbe4a9118522f14a9d4429b13"
}
]
}
70 changes: 70 additions & 0 deletions research/partial-swap-digest/TASK.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"schema_version": 1,
"task_id": "replay-runtime",
"priority_revision": 3,
"base_commit": "0b1cccf86e2f5132ed286a26ef0a681a495740ea",
"chooser_seed": "c88339d24517c9354275ac905ca0f320",
"original_card": {
"id": "replay-runtime",
"question": "Can one measured replay bottleneck be sped up without dropping coverage?",
"starting_points": [
"scripts/run_isolated_tests.py",
"scripts/verify_replay_coverage.py",
"certificates/selected-result.json"
],
"methods": [
"Profile one isolated replay and optimize the measured bottleneck.",
"Design source-bound reuse with explicit dependency invalidation and negative controls."
],
"acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.",
"first_step": {
"command": [
"python3",
"-B",
"scripts/research_baseline.py"
],
"expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY",
"inspect": "Read the selected reproduction command and choose a single replay stage for profiling.",
"scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay."
},
"first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.",
"bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.",
"allowed_variations": [
"Profile one stage or design one source-bound cache boundary."
],
"scope_change_triggers": [
"Skipping coverage or comparing different fixtures to claim speedup."
],
"overlap_terms": [
"replay runtime",
"cache invalidation",
"isolated tests"
]
},
"scope_status": "refined",
"actual_scope": "Can scripts/partial_swap/shared.py:SharedPointCircuit.verify emit the same circuit_sha256 digest lines (and the same support/topology assertion checks) without per-node json.dumps, so partial-swap verify receipts stay fieldwise identical while certificates/partial-swap-network.json updates only the shared.py source_sha256 pin?",
"scope_change_reason": "The catalogue card asks for one measured replay bottleneck with before/after wall time and retained checks. Expertise override selected verifier-engineering after open tooling PRs #1984/#1994 left the same hand-rolled digest pattern available on the distinct partial-swap fork of SharedPointCircuit (scripts/partial_swap/shared.py), which still called json.dumps per active node. Profiling named that digest stream as about half of h=46 verify time. Mask/closed-form ExclusionCircuit and DisjointTensor support rewrites (#2001) and the canonical shared_point_circuit.py digest object (#1994) are deliberately out of scope.",
"bottleneck_link": "Side result on review throughput: partial-swap producers, skip-strip graphs and related historical packages import partial_swap.shared.SharedPointCircuit.verify. A faster identical digest does not change kappa or the binding complex supplier.",
"budget_minutes": 60,
"stop_rule": "Ship an equivalence-preserving partial_swap SharedPointCircuit.verify digest change with frozen baseline, identical receipts on the historical h=46 circuit, pin-only certificate refresh, registered replay and a measured before/after median. Do not reopen mathematical screens, rewrite ExclusionCircuit/DisjointTensor support masks, or edit scripts/shared_point_circuit.py.",
"outcome": "completed",
"evidence": "PASS_PARTIAL_SWAP_DIGEST via research/partial-swap-digest/verify.py (also under -O); PASS_IDENTICAL_PARTIAL_SWAP_DIGEST_RECEIPTS via benchmark.py; certificates/partial-swap-network.json changes only scripts/partial_swap/shared.py in source_sha256.",
"author": "Wentao Li",
"github": "VictorLiwentao",
"email": "wentaol4@illinois.edu",
"ai_assistance": "Substantial AI assistance for orientation, overlap search, profiling, implementation, packaging, benchmarking and writing. Not independent human peer review.",
"open_questions": [
{
"question": "Should research packages that pin live scripts/partial_swap/shared.py bytes (for example copied-fixed / skip-strip provenance) refresh that one SHA-256 entry after this equivalence-preserving digest rewrite?",
"why_it_matters": "Those provenance packages bind working-tree bytes of shared.py; leaving old pins keeps this tooling PR focused, but a later full provenance replay on main would see a hash mismatch until refreshed.",
"first_step": "Open a dedicated provenance follow-up that only rewrites the shared.py entry after confirming circuit_sha256 identity.",
"blocked_by": "Pin repair outside certificates/partial-swap-network.json is outside this tooling change."
},
{
"question": "Is partial_swap.shared.SharedPointCircuit.__init__ merge/lookup construction worth a separate identical-receipt rewrite?",
"why_it_matters": "Bit-compression and large partial-swap builds still spend substantial wall time constructing the shared-point DAG; that is a different object from the verify digest stream measured here.",
"first_step": "Profile SharedPointCircuit(46).__init__ alone and compare against the verify residual after this digest change.",
"blocked_by": "Out of this session's stop rule; verify digests were the measured bottleneck."
}
]
}
55 changes: 55 additions & 0 deletions research/partial-swap-digest/VERIFY.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"schema_version": 1,
"status": "ready",
"python": "3.12",
"requirements": [],
"inputs": [
"scripts/partial_swap/shared.py",
"scripts/exclusion_circuit.py",
"scripts/partial_swap_network.py",
"scripts/partial_swap_producer.py",
"certificates/partial-swap-network.json",
"notes/partial-swap-note.tex",
"scripts/partial_swap/README.md"
],
"commands": [
{
"argv": [
"{python}",
"-I",
"-B",
"{package}/verify.py"
],
"timeout_seconds": 300,
"checks": "Exact baseline copy of the base-commit scripts/partial_swap/shared.py; identical SharedPointCircuit.verify receipts on h in {6,8,10,12,46}; encoding foil rejects wrong null and flat encodings; support-core rejection preserved; certificates/partial-swap-network.json changes only the shared.py source_sha256 pin."
},
{
"argv": [
"{python}",
"-I",
"-O",
"-B",
"{package}/verify.py"
],
"timeout_seconds": 300,
"checks": "Same digest equivalence under -O. Historical support checks use assert and are stripped under -O; circuit_sha256 identity remains the gate."
},
{
"argv": [
"{python}",
"-I",
"-B",
"-m",
"unittest",
"discover",
"-s",
"tests",
"-p",
"test_partial_swap_digest.py",
"-v"
],
"timeout_seconds": 120,
"checks": "Focused partial-swap digest package controls."
}
]
}
Loading