From ea5d11f172fd833638f99740c3776a6eb4dfcaef Mon Sep 17 00:00:00 2001 From: qingyunqian Date: Thu, 30 Jul 2026 05:29:46 +0800 Subject: [PATCH 1/3] Add Task 02 final expert optimization evidence --- optimized_solutions/challenge-02/README.md | 19 + .../research/IMPLEMENTATION_COMPARISON.md | 231 +++ .../challenge-02/research/INSIGHTS.md | 88 + .../challenge-02/research/LOG.md | 335 ++++ .../challenge-02/research/SURVEY.md | 155 ++ .../research/check_batched_purity.py | 113 ++ .../research/check_training_scan.py | 76 + .../research/figures/e01-gate-fusion.svg | 1490 ++++++++++++++++ .../research/figures/e02-training-scan.svg | 1487 ++++++++++++++++ .../research/figures/e03-frobenius-purity.svg | 1508 ++++++++++++++++ .../research/figures/e04-sparse-xxz.svg | 1521 +++++++++++++++++ .../research/figures/e05-packed-params.svg | 1474 ++++++++++++++++ .../research/figures/e06-entropy-vmap.svg | 1470 ++++++++++++++++ .../research/figures/e07-batched-purity.svg | 1486 ++++++++++++++++ .../research/plot_factor_ablations.py | 89 + .../research/profile_reference.py | 158 ++ .../profiles/e01-gate-fusion-equivalence.json | 13 + .../profiles/e01-gate-fusion-paired.json | 31 + .../e02-training-scan-equivalence.json | 18 + .../profiles/e02-training-scan-paired.json | 70 + .../profiles/e03-purity-equivalence.json | 15 + .../research/profiles/e03-purity-paired.json | 33 + .../profiles/e04-sparse-xxz-equivalence.json | 16 + .../profiles/e04-sparse-xxz-paired.json | 33 + .../e05-packed-params-equivalence.json | 16 + .../profiles/e05-packed-params-paired.json | 33 + .../e06-entropy-vmap-equivalence.json | 15 + .../profiles/e06-entropy-vmap-paired.json | 33 + .../e07-batched-purity-equivalence.json | 15 + .../profiles/e07-batched-purity-paired.json | 71 + .../e08-purestate-purity-equivalence.json | 15 + .../research/profiles/final-equivalence.json | 16 + .../profiles/final-reference-paired.json | 38 + .../research/profiles/reference-profile.json | 128 ++ ...solution_2_training_scan_batched_purity.py | 168 ++ 35 files changed, 12477 insertions(+) create mode 100644 optimized_solutions/challenge-02/README.md create mode 100644 optimized_solutions/challenge-02/research/IMPLEMENTATION_COMPARISON.md create mode 100644 optimized_solutions/challenge-02/research/INSIGHTS.md create mode 100644 optimized_solutions/challenge-02/research/LOG.md create mode 100644 optimized_solutions/challenge-02/research/SURVEY.md create mode 100644 optimized_solutions/challenge-02/research/check_batched_purity.py create mode 100644 optimized_solutions/challenge-02/research/check_training_scan.py create mode 100644 optimized_solutions/challenge-02/research/figures/e01-gate-fusion.svg create mode 100644 optimized_solutions/challenge-02/research/figures/e02-training-scan.svg create mode 100644 optimized_solutions/challenge-02/research/figures/e03-frobenius-purity.svg create mode 100644 optimized_solutions/challenge-02/research/figures/e04-sparse-xxz.svg create mode 100644 optimized_solutions/challenge-02/research/figures/e05-packed-params.svg create mode 100644 optimized_solutions/challenge-02/research/figures/e06-entropy-vmap.svg create mode 100644 optimized_solutions/challenge-02/research/figures/e07-batched-purity.svg create mode 100644 optimized_solutions/challenge-02/research/plot_factor_ablations.py create mode 100644 optimized_solutions/challenge-02/research/profile_reference.py create mode 100644 optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-equivalence.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-paired.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e02-training-scan-equivalence.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e02-training-scan-paired.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e03-purity-equivalence.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e03-purity-paired.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-equivalence.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-paired.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e05-packed-params-equivalence.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e05-packed-params-paired.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-equivalence.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-paired.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e07-batched-purity-equivalence.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e07-batched-purity-paired.json create mode 100644 optimized_solutions/challenge-02/research/profiles/e08-purestate-purity-equivalence.json create mode 100644 optimized_solutions/challenge-02/research/profiles/final-equivalence.json create mode 100644 optimized_solutions/challenge-02/research/profiles/final-reference-paired.json create mode 100644 optimized_solutions/challenge-02/research/profiles/reference-profile.json create mode 100644 optimized_solutions/challenge-02/solution_2_training_scan_batched_purity.py diff --git a/optimized_solutions/challenge-02/README.md b/optimized_solutions/challenge-02/README.md new file mode 100644 index 0000000..d4bc682 --- /dev/null +++ b/optimized_solutions/challenge-02/README.md @@ -0,0 +1,19 @@ +# Challenge 02 optimized expert solution + +This directory packages the final reviewed Task 02 campaign from Benchmark +PR [#17](https://github.com/hmyuuu/OrbitBreakersExpertBenchmarks/pull/17), +with the final tree taken from Benchmark `main` at `7e2298b`. + +- `solution_2_training_scan_batched_purity.py` is the optimized + TensorCircuit-NG variant. +- `research/IMPLEMENTATION_COMPARISON.md` is the final report. +- `research/profiles/`, `research/figures/`, and the plotting/equivalence + scripts preserve the factor-by-factor ablation evidence. + +All six matched pairs passed. Mean runtime changed from `4.495463 s` to +`4.031039 s`; mean paired speedup was `1.115649x` with a 95% t-interval of +`[1.057686x, 1.173613x]`. + +The canonical expert under `tasks/challenge-02/solution/` is intentionally +unchanged. Benchmark-harness reproduction commands in the research record +should be run in the Benchmark repository pinned above. diff --git a/optimized_solutions/challenge-02/research/IMPLEMENTATION_COMPARISON.md b/optimized_solutions/challenge-02/research/IMPLEMENTATION_COMPARISON.md new file mode 100644 index 0000000..ff80ff3 --- /dev/null +++ b/optimized_solutions/challenge-02/research/IMPLEMENTATION_COMPARISON.md @@ -0,0 +1,231 @@ +# Task 02 Human-Expert Optimization and Factor Ablation + +## Result + +The optimized implementation preserves the expert's 12-qubit +entanglement-profile-constrained VQE and is **1.11565x faster** in the final +six-pair same-machine comparison. Mean end-to-end runtime fell from +`4.495463 s` to `4.031039 s`; the candidate won all six counterbalanced +pairs. The mean paired speedup has a two-sided 95% Student-t interval of +`[1.057686x, 1.173613x]`. + +| Pair | Order | Expert (s) | Candidate (s) | Speedup | +|---:|---|---:|---:|---:| +| 1 | expert → candidate | 4.865151 | 3.981228 | 1.222023x | +| 2 | candidate → expert | 4.364947 | 4.042312 | 1.079814x | +| 3 | expert → candidate | 4.411195 | 4.134876 | 1.066826x | +| 4 | candidate → expert | 4.457106 | 4.007787 | 1.112111x | +| 5 | expert → candidate | 4.432053 | 4.030015 | 1.099761x | +| 6 | candidate → expert | 4.442327 | 3.990016 | 1.113361x | +| **Mean** | — | **4.495463** | **4.031039** | **1.115649x** | + +The requested first-five view is consistent: expert/candidate means are +`4.506090/4.039244 s`, and mean paired speedup is `1.116107x`. The sixth pair +is retained because the repository workflow predeclares six pairs and uses +their t-interval for promotion. + +Machine-readable result: +[`profiles/final-reference-paired.json`](profiles/final-reference-paired.json). + +## Optimized implementation + +Two accepted mechanisms are present. + +1. **One TensorCircuit training scan.** Parameters and Optax state are carried + through one `K.jaxy_scan`, and the complete 500-update function is compiled + once with `K.jit`. Each scan output is still the loss, energy density, + three entropies, and entropy MSE evaluated *before* its corresponding Adam + update. This removes 500 Python-to-device dispatches without removing an + update or changing history semantics. +2. **One batched exact-purity kernel.** The three block checkpoint states are + returned together. TensorCircuit's reduced density matrix is evaluated + through `K.vmap`, and order-2 Renyi entropy uses the Hermitian identity + `Tr(rho²) = sum(rho * conj(rho))`. This removes the three dense + `rho @ rho` products while keeping TensorCircuit's normalized density + matrices. + +Both nested scans use TensorCircuit backend `K.jaxy_scan`; the final source +does not directly import JAX. NumPy is used only for deterministic +initialization/input conversion and Optax supplies the unchanged Adam update. +The circuit, state evolution, density matrices, Hamiltonian action, autodiff, +JIT, vmap, and scans remain TensorCircuit-NG/backend-native. + +No parameter is tied or removed. There is no static answer, alternate quantum +framework, handwritten state-vector simulator, approximation, early stopping, +or relaxed evaluator threshold. + +## Why these changes target the measured cost + +The frozen reference profile found that one update lowers in `0.803158 s`, +compiles in `1.929769 s`, contains 15,479 StableHLO lines, and then takes +`0.002643 s` on average over 12 steady calls. Five hundred steady calls +project to `1.321653 s`, so both compilation and repeated dispatch/execution +are material. + +The forward trajectory accounts for about 93.5% of separately measured loss +time (`0.000889/0.000951 s`). A single generic entropy call is only +`0.000132 s`, and a Hamiltonian action is `0.000176 s`. These measurements +explain why removing the host training loop helps, why entropy changes need +batching to become reliable, and why replacing the Hamiltonian action does +not help at this scale. + +Reference profile: +[`profiles/reference-profile.json`](profiles/reference-profile.json). + +## Factor ablation + +Each timing-eligible factor was tested in six alternating matched pairs. +E01 and E02 compare with the immutable expert; E03–E07 compare directly with +the accepted scan parent. Ratios are therefore attribution experiments, not +numbers to multiply. A factor was promoted only when all cells passed, it won +at least five pairs, and the lower endpoint of its 95% paired-speedup +t-interval exceeded one. + +| ID | Factor | Mean paired speedup | 95% t-CI | Wins | Decision | +|---|---|---:|---:|---:|---| +| E01 | Exact local gate fusion | 0.965849x | [0.946219, 0.985478] | 0/6 | Discard | +| E02 | Whole-training `K.jaxy_scan` | 1.035580x | [1.010063, 1.061098] | 6/6 | **Keep** | +| E03 | Frobenius purity alone | 1.024675x | [0.961881, 1.087470] | 5/6 | Inconclusive | +| E04 | TensorCircuit sparse XXZ | 0.972882x | [0.947782, 0.997981] | 2/6 | Discard | +| E05 | Single-leaf parameter packing | 0.428014x | [0.411501, 0.444527] | 0/6 | Discard | +| E06 | Checkpoint entropy `K.vmap` alone | 1.046783x | [0.985861, 1.107705] | 5/6 | Inconclusive | +| E07 | `K.vmap` + exact Frobenius purity | 1.074457x | [1.044174, 1.104740] | 6/6 | **Keep** | + +### E01: exact local gate fusion + +Fusion reduced 243 gate applications to 105, but dynamic trigonometry and +matrix construction outweighed the savings. The implementation was correct +at the gate, state, gradient, and post-update-observable levels, yet was +3.4% slower by paired ratio. + +![E01 paired gate-fusion ablation](figures/e01-gate-fusion.svg) + +### E02: whole-training scan + +All four 12-step histories were bit-identical. Moving the 500 updates across +one TensorCircuit scan boundary produced the first statistically supported +gain. + +![E02 paired training-scan ablation](figures/e02-training-scan.svg) + +### E03: exact Frobenius purity alone + +Replacing `trace(rho @ rho)` was numerically valid and won five pairs, but one +unfavorable pair widened the interval across one. It is not credited as an +independent gain. + +![E03 paired purity ablation](figures/e03-frobenius-purity.svg) + +### E04: TensorCircuit sparse XXZ + +`PauliStringSum2COO(..., numpy=True)` and `K.sparse_dense_matmul` passed the +Hamiltonian and trajectory audits, but were slower than the current 45-term +MVP for this 4,096-amplitude state. + +![E04 paired sparse-XXZ ablation](figures/e04-sparse-xxz.svg) + +### E05: packed parameters + +Packing ten PyTree leaves into `(3, 81)` was bit-exact but more than doubled +runtime. Static unpack slices introduce expensive gather/scatter work in +compilation and reverse mode; the expert's PyTree is already efficient. + +![E05 paired packed-parameter ablation](figures/e05-packed-params.svg) + +### E06: checkpoint `K.vmap` alone + +Batching the unchanged generic entropy kernel won five pairs but did not pass +the confidence rule. It is retained only as the predeclared subfactor evidence +for E07. + +![E06 paired entropy-vmap ablation](figures/e06-entropy-vmap.svg) + +### E07: batched exact purity + +Combining E03 and E06 changes the shared batched kernel: the three generic +density matrices remain TensorCircuit-generated while all three second +matrix products disappear together. This combination passed with `6/6` wins +and a lower confidence bound of `1.044174x`. The defensible attribution is to +the **combination**, not to either statistically inconclusive subfactor. + +![E07 paired batched-purity ablation](figures/e07-batched-purity.svg) + +E08 attempted to batch pure-state Gram matrices directly for the contiguous +six/six cut. It was rejected before timing because the changed complex64 +contraction order caused a `5.35e-6` entropy-history difference above the +frozen tolerance. Since it was not timing-eligible, no performance chart or +speedup claim is manufactured for it. + +All plots are regenerated from the tracked paired JSON files by +[`plot_factor_ablations.py`](plot_factor_ablations.py). + +## Correctness + +The candidate preserves: + +- the 12-qubit Neel state and complex64 TensorCircuit evolution; +- three even-plus-odd blocks and all 243 independently initialized angles; +- every ordered `RY`, `RZ`, `RXX`, `RYY`, and `RZZ` gate; +- the three normalized half-chain order-2 Renyi checkpoints; +- the exact 45-term open XXZ plus staggered-field energy; +- seed 2026, Adam learning rate `0.015`, exactly 500 sequential updates, and + every pre-update history; +- the original four-key NumPy result contract. + +After the final TensorCircuit-native normalization, the 12-step audit measured: + +```text +initial loss absolute error: 0 +maximum auxiliary error: 2.98e-7 +maximum gradient-element error: 1.21e-8 +maximum 12-step history error: 1.07e-6 +``` + +Every one of the 12 final benchmark cells passed the canonical evaluator. +The candidate remains below the repository's 200-effective-line policy at +168 physical lines. + +## Reproduction and provenance + +The benchmark used a fresh evaluator process per cell in a no-network +container with six CPUs, 7 GiB memory, and a 300-second cap. The hard six-CPU +backend limit is not treated as a problem: every claim is a counterbalanced +relative comparison on the same machine and resource allocation. + +Environment: + +```text +image ID: sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833 +TensorCircuit-NG: 1.8.0.dev20260726 +JAX / JAXLIB: 0.10.0 / 0.10.0 +Optax: 0.2.8 +TensorNetwork / Quimb: 0.5.1 / 1.11.1 +candidate SHA-256: aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30 +raw final report SHA-256: 27ec959f8e23156a0c8f0b15bb0f122b86e3a32e1842764888ef90eb07a842dd +``` + +Run: + +```bash +./bench run 02 \ + --solution optimized --compare-to reference \ + --repeat 6 --engine docker --cpus 6 --memory 7g \ + --timeout 300 --no-build \ + --output results/task-02-final-20260729 +``` + +Regenerate charts: + +```bash +MPLCONFIGDIR=/tmp/task02-mplconfig \ + python3 research/task-02/plot_factor_ablations.py +``` + +The complete append-only chronology, candidate hashes, audits, raw-report +hashes, and negative results are in [`LOG.md`](LOG.md). The concise mechanism +ledger is in [`INSIGHTS.md`](INSIGHTS.md). The reusable campaign procedure is +[`EXPERT_OPTIMIZATION_WORKFLOW.md`](https://github.com/hmyuuu/OrbitBreakersExpertBenchmarks/blob/7e2298b/autoresearch/EXPERT_OPTIMIZATION_WORKFLOW.md). + +The conclusion is intentionally limited to this public canonical workload, +latest tested TensorCircuit-NG image, and same-host resource allocation. It is +not a global SOTA or scaling claim. diff --git a/optimized_solutions/challenge-02/research/INSIGHTS.md b/optimized_solutions/challenge-02/research/INSIGHTS.md new file mode 100644 index 0000000..42151ab --- /dev/null +++ b/optimized_solutions/challenge-02/research/INSIGHTS.md @@ -0,0 +1,88 @@ +# Task 02 Research Insights + +Task: `task-02` + +Last consolidated: `2026-07-29` + +Evidence ledger: [`LOG.md`](LOG.md) + +## Current best + +The accepted implementation combines whole-training TensorCircuit +`K.jaxy_scan` with batched checkpoint states and exact Frobenius purity. +Against the scan-only parent, the entropy combination achieved `1.074457x` +mean paired speedup, 95% interval `[1.044174x, 1.104740x]`, and `6/6` wins. +The final immutable-reference comparison is recorded separately after source +freeze. + +## Preserved semantics + +- 12-qubit Neel input and complex64 TensorCircuit-NG evolution; +- six brickwork sublayers with all 243 independent parameters; +- three half-chain Renyi-2 checkpoints and the fixed target profile; +- the 45-term open XXZ plus staggered-field Hamiltonian; +- fixed seed 2026, Adam learning rate `0.015`, and 500 sequential updates; +- every pre-update history and the original four-key NumPy result contract. + +## Confirmed bottlenecks + +- One update lowers in `0.803158 s`, compiles in `1.929769 s`, and contains + 15,479 StableHLO lines. The 500 steady updates project to `1.321653 s`, so + both cold graph staging and steady execution are material. +- The separately compiled trajectory is about 93.5% of the forward loss + runtime (`0.000889/0.000951 s`), making exact gate-graph reduction the + highest-priority factor. +- The host dispatches one compiled optimizer update 500 times. A whole-training + scan can remove that boundary, although it cannot eliminate the steady + quantum kernel itself. +- The termwise Hamiltonian MVP traces 45 independent paths, but its separately + measured forward action is only `0.000176 s`. Sparse conversion is therefore + a secondary compile-size hypothesis, not the primary steady bottleneck. +- One generic Renyi-2 call is `0.000132 s`; its Frobenius-purity rewrite is + algebraically exact but expected to be a smaller factor than gate fusion. + +Profile: [`profiles/reference-profile.json`](profiles/reference-profile.json). + +## What worked + +- Whole-training `K.jaxy_scan` preserved the four 12-step histories + bit-for-bit and reduced canonical mean runtime from `4.724217` to + `4.563051 s` in its six-pair session. +- Returning all three block checkpoints and batching the exact + `-log(sum(rho * conj(rho)))` calculation with `K.vmap` produced a further + `1.074457x` paired gain over scan-only, with its confidence interval wholly + above one. +- The combination result is not attributed to either subfactor alone: + `K.vmap` alone (`1.046783x`) and Frobenius purity alone (`1.024675x`) both + had wide intervals crossing one. The confirmed unit is their shared kernel. + +## What did not work + +- Exact local gate fusion reduced the gate-application count but regressed to + `0.965849x`; dynamic trigonometry and matrix assembly cost more than the + saved applications. +- TensorCircuit sparse XXZ action regressed to `0.972882x`; the 45-term + termwise MVP is preferable at this size. +- Packing the ten-leaf PyTree into one tensor was bit-exact but collapsed to + `0.428014x` due to slice/gather/scatter compile and autodiff overhead. +- Frobenius purity alone and checkpoint `K.vmap` alone were inconclusive and + are not claimed independently. +- Direct batched pure-state Gram matrices were rejected before timing: a + different complex64 contraction order exceeded the frozen trajectory + tolerance despite algebraic equivalence. + +## Open hypotheses + +1. larger-qubit scaling, which is outside this frozen workload; +2. future TensorCircuit compiler changes that may alter the discarded + gate-fusion or sparse-kernel tradeoffs. + +## Evidence limits + +Evidence covers only the canonical public Task 02 configuration, one latest +TensorCircuit-NG image, and one 6-CPU/7-GiB same-host profile. It does not +establish global SOTA or scaling. End-to-end differences include cold import, +tracing, compilation, 500 updates, synchronization, and conversion. + +The final six-pair comparison records `1.115649x` mean paired speedup with a +95% Student-t interval `[1.057686x, 1.173613x]` and `6/6` wins. diff --git a/optimized_solutions/challenge-02/research/LOG.md b/optimized_solutions/challenge-02/research/LOG.md new file mode 100644 index 0000000..f8e0e7c --- /dev/null +++ b/optimized_solutions/challenge-02/research/LOG.md @@ -0,0 +1,335 @@ +# Task 02 Autoresearch Campaign + +Task: `task-02` + +Campaign branch: `codex/orbitbreakers/task-02/extreme-native` + +Campaign task: `task-02` + +Insights: [`INSIGHTS.md`](INSIGHTS.md) + +## Campaign objective + +Reduce evaluator-reported runtime for the immutable Task 02 human expert while +preserving all 243 trainable parameters, three block-checkpoint Renyi-2 +entropies, the 45-term XXZ energy, and exactly 500 sequential Adam updates. + +## Selection and gates + +- `2026-07-29T13:30Z`: inspected all open PRs on `sxzgroup/ORBIT-Q` and the + benchmark repository. No active Task 02 optimization was present. This + campaign and every hypothesis worktree are bound to Task 02. +- Base commit: + `d13e2591574cc1480507b00bcb33b0c6a48e6b99`. +- Public data only; no hidden or private evaluation is used. +- Reference and initial optimized sources were byte-identical at selection, + SHA-256 + `cd5776dfb223924edd83795bd8222032351008a584b55d747110521c709dcdd3`. + +## Baseline `reference-six-20260729` + +Hypothesis: the latest TensorCircuit-NG image and fixed 6-CPU/7-GiB envelope +produce a valid repeated reference suitable for paired promotion decisions. + +Command: + +`./bench run 02 --solution reference --repeat 6 --engine docker --cpus 6 +--memory 7g --timeout 300 --no-build --output +results/task-02-reference-20260729` + +Environment: + +- image ID: + `sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833`; +- TensorCircuit-NG `1.8.0.dev20260726`; +- JAX/JAXLIB `0.10.0` / `0.10.0`; +- Optax `0.2.8`; +- TensorNetwork `0.5.1`; Quimb `1.11.1`; +- host fingerprint: + `c627504db97dc65b8d998afb4b9cdf73cfc3eff2ce2ac589b4a7a4aa0c7fdc48`; +- one shared container, six CPUs, 7 GiB, no network, 300-second per-cell cap; +- evaluator SHA-256: + `0d9360d4812d033d364253dd478444f68918f1b05f04146eddcb846a3dca3a1e`; +- dependency-lock SHA-256: + `cd5ac5cb2102ea7b40bd46dc81320cc59e0ce0671ab88c597f81d82b384a824b`. + +Result: + +```text +terminal_status: SUCCESS +valid: true +timed_out: false +passing_runs: 6/6 +runtimes_sec: 4.559075, 4.986945, 4.990731, 5.188701, 4.813289, 6.035628 +mean_runtime_sec: 5.0957281667 +median_runtime_sec: 4.988838 +sample_stdev_sec: 0.5064942904 +runtime_stderr_sec: 0.2067754282 +min_runtime_sec: 4.559075 +max_runtime_sec: 6.035628 +``` + +Immutable report SHA-256: +`7d450e074cc5a4cabca72e9f6cd5787e2f5226c42c69cf6c3016ec53465b9912`. + +Decision: `baseline`. The repeated-reference promotion gate passes. No +improvement is claimed without matched candidate pairs. + +## Append-only campaign events + +- `2026-07-29T13:31Z`: inspected installed TensorCircuit sources. The expert's + Pauli MVP traces one path per Hamiltonian term; Renyi-2 forms `rho @ rho`; + and the backend's `K.jaxy_scan` delegates to `jax.lax.scan`. +- `2026-07-29T13:31Z`: completed the cited survey and canonical public workload + record. Candidate editing remains blocked until the manifest is rebound and + the fail-closed gate passes. +- `2026-07-29T13:33Z`: survey, public dataset, and repeated-reference gates all + pass. Added an immutable-reference profiler to separate lowering, + compilation, trajectory, entropy, Hamiltonian action, and steady optimizer + execution before selecting candidate factors. +- `2026-07-29T13:35Z`: immutable-reference profile completed. Report + `research/task-02/profiles/reference-profile.json`, SHA-256 + `b7d190ea225ca5586d813759b89fea0cba05c045ca41e72e8f687a8769241d40`; + profiler SHA-256 + `538a86104c32925586606394f50be069800c18b054bae45a6ebb786ac0e76a8b`. + One update lowers in `0.803158 s`, compiles in `1.929769 s`, contains + 15,479 StableHLO lines, and executes in `0.002643 s` mean over 12 steady + calls. The projected 500-update kernel time is `1.321653 s`. The forward + trajectory accounts for about 93.5% of the separately measured loss + execution (`0.000889/0.000951 s`); a Hamiltonian action is only + `0.000176 s`, and one generic entropy is `0.000132 s`. Decision: prioritize + graph reduction and host-loop removal, while treating sparse Hamiltonian and + purity rewrites as secondary measured factors. + +## Append-only corrections + +Append corrections below this heading. Never rewrite an earlier result after +it has informed another experiment. + +## Experiment `e07-batched-purity` + +Branch: `codex/orbitbreakers/task-02/e07-batched-purity` + +Parent commit: `edf1e91` (accepted whole-training scan). + +Execution note: this hypothesis uses a fresh local shared Git checkout and +independent branch at the accepted commit after worktree permission review +timed out. + +Hypothesis: the predeclared shared-kernel combination of checkpoint +`K.vmap` and exact Frobenius purity will batch the three reduced-density +matrices while removing all three dense `rho @ rho` products. The prior +single-factor reports remain the subfactor ablations; neither subfactor alone +passed the confidence rule. + +Permitted data: public Task 02 artifacts and the two completed single-factor +reports only. No hidden/private evaluation. + +Pre-evaluation correctness rule: initial loss/auxiliary values, gradient, and +all four 12-step histories must satisfy the frozen survey tolerances. + +Candidate source SHA-256: +`181c0459c8194aa259be813e23896d3c70691adf5999a26353fe57cab14d3f3d`. + +Candidate source-diff SHA-256: +`ad7f082c18273b9f8c67cab5aef8477983791011261bb604ea62f6768d3a3fcf`. + +The 12-step audit passed: initial loss error `0`, auxiliary maximum error +`2.981e-7`, gradient maximum error `1.211e-8`, and maximum history error +`1.073e-6`. Audit report SHA-256: +`107c59ce1785ee9ada91e061d01970f1522ea73f3d8fe3efea37c03138d06b53`. + +Six direct parent/factor pairs all passed. Parent/factor means were +`4.531128/4.218862 s`; factor wins `6/6`; mean paired speedup `1.074457x`, +95% Student-t interval `[1.044174x, 1.104740x]`. The runner roles were +intentionally reversed so its registered `optimized` source was the factor; +the tracked report normalizes every ratio as parent/factor. Raw report +SHA-256: +`6dd10f3c24054668734022000058391c192c87f0554d404a6d3b7d61593ee07e`. + +Decision: `keep`. The shared-kernel combination passes the confidence rule +although each predeclared subfactor was inconclusive alone. + +## Experiment `e02-training-scan` + +Branch: `codex/orbitbreakers/task-02/e02-training-scan` + +Parent commit: `77939b1` + +Hypothesis: carrying parameters and Optax state through one TensorCircuit +`K.jaxy_scan`, compiled by `K.jit`, will preserve all 500 sequential updates +and pre-update histories while removing 500 Python-to-device dispatches. + +Permitted data: public Task 02 artifacts and tracked reference profile only. +No hidden/private evaluation. + +Candidate SHA-256: +`6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a`. + +Candidate diff SHA-256: +`9b590f4cb193a39327b38165bcd255f3e051f5eb76d495b141194ebefbcbe1d8`. + +Pre-evaluation correctness rule: all four 12-step pre-update histories must +match the immutable expert within `2e-4` and retain identical shapes. + +The 12-step audit passed with bit-identical values and shapes for all four +returned histories. Audit report SHA-256: +`8864dd25031e00e1df188f705824738925e3679e4e46e06ae7078c5ccb6a1493`. + +Six alternating canonical pairs all passed. Reference/candidate means were +`4.724217/4.563051 s`; candidate wins `6/6`; mean paired speedup +`1.035580x`, 95% Student-t interval `[1.010063x, 1.061098x]`. Raw report +SHA-256: +`549e267378bc1eca2ea2b839810af4c46780ac8bdc7800eacdfc15385bc1e33b`. + +Decision: `keep`. Whole-training `K.jaxy_scan` is the first accepted parent +and removes about 3.41% of end-to-end runtime in this session. + +## Consolidated independent-factor records + +The following experiments ran on isolated branches. They are appended here +after completion so the final branch retains both successful and negative +evidence without promoting discarded code. + +### Experiment `e01-gate-fusion` + +Parent commit: `77939b1`. Candidate SHA-256: +`76917fc2292984b0102dda14ceb3b873f4ca55779554d29f2fa887ffd2f3f214`. + +Hypothesis: replace all exact `RY -> RZ` pairs and commuting +`RXX -> RYY -> RZZ` triples with one differentiable TensorCircuit unitary, +reducing circuit applications from 243 to 105 without tying parameters. + +The final audit passed: local matrix error `1.33e-7`, state error `3.07e-7`, +loss error `2.38e-7`, gradient error `7.45e-8`, and post-update physical +output error `5.36e-7`. The raw Adam parameter difference (`3.63e-4`) came +from near-zero-gradient sensitivity and did not alter observables. Audit +report SHA-256: +`0c389fba34386ab57904a833d90f1192fe174515bfc5c928e27f44fb1e670a33`. + +Six pairs: reference/candidate means `4.659226/4.825325 s`, `0/6` wins, +mean paired speedup `0.965849x`, 95% interval +`[0.946219x, 0.985478x]`. Raw report SHA-256: +`1804ebe44515690e1985411b16a51153aa6ddb88ec8a6c964d4d90fe0c365ce9`. + +Decision: `discard`. Dynamic trigonometric and matrix assembly outweighed the +smaller gate-application count. + +### Experiment `e03-purity` + +Parent: accepted scan. Candidate SHA-256: +`ab560235d23e2dcd5256467f1dba03bb4eee7d675250ccf9054c3d8a670c508e`. + +Hypothesis: use the exact Hermitian identity +`trace(rho @ rho) = sum(rho * conj(rho))`, removing three 64-by-64 matrix +products per loss. + +The audit passed with gradient error `1.70e-8` and maximum 12-step history +error `1.25e-6`. Six pairs: parent/factor means +`4.591056/4.491962 s`, `5/6` wins, mean paired speedup `1.024675x`, 95% +interval `[0.961881x, 1.087470x]`. Raw report SHA-256: +`cccabf99871f8fe7d62ac42fdedd6d77394157fdd41a490ff42f324104565184`. + +Decision: `discard_inconclusive`; the interval crosses one. + +### Experiment `e04-sparse-xxz` + +Parent: accepted scan. Candidate SHA-256: +`c5997e6147212271ec45321880a14d696849a6436fb99f16a02b72fc42992942`. + +Hypothesis: replace 45 termwise MVP traces with TensorCircuit +`PauliStringSum2COO(..., numpy=True)` plus `K.sparse_dense_matmul`. + +The audit passed with Hamiltonian-action error `1.67e-5`, gradient error +`3.91e-8`, and maximum 12-step history error `1.19e-6`. Six pairs: +parent/factor means `4.296697/4.417261 s`, `2/6` wins, mean paired speedup +`0.972882x`, 95% interval `[0.947782x, 0.997981x]`. Raw report SHA-256: +`8bfba5d0d90cde8ddb571e38d975044e5ea50001e9581a1a617a13fe9bca6c12`. + +Decision: `discard`. For this 12-qubit, 45-term workload the native sparse +construction/kernel is slower than the current termwise MVP. + +### Experiment `e05-packed-params` + +Parent: accepted scan. Candidate SHA-256: +`895ede0c511e60221400a85066b036ab57fce683df614a2cabb389e928826b70`. + +Hypothesis: pack ten parameter leaves into one `(3, 81)` tensor to shrink scan +carry, Optax state, PyTree bookkeeping, and the compiled graph. + +The audit was bit-identical for initialization, loss, auxiliary values, +gradient, and four 12-step histories. Six pairs: parent/factor means +`4.592900/10.730835 s`, `0/6` wins, mean paired speedup `0.428014x`, 95% +interval `[0.411501x, 0.444527x]`. Raw report SHA-256: +`b24d2fbeb2094e23f2353b94a71896dc6b1f506bf6eea600b14536aa7d7617fb`. + +Decision: `discard`. Static unpack slices add costly gather/scatter autodiff; +the original ten-leaf PyTree is substantially better. + +### Experiment `e06-entropy-vmap` + +Parent: accepted scan. Candidate SHA-256: +`c9c7840740152f03f23ddbc50379098847508007288da397ecf592952204cdb2`. + +Hypothesis: return all three checkpoint states, then apply unchanged +TensorCircuit reduced-density-matrix Renyi-2 kernels through `K.vmap`. + +The audit passed with gradient error `1.86e-8` and maximum 12-step history +error `8.34e-7`. Six pairs: parent/factor means +`4.765934/4.572339 s`, `5/6` wins, mean paired speedup `1.046783x`, 95% +interval `[0.985861x, 1.107705x]`. Raw report SHA-256: +`a43cd8242d76503057c88e4de2ee7b702965ecf89c41643b21ba4d8664d13a97`. + +Decision: `discard_inconclusive`. It is not retained alone; E07 separately +predeclared and measured the changed shared kernel formed by combining this +factor with exact Frobenius purity. + +## Final TensorCircuit-native normalization + +After factor selection, the inner block scan was changed from direct +`jax.lax.scan` to TensorCircuit backend `K.jaxy_scan`, and the now-unused +direct JAX import was removed. In the installed backend this is a thin +framework-native delegation to the same JAX primitive, so it is a fidelity +normalization rather than a separately claimed speedup factor. The final +source SHA-256 before confirmation is: +`aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30`. + +The full E07 equivalence audit and final immutable-reference timing are rerun +after this normalization; no earlier factor result is reused as final timing. + +## Experiment `e08-purestate-purity` + +Parent commit: `0501d90`. Candidate source SHA-256: +`950e86b9c0db25497034ce0ff385619262bbdecfee56e35bcf832f13f95da7e3`. + +Hypothesis: exploit the contiguous six/six public half-chain cut by reshaping +all checkpoint pure states to `(3, 64, 64)`, constructing retained-half Gram +matrices in one backend `K.einsum`, and computing their purities together. + +The audit failed the frozen gate before timing. Initial loss error was +`5.96e-7` and gradient error `3.77e-8`, but the changed complex64 contraction +order produced auxiliary error `2.50e-6` and 12-step entropy-history error +`5.35e-6`, above the predeclared tolerance. Audit report SHA-256: +`d032009a567fcf2ec1da244318e27a8f1788a20c19af029b6afb8cc0eaa08b4d`. + +Decision: `discard_before_timing`. No performance claim or chart is produced +for a candidate that failed correctness. + +## Final immutable-reference confirmation + +Final candidate SHA-256: +`aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30`. + +The post-normalization 12-step audit reproduced the E07 values: loss error +`0`, auxiliary error `2.981e-7`, gradient error `1.211e-8`, and maximum +history error `1.073e-6`. + +All twelve cells in six alternating immutable-reference/candidate pairs +passed. Reference/candidate means were `4.495463/4.031039 s`; candidate wins +`6/6`; mean paired speedup `1.115649x`, 95% Student-t interval +`[1.057686x, 1.173613x]`; mean paired improvement `10.192992%`. The first +five pairs independently give mean runtimes `4.506090/4.039244 s` and mean +paired speedup `1.116107x`. Raw report SHA-256: +`27ec959f8e23156a0c8f0b15bb0f122b86e3a32e1842764888ef90eb07a842dd`. + +Decision: `final_keep`. diff --git a/optimized_solutions/challenge-02/research/SURVEY.md b/optimized_solutions/challenge-02/research/SURVEY.md new file mode 100644 index 0000000..6dc081e --- /dev/null +++ b/optimized_solutions/challenge-02/research/SURVEY.md @@ -0,0 +1,155 @@ +# ORBIT-Q Task 02 Runtime Optimization Survey + +**Status: READY** + +Campaign task: `task-02` + +Survey freeze: `2026-07-29T13:31:00Z` + +Reference commit: `d13e2591574cc1480507b00bcb33b0c6a48e6b99` + +This campaign covers only Task 02. The immutable expert, public canonical +workload, semantic constraints, optimization hypotheses, and measurement rule +are frozen before the first candidate edit. + +## Evidence and claim boundary + +The immutable human expert is `references/task-02/solution_2.py` +(`sha256:cd5776dfb223924edd83795bd8222032351008a584b55d747110521c709dcdd3`). +The public contract and evaluator are `tasks/task-02/problem.md` +(`sha256:e3e9b7517cd8aa1d0fad4fe4bce13cd61cde94d94c21b0324df95e80dd581a39`) +and `tasks/task-02/evaluator/evaluate_2.py` +(`sha256:0d9360d4812d033d364253dd478444f68918f1b05f04146eddcb846a3dca3a1e`). + +At `2026-07-29T13:30Z`, the six open PRs on `sxzgroup/ORBIT-Q` were +repository infrastructure, agent-axis results, and the Task 07 design report; +none targeted Task 02. The separate benchmark repository likewise had no +active Task 02 optimization PR. + +The immutable reference passed six fresh evaluator processes at +`4.559075`, `4.986945`, `4.990731`, `5.188701`, `4.813289`, and +`6.035628` seconds. Its mean is `5.095728` seconds, median `4.988838` +seconds, sample standard deviation `0.506494` seconds, and standard error +`0.206775` seconds. No external result uses this exact evaluator, target +profile, initialization, 500-step Adam trajectory, image, and hardware +allocation. Claims are limited to same-machine gains over the bundled expert +on the canonical public workload. + +## Framework and environment + +Measurements use image +`sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833` +with six CPUs, 7 GiB memory, no network, and a fresh evaluator process per +cell. The dependency lock is +`envs/tensorcircuit-py311/requirements.lock` +(`sha256:cd5ac5cb2102ea7b40bd46dc81320cc59e0ce0671ab88c597f81d82b384a824b`). +No TensorCircuit downgrade is used. + +| Component | Version | Inspected source | +| --- | --- | --- | +| TensorCircuit-NG | `1.8.0.dev20260726` | `quantum.py` (`sha256:fcaee21ba5ccde1b89c46e2f5424c48d342e3bfaedf72adba672ab6bd4ded703`), `circuit.py` (`sha256:5c4d569325369d957dc60bbeca8a581508549ff9813a7a163de61a6294864662`), and `gates.py` (`sha256:6db54dab1390360273ef527a1fadc4f36ba169d7e961dcc4bd049b6b2a43cbe4`) | +| JAX / JAXLIB | `0.10.0` / `0.10.0` | TensorCircuit JAX backend (`sha256:88657aebf8e5d566ac4e653abe327083da0253f02a3a297a134b871ffe4baab9`) | +| Optax | `0.2.8` | Adam with the required `0.015` learning rate and exactly 500 updates | +| TensorNetwork / Quimb | `0.5.1` / `1.11.1` | Installed support stack; the dense state path does not invoke OMECo | + +TensorCircuit documents sparse, dense, vmap, termwise, and MPO alternatives +for Pauli-sum expectation values: +. +Its public quantum source documents both `PauliStringSum2MVP` and +`PauliStringSum2COO`, and implements order-2 Renyi entropy as +`-log(trace(rho @ rho))`: +. +TensorCircuit's FAQ describes the same reduced-density-matrix and Renyi APIs +used by the expert: +. +JAX documents that `lax.scan` lowers a fixed loop to one WhileOp rather than +unrolling it: +. + +## Task 02: entanglement-profile-constrained VQE + +The expert evolves a dense 12-qubit complex64 state from the Neel basis state. +Each of three blocks applies one even and one odd brickwork sublayer. Every +sublayer applies independent `RY -> RZ` rotations, followed by independent +`RXX -> RYY -> RZZ` gates on its bonds. After each complete block it computes +the left-half Renyi-2 entropy. The final state is evaluated against the +45-term open XXZ plus staggered-field Hamiltonian. Reverse-mode differentiation +updates all 243 independent float32 parameters with Adam for exactly 500 steps. + +Every viable candidate must preserve: + +- the 12-qubit Neel input, six trainable sublayers, and all 243 independent + parameters initialized from the fixed NumPy seed 2026; +- the exact TensorCircuit gate convention and every ordered + `RY -> RZ -> RXX -> RYY -> RZZ` operation; +- the normalized state after each complete block and the three half-chain + order-2 Renyi entropies; +- the exact 45-term XXZ/staggered-field energy, entropy weight `0.25`, target + profile `[0.30, 0.60, 0.80]`, and complex64 semantics; +- exactly 500 sequential Adam updates and every pre-update energy, loss, + entropy MSE, and three-entropy row; +- TensorCircuit-NG as the central quantum framework and the original four-key + NumPy output contract. + +## Source-supported cost model + +One loss contains 243 parameterized TensorCircuit gates, three 64-by-64 +reduced-density matrices, three dense `rho @ rho` products, and one +45-term Hamiltonian action on 4,096 amplitudes. Reverse mode differentiates +through all of these operations. The expert stages one update once, but then +dispatches the compiled update from Python 500 times. + +The installed `PauliStringSum2MVP` loops over all 45 Pauli terms in Python +during tracing and emits a separate mask/flip/multiply/accumulate path per +term. `PauliStringSum2COO` instead creates one native backend sparse operator. +The installed pure-state reduced-density-matrix path reshapes the amplitude +vector to 64-by-64 and forms `rho = w @ w.adjoint()`. For a Hermitian density +matrix, `trace(rho @ rho) = sum(abs(rho) ** 2)`, so the second dense matrix +product is algebraically removable without changing the requested entropy. + +The three Pauli rotations on a bond commute. Their product is one exact +parity-preserving 4-by-4 TensorCircuit gate. Likewise, each `RY -> RZ` +sequence is one exact 2-by-2 gate. This can reduce 81 gate applications per +block to 35 while keeping every angle independent. + +## Frozen experiments + +1. **Whole-training TensorCircuit scan.** Carry parameters and Optax state + through `K.jaxy_scan` and return all pre-update observables. This tests host + dispatch independently. +2. **Exact Renyi-2 purity reduction.** Keep TensorCircuit's reduced density + matrix but replace `trace(rho @ rho)` with `sum(abs(rho) ** 2)`. Require + state, entropy, loss, gradient, one-update, and short-history agreement. +3. **Native sparse XXZ action.** Compare TensorCircuit + `PauliStringSum2COO` plus backend sparse-dense multiplication against the + expert's termwise MVP. Retain only if canonical timing improves. +4. **Exact local gate fusion.** Replace each parameterized `RY -> RZ` pair + and commuting `RXX -> RYY -> RZZ` triple with its exact differentiable + TensorCircuit unitary. Audit random gate matrices and end-to-end gradients. +5. **Initial-state constant construction.** Build the same Neel amplitude + vector without eight circuit nodes only if profiling shows a measurable + residual; this is expected to be negligible. +6. **MPS or truncated Schmidt simulation.** Reject for the canonical + campaign: the entropy checkpoint and unconstrained entanglers do not give a + static small exact bond bound, and truncation would change semantics. + +Each retained factor will receive six alternating matched pairs against its +accepted parent, plus one chart. The final combination will be remeasured +against the immutable expert. + +## Correctness and measurement rule + +Before canonical timing, compare reference and candidate block states, +entropies, energy, complete loss, gradient leaves, one Adam update, and a +short physical history. Frozen complex64 tolerances are `2e-6` for gates, +states, observables, and initial loss; `1e-5` for gradient elements; and +`2e-4` for post-update and short-history physical outputs. Raw Adam parameter +differences caused only by theoretical-zero complex64 gradients must be +reported and cannot replace the physical-output checks. + +Final evidence uses six counterbalanced canonical pairs in one no-network +container. Odd pairs run reference then candidate; even pairs reverse order. +Every cell is a fresh evaluator process with a 300-second cap. Promotion +requires all 12 cells to pass, candidate wins at least five of six pairs, +candidate mean and median are lower, and the lower endpoint of a two-sided +95% Student-t interval for mean pairwise speedup exceeds `1.0`. diff --git a/optimized_solutions/challenge-02/research/check_batched_purity.py b/optimized_solutions/challenge-02/research/check_batched_purity.py new file mode 100644 index 0000000..9e9761d --- /dev/null +++ b/optimized_solutions/challenge-02/research/check_batched_purity.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +"""Audit the batched exact Renyi-2 kernel for Task 02.""" + +from __future__ import annotations + +import argparse +import importlib.util +import json +from pathlib import Path + +import numpy as np +import tensorcircuit as tc + + +ROOT = Path(__file__).resolve().parents[2] +REFERENCE = ROOT / "references" / "task-02" / "solution_2.py" +CANDIDATE = ROOT / "src" / "solutions" / "task-02" / "solution_2.py" +EVALUATOR = ROOT / "tasks" / "task-02" / "evaluator" / "evaluate_2.py" +K = tc.set_backend("jax") +tc.set_dtype("complex64") + + +def load(path: Path, name: str): + spec = importlib.util.spec_from_file_location(name, path) + if spec is None or spec.loader is None: + raise RuntimeError(path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def tree_error(a, b): + aa = K.tree_flatten(a)[0] + bb = K.tree_flatten(b)[0] + return max( + float(np.max(np.abs(K.numpy(x) - K.numpy(y)))) + for x, y in zip(aa, bb) + ) + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--steps", type=int, default=12) + parser.add_argument("--output", type=Path) + args = parser.parse_args() + reference = load(REFERENCE, "task02_reference_batched_purity_audit") + candidate = load(CANDIDATE, "task02_candidate_batched_purity_audit") + evaluator = load(EVALUATOR, "task02_evaluator_batched_purity_audit") + config = dict(evaluator.DEFAULT_CONFIG) + config["target_entropies"] = np.asarray( + config["target_entropies"], dtype=np.float32 + ) + params = reference.initial_parameters(config) + circuit = tc.Circuit(config["n_qubits"]) + for i in range(1, config["n_qubits"], 2): + circuit.x(i) + input_state = circuit.state() + target = K.convert_to_tensor(config["target_entropies"]) + href = reference.build_xxz_mvp(config) + hcand = candidate.build_xxz_mvp(config) + + def ref_loss(p): + return reference.observables(p, input_state, href, config, target) + + def cand_loss(p): + return candidate.observables(p, input_state, hcand, config, target) + + (ref_loss_value, ref_aux), ref_grad = K.value_and_grad( + ref_loss, has_aux=True + )(params) + (cand_loss_value, cand_aux), cand_grad = K.value_and_grad( + cand_loss, has_aux=True + )(params) + config["max_steps"] = args.steps + expected = reference.run_solution(config) + actual = candidate.run_solution(config) + history_errors = { + key: float( + np.max( + np.abs( + np.asarray(expected[key], dtype=float) + - np.asarray(actual[key], dtype=float) + ) + ) + ) + for key in sorted(expected) + } + report = { + "schema_version": 1, + "task_id": "02", + "steps": args.steps, + "loss_abs_error": float( + abs(K.numpy(ref_loss_value - cand_loss_value)) + ), + "aux_max_error": tree_error(ref_aux, cand_aux), + "gradient_max_error": tree_error(ref_grad, cand_grad), + "history_max_abs_errors": history_errors, + } + report["passed"] = ( + report["loss_abs_error"] <= 2e-6 + and report["aux_max_error"] <= 2e-6 + and report["gradient_max_error"] <= 1e-5 + and max(history_errors.values()) <= 2e-4 + ) + encoded = json.dumps(report, indent=2, sort_keys=True) + "\n" + if args.output: + args.output.write_text(encoded, encoding="utf-8") + print(encoded, end="") + raise SystemExit(0 if report["passed"] else 1) + + +if __name__ == "__main__": + main() diff --git a/optimized_solutions/challenge-02/research/check_training_scan.py b/optimized_solutions/challenge-02/research/check_training_scan.py new file mode 100644 index 0000000..5ff2509 --- /dev/null +++ b/optimized_solutions/challenge-02/research/check_training_scan.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +"""Compare Task 02 Python-dispatched and K.jaxy_scan training histories.""" + +from __future__ import annotations + +import argparse +import importlib.util +import json +from pathlib import Path + +import numpy as np + + +ROOT = Path(__file__).resolve().parents[2] +REFERENCE = ROOT / "references" / "task-02" / "solution_2.py" +CANDIDATE = ROOT / "src" / "solutions" / "task-02" / "solution_2.py" +EVALUATOR = ROOT / "tasks" / "task-02" / "evaluator" / "evaluate_2.py" + + +def load(path: Path, name: str): + spec = importlib.util.spec_from_file_location(name, path) + if spec is None or spec.loader is None: + raise RuntimeError(path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--steps", type=int, default=12) + parser.add_argument("--output", type=Path) + args = parser.parse_args() + reference = load(REFERENCE, "task02_reference_scan_audit") + candidate = load(CANDIDATE, "task02_candidate_scan_audit") + evaluator = load(EVALUATOR, "task02_evaluator_scan_audit") + config = dict(evaluator.DEFAULT_CONFIG) + config["target_entropies"] = np.asarray( + config["target_entropies"], dtype=np.float32 + ) + config["max_steps"] = args.steps + + expected = reference.run_solution(config) + actual = candidate.run_solution(config) + errors = { + key: float( + np.max( + np.abs( + np.asarray(expected[key], dtype=float) + - np.asarray(actual[key], dtype=float) + ) + ) + ) + for key in sorted(expected) + } + shapes_match = { + key: np.shape(expected[key]) == np.shape(actual[key]) + for key in sorted(expected) + } + report = { + "schema_version": 1, + "task_id": "02", + "steps": args.steps, + "max_abs_errors": errors, + "shapes_match": shapes_match, + "passed": all(shapes_match.values()) and max(errors.values()) <= 2e-4, + } + encoded = json.dumps(report, indent=2, sort_keys=True) + "\n" + if args.output: + args.output.write_text(encoded, encoding="utf-8") + print(encoded, end="") + raise SystemExit(0 if report["passed"] else 1) + + +if __name__ == "__main__": + main() diff --git a/optimized_solutions/challenge-02/research/figures/e01-gate-fusion.svg b/optimized_solutions/challenge-02/research/figures/e01-gate-fusion.svg new file mode 100644 index 0000000..cbfd6af --- /dev/null +++ b/optimized_solutions/challenge-02/research/figures/e01-gate-fusion.svg @@ -0,0 +1,1490 @@ + + + + + + + + image/svg+xml + + + Matplotlib v3.10.8, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/optimized_solutions/challenge-02/research/figures/e02-training-scan.svg b/optimized_solutions/challenge-02/research/figures/e02-training-scan.svg new file mode 100644 index 0000000..31f6fa1 --- /dev/null +++ b/optimized_solutions/challenge-02/research/figures/e02-training-scan.svg @@ -0,0 +1,1487 @@ + + + + + + + + image/svg+xml + + + Matplotlib v3.10.8, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/optimized_solutions/challenge-02/research/figures/e03-frobenius-purity.svg b/optimized_solutions/challenge-02/research/figures/e03-frobenius-purity.svg new file mode 100644 index 0000000..bba7075 --- /dev/null +++ b/optimized_solutions/challenge-02/research/figures/e03-frobenius-purity.svg @@ -0,0 +1,1508 @@ + + + + + + + + image/svg+xml + + + Matplotlib v3.10.8, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/optimized_solutions/challenge-02/research/figures/e04-sparse-xxz.svg b/optimized_solutions/challenge-02/research/figures/e04-sparse-xxz.svg new file mode 100644 index 0000000..ba53338 --- /dev/null +++ b/optimized_solutions/challenge-02/research/figures/e04-sparse-xxz.svg @@ -0,0 +1,1521 @@ + + + + + + + + image/svg+xml + + + Matplotlib v3.10.8, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/optimized_solutions/challenge-02/research/figures/e05-packed-params.svg b/optimized_solutions/challenge-02/research/figures/e05-packed-params.svg new file mode 100644 index 0000000..6c1147d --- /dev/null +++ b/optimized_solutions/challenge-02/research/figures/e05-packed-params.svg @@ -0,0 +1,1474 @@ + + + + + + + + image/svg+xml + + + Matplotlib v3.10.8, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/optimized_solutions/challenge-02/research/figures/e06-entropy-vmap.svg b/optimized_solutions/challenge-02/research/figures/e06-entropy-vmap.svg new file mode 100644 index 0000000..2546747 --- /dev/null +++ b/optimized_solutions/challenge-02/research/figures/e06-entropy-vmap.svg @@ -0,0 +1,1470 @@ + + + + + + + + image/svg+xml + + + Matplotlib v3.10.8, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/optimized_solutions/challenge-02/research/figures/e07-batched-purity.svg b/optimized_solutions/challenge-02/research/figures/e07-batched-purity.svg new file mode 100644 index 0000000..29d04ad --- /dev/null +++ b/optimized_solutions/challenge-02/research/figures/e07-batched-purity.svg @@ -0,0 +1,1486 @@ + + + + + + + + image/svg+xml + + + Matplotlib v3.10.8, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/optimized_solutions/challenge-02/research/plot_factor_ablations.py b/optimized_solutions/challenge-02/research/plot_factor_ablations.py new file mode 100644 index 0000000..fca4f7f --- /dev/null +++ b/optimized_solutions/challenge-02/research/plot_factor_ablations.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +"""Render one paired-speedup SVG for every measured Task 02 factor.""" + +import json +from pathlib import Path + +import matplotlib + +matplotlib.use("Agg") +import matplotlib.pyplot as plt + + +ROOT = Path(__file__).resolve().parent +PROFILES = ROOT / "profiles" +FIGURES = ROOT / "figures" + +FACTORS = [ + ("e01-gate-fusion-paired.json", "e01-gate-fusion.svg", "Exact local gate fusion"), + ("e02-training-scan-paired.json", "e02-training-scan.svg", "Whole-training K.jaxy_scan"), + ("e03-purity-paired.json", "e03-frobenius-purity.svg", "Exact Frobenius purity"), + ("e04-sparse-xxz-paired.json", "e04-sparse-xxz.svg", "TensorCircuit sparse XXZ"), + ("e05-packed-params-paired.json", "e05-packed-params.svg", "Single-leaf parameter packing"), + ("e06-entropy-vmap-paired.json", "e06-entropy-vmap.svg", "Checkpoint entropy K.vmap"), + ("e07-batched-purity-paired.json", "e07-batched-purity.svg", "K.vmap + exact purity"), +] + + +def render_factor(profile_name, output_name, title): + data = json.loads((PROFILES / profile_name).read_text()) + ratios = [pair["speedup"] for pair in data["pairs"]] + mean = data["mean_paired_speedup"] + low, high = data["paired_speedup_95pct_t_ci"] + decision = data["decision"] + color = "#2E7D32" if decision == "keep" else "#B26A00" + if decision == "discard": + color = "#B3261E" + + fig, ax = plt.subplots(figsize=(7.2, 4.3)) + ax.axhline(1.0, color="#303030", linewidth=1.0) + ax.scatter(range(1, 7), ratios, color=color, s=42, zorder=3) + ax.errorbar( + 7, + mean, + yerr=[[mean - low], [high - mean]], + fmt="D", + color=color, + capsize=6, + markersize=7, + linewidth=2, + ) + span = max(max(ratios + [high, 1.0]) - min(ratios + [low, 1.0]), 0.08) + ax.set_ylim( + min(ratios + [low, 1.0]) - 0.16 * span, + max(ratios + [high, 1.0]) + 0.22 * span, + ) + ax.set_xticks(range(1, 8), ["1", "2", "3", "4", "5", "6", "mean"]) + ax.set_xlabel("Alternating matched pair") + ax.set_ylabel("Speedup (parent runtime / factor runtime)") + fig.suptitle(title, y=0.96, fontsize=13) + ax.grid(axis="y", color="#D0D0D0", linewidth=0.6) + ax.text( + 0.02, + 0.94, + f"mean {mean:.4f}× · 95% t-CI [{low:.4f}, {high:.4f}] · {decision}", + transform=ax.transAxes, + ha="left", + va="top", + fontsize=9, + ) + ax.text(6.85, 1.0, "no change", ha="right", va="bottom", fontsize=8) + fig.subplots_adjust(left=0.14, right=0.98, bottom=0.16, top=0.82) + fig.savefig( + FIGURES / output_name, + bbox_inches="tight", + metadata={"Date": None}, + ) + plt.close(fig) + + +def main(): + FIGURES.mkdir(parents=True, exist_ok=True) + plt.rcParams["svg.hashsalt"] = "task-02-factor-ablations" + plt.rcParams["font.family"] = "DejaVu Sans" + for args in FACTORS: + render_factor(*args) + + +if __name__ == "__main__": + main() diff --git a/optimized_solutions/challenge-02/research/profile_reference.py b/optimized_solutions/challenge-02/research/profile_reference.py new file mode 100644 index 0000000..cd5478e --- /dev/null +++ b/optimized_solutions/challenge-02/research/profile_reference.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python3 +"""Profile the immutable Task 02 expert without changing benchmark code.""" + +from __future__ import annotations + +import argparse +import hashlib +import importlib.util +import json +import statistics +import time +from pathlib import Path + +import jax +import numpy as np +import optax +import tensorcircuit as tc + + +ROOT = Path(__file__).resolve().parents[2] +REFERENCE = ROOT / "references" / "task-02" / "solution_2.py" +EVALUATOR = ROOT / "tasks" / "task-02" / "evaluator" / "evaluate_2.py" + + +def load_module(path: Path, name: str): + spec = importlib.util.spec_from_file_location(name, path) + if spec is None or spec.loader is None: + raise RuntimeError(f"cannot load {path}") + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def sha256(path: Path) -> str: + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def sync(value): + return jax.block_until_ready(value) + + +def timed_calls(fn, args, repeat: int): + values = [] + for _ in range(repeat): + start = time.perf_counter() + sync(fn(*args)) + values.append(time.perf_counter() - start) + return { + "values_sec": values, + "mean_sec": statistics.mean(values), + "median_sec": statistics.median(values), + } + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--repeat", type=int, default=12) + parser.add_argument("--output", type=Path) + args = parser.parse_args() + + expert = load_module(REFERENCE, "task02_reference_profile") + evaluator = load_module(EVALUATOR, "task02_evaluator_profile") + config = dict(evaluator.DEFAULT_CONFIG) + config["target_entropies"] = np.asarray( + evaluator.DEFAULT_CONFIG["target_entropies"], dtype=np.float32 + ) + + K = tc.set_backend("jax") + tc.set_dtype("complex64") + params = expert.initial_parameters(config) + circuit = tc.Circuit(config["n_qubits"]) + for i in range(1, config["n_qubits"], 2): + circuit.x(i) + input_state = circuit.state() + hamiltonian_mvp = expert.build_xxz_mvp(config) + target = K.convert_to_tensor(config["target_entropies"]) + optimizer = optax.adam(config["learning_rate"]) + opt_state = optimizer.init(params) + + def loss_fn(p): + return expert.observables( + p, input_state, hamiltonian_mvp, config, target + ) + + def train_step(p, state): + (loss, aux), grads = K.value_and_grad(loss_fn, has_aux=True)(p) + updates, state = optimizer.update(grads, state, p) + p = optax.apply_updates(p, updates) + return p, state, loss, aux + + def trajectory(p): + return expert.block_states(p, input_state, config) + + trajectory_jit = K.jit(trajectory) + loss_jit = K.jit(loss_fn) + step_jit = K.jit(train_step) + + profile = {} + for name, fn, fn_args in ( + ("trajectory", trajectory_jit, (params,)), + ("loss", loss_jit, (params,)), + ("train_step", step_jit, (params, opt_state)), + ): + start = time.perf_counter() + lowered = fn.lower(*fn_args) + lower_sec = time.perf_counter() - start + stablehlo = str(lowered.compiler_ir(dialect="stablehlo")) + start = time.perf_counter() + compiled = lowered.compile() + compile_sec = time.perf_counter() - start + start = time.perf_counter() + sync(compiled(*fn_args)) + cold_execute_sec = time.perf_counter() - start + profile[name] = { + "lower_sec": lower_sec, + "compile_sec": compile_sec, + "cold_execute_sec": cold_execute_sec, + "stablehlo_lines": len(stablehlo.splitlines()), + "steady": timed_calls(compiled, fn_args, args.repeat), + } + + final_state, _ = trajectory_jit(params) + sync(final_state) + energy_jit = K.jit(lambda s: expert.xxz_energy(s, hamiltonian_mvp)) + entropy_jit = K.jit(lambda s: expert.renyi2_entropy(s, config)) + for name, fn in (("energy", energy_jit), ("one_entropy", entropy_jit)): + lowered = fn.lower(final_state) + stablehlo = str(lowered.compiler_ir(dialect="stablehlo")) + start = time.perf_counter() + compiled = lowered.compile() + compile_sec = time.perf_counter() - start + profile[name] = { + "compile_sec": compile_sec, + "stablehlo_lines": len(stablehlo.splitlines()), + "steady": timed_calls(compiled, (final_state,), args.repeat), + } + + report = { + "schema_version": 1, + "task_id": "02", + "reference_sha256": sha256(REFERENCE), + "evaluator_sha256": sha256(EVALUATOR), + "jax": jax.__version__, + "tensorcircuit": tc.__version__, + "repeat": args.repeat, + "profile": profile, + "projected_500_train_steps_sec": ( + profile["train_step"]["steady"]["mean_sec"] * config["max_steps"] + ), + } + encoded = json.dumps(report, indent=2, sort_keys=True) + "\n" + if args.output: + args.output.write_text(encoded, encoding="utf-8") + print(encoded, end="") + + +if __name__ == "__main__": + main() diff --git a/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-equivalence.json new file mode 100644 index 0000000..2b7ddee --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-equivalence.json @@ -0,0 +1,13 @@ +{ + "aux_max_error": 2.384185791015625e-07, + "entropy_max_error": 0.0, + "gradient_max_error": 7.450580596923828e-08, + "loss_abs_error": 2.384185791015625e-07, + "max_gate_matrix_error": 1.3328003944934608e-07, + "one_update_parameter_max_error": 0.0003634784370660782, + "passed": true, + "post_update_aux_max_error": 5.364418029785156e-07, + "schema_version": 1, + "state_max_error": 3.071953074140765e-07, + "task_id": "02" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-paired.json b/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-paired.json new file mode 100644 index 0000000..db6d2ab --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-paired.json @@ -0,0 +1,31 @@ +{ + "schema_version": 1, + "task_id": "02", + "factor": "exact_local_gate_fusion", + "parent": "immutable_reference", + "candidate_sha256": "76917fc2292984b0102dda14ceb3b873f4ca55779554d29f2fa887ffd2f3f214", + "raw_report_sha256": "1804ebe44515690e1985411b16a51153aa6ddb88ec8a6c964d4d90fe0c365ce9", + "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", + "cpus": 6, + "memory": "7g", + "passing_cells": 12, + "pairs": [ + {"pair": 1, "order": "reference->candidate", "reference_sec": 4.675749, "candidate_sec": 4.718604, "speedup": 0.9909178646904889}, + {"pair": 2, "order": "candidate->reference", "reference_sec": 4.589206, "candidate_sec": 4.696532, "speedup": 0.9771478188586812}, + {"pair": 3, "order": "reference->candidate", "reference_sec": 4.706527, "candidate_sec": 4.962863, "speedup": 0.948349168614971}, + {"pair": 4, "order": "candidate->reference", "reference_sec": 4.57895, "candidate_sec": 4.807351, "speedup": 0.9524892191146435}, + {"pair": 5, "order": "reference->candidate", "reference_sec": 4.663297, "candidate_sec": 4.922267, "speedup": 0.9473880632643455}, + {"pair": 6, "order": "candidate->reference", "reference_sec": 4.741629, "candidate_sec": 4.844332, "speedup": 0.9787993473609984} + ], + "reference_mean_sec": 4.659226333333333, + "reference_median_sec": 4.669523, + "reference_stderr_sec": 0.026245163462584452, + "candidate_mean_sec": 4.825324833333333, + "candidate_median_sec": 4.825841499999999, + "candidate_stderr_sec": 0.043579732377499014, + "mean_paired_speedup": 0.9658485803173548, + "paired_speedup_stderr": 0.007636222471772435, + "paired_speedup_95pct_t_ci": [0.9462190455385387, 0.9854781150961708], + "candidate_wins": 0, + "decision": "discard" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e02-training-scan-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e02-training-scan-equivalence.json new file mode 100644 index 0000000..4b0e6e9 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e02-training-scan-equivalence.json @@ -0,0 +1,18 @@ +{ + "max_abs_errors": { + "energy_density_history": 0.0, + "entropy_history": 0.0, + "entropy_mse_history": 0.0, + "loss_history": 0.0 + }, + "passed": true, + "schema_version": 1, + "shapes_match": { + "energy_density_history": true, + "entropy_history": true, + "entropy_mse_history": true, + "loss_history": true + }, + "steps": 12, + "task_id": "02" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e02-training-scan-paired.json b/optimized_solutions/challenge-02/research/profiles/e02-training-scan-paired.json new file mode 100644 index 0000000..16e4664 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e02-training-scan-paired.json @@ -0,0 +1,70 @@ +{ + "schema_version": 1, + "task_id": "02", + "factor": "whole_training_k_jaxy_scan", + "parent": "immutable_reference", + "candidate_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", + "raw_report_sha256": "549e267378bc1eca2ea2b839810af4c46780ac8bdc7800eacdfc15385bc1e33b", + "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", + "cpus": 6, + "memory": "7g", + "passing_cells": 12, + "pairs": [ + { + "pair": 1, + "order": "reference->candidate", + "reference_sec": 4.64709, + "candidate_sec": 4.622549, + "speedup": 1.0053089756322757 + }, + { + "pair": 2, + "order": "candidate->reference", + "reference_sec": 4.725854, + "candidate_sec": 4.547981, + "speedup": 1.039110321700992 + }, + { + "pair": 3, + "order": "reference->candidate", + "reference_sec": 4.690144, + "candidate_sec": 4.655539, + "speedup": 1.0074330813252772 + }, + { + "pair": 4, + "order": "candidate->reference", + "reference_sec": 4.723182, + "candidate_sec": 4.531975, + "speedup": 1.042190656391529 + }, + { + "pair": 5, + "order": "reference->candidate", + "reference_sec": 4.808917, + "candidate_sec": 4.522497, + "speedup": 1.0633322697615941 + }, + { + "pair": 6, + "order": "candidate->reference", + "reference_sec": 4.750113, + "candidate_sec": 4.497762, + "speedup": 1.0561059033359257 + } + ], + "reference_mean_sec": 4.724216666666667, + "reference_median_sec": 4.724518, + "reference_stderr_sec": 0.022329343375428128, + "candidate_mean_sec": 4.5630505, + "candidate_median_sec": 4.539978, + "candidate_stderr_sec": 0.025294363838280938, + "mean_paired_speedup": 1.0355802013579323, + "paired_speedup_stderr": 0.009926813991785015, + "paired_speedup_95pct_t_ci": [ + 1.0100625136249093, + 1.0610978890909553 + ], + "candidate_wins": 6, + "decision": "keep" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e03-purity-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e03-purity-equivalence.json new file mode 100644 index 0000000..4cdb3bd --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e03-purity-equivalence.json @@ -0,0 +1,15 @@ +{ + "aux_max_error": 2.9803231882397085e-07, + "gradient_max_error": 1.6996636986732483e-08, + "history_max_abs_errors": { + "energy_density_history": 1.2516975402832031e-06, + "entropy_history": 8.568167686462402e-07, + "entropy_mse_history": 6.258487701416016e-07, + "loss_history": 1.1920928955078125e-06 + }, + "loss_abs_error": 0.0, + "passed": true, + "schema_version": 1, + "steps": 12, + "task_id": "02" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e03-purity-paired.json b/optimized_solutions/challenge-02/research/profiles/e03-purity-paired.json new file mode 100644 index 0000000..3fa73d8 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e03-purity-paired.json @@ -0,0 +1,33 @@ +{ + "schema_version": 1, + "task_id": "02", + "factor": "exact_frobenius_purity", + "parent_commit": "edf1e91", + "parent_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", + "candidate_sha256": "ab560235d23e2dcd5256467f1dba03bb4eee7d675250ccf9054c3d8a670c508e", + "raw_report_sha256": "cccabf99871f8fe7d62ac42fdedd6d77394157fdd41a490ff42f324104565184", + "role_note": "The runner labels the new registered optimized source as reference and the explicit accepted-parent source as candidate. Factor speedup below is parent_sec/factor_sec.", + "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", + "cpus": 6, + "memory": "7g", + "passing_cells": 12, + "pairs": [ + {"pair": 1, "order": "factor->parent", "parent_sec": 4.512375, "factor_sec": 4.422352, "speedup": 1.0203563624062488}, + {"pair": 2, "order": "parent->factor", "parent_sec": 4.525156, "factor_sec": 4.983842, "speedup": 0.9079653809249972}, + {"pair": 3, "order": "factor->parent", "parent_sec": 4.536363, "factor_sec": 4.385974, "speedup": 1.0342886209539772}, + {"pair": 4, "order": "parent->factor", "parent_sec": 4.623152, "factor_sec": 4.35917, "speedup": 1.0605578584914102}, + {"pair": 5, "order": "factor->parent", "parent_sec": 4.600339, "factor_sec": 4.314358, "speedup": 1.066285876137307}, + {"pair": 6, "order": "parent->factor", "parent_sec": 4.748949, "factor_sec": 4.486073, "speedup": 1.0585982439429762} + ], + "parent_mean_sec": 4.591055666666667, + "parent_median_sec": 4.568351, + "parent_stderr_sec": 0.0363186640555208, + "factor_mean_sec": 4.4919615, + "factor_median_sec": 4.4041630000000005, + "factor_stderr_sec": 0.10119889970473989, + "mean_paired_speedup": 1.0246753904761527, + "paired_speedup_stderr": 0.024428152166625212, + "paired_speedup_95pct_t_ci": [0.9618808262384664, 1.0874699547138391], + "factor_wins": 5, + "decision": "discard_inconclusive" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-equivalence.json new file mode 100644 index 0000000..fc08935 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-equivalence.json @@ -0,0 +1,16 @@ +{ + "aux_max_error": 0.0, + "gradient_max_error": 3.91155481338501e-08, + "hamiltonian_action_max_error": 1.665520539972931e-05, + "history_max_abs_errors": { + "energy_density_history": 1.1920928955078125e-06, + "entropy_history": 5.662441253662109e-07, + "entropy_mse_history": 5.662441253662109e-07, + "loss_history": 1.1920928955078125e-06 + }, + "loss_abs_error": 0.0, + "passed": true, + "schema_version": 1, + "steps": 12, + "task_id": "02" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-paired.json b/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-paired.json new file mode 100644 index 0000000..f09ffc9 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-paired.json @@ -0,0 +1,33 @@ +{ + "schema_version": 1, + "task_id": "02", + "factor": "tensorcircuit_sparse_xxz", + "parent_commit": "edf1e91", + "parent_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", + "candidate_sha256": "c5997e6147212271ec45321880a14d696849a6436fb99f16a02b72fc42992942", + "raw_report_sha256": "8bfba5d0d90cde8ddb571e38d975044e5ea50001e9581a1a617a13fe9bca6c12", + "role_note": "The runner labels the new registered optimized source as reference and the explicit accepted-parent source as candidate. Factor speedup below is parent_sec/factor_sec.", + "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", + "cpus": 6, + "memory": "7g", + "passing_cells": 12, + "pairs": [ + {"pair": 1, "order": "factor->parent", "parent_sec": 4.298455, "factor_sec": 4.516255, "speedup": 0.9517742022981429}, + {"pair": 2, "order": "parent->factor", "parent_sec": 4.283501, "factor_sec": 4.439776, "speedup": 0.9648011521301976}, + {"pair": 3, "order": "factor->parent", "parent_sec": 4.380654, "factor_sec": 4.363093, "speedup": 1.004024897016864}, + {"pair": 4, "order": "parent->factor", "parent_sec": 4.221151, "factor_sec": 4.393876, "speedup": 0.9606896052596842}, + {"pair": 5, "order": "factor->parent", "parent_sec": 4.206659, "factor_sec": 4.410758, "speedup": 0.9537270011186285}, + {"pair": 6, "order": "parent->factor", "parent_sec": 4.389762, "factor_sec": 4.379807, "speedup": 1.002272931204503} + ], + "parent_mean_sec": 4.296697, + "parent_median_sec": 4.290978, + "parent_stderr_sec": 0.03146486750541519, + "factor_mean_sec": 4.417260833333334, + "factor_median_sec": 4.402317, + "factor_stderr_sec": 0.022533574087594568, + "mean_paired_speedup": 0.97288163150467, + "paired_speedup_stderr": 0.00976407457404015, + "paired_speedup_95pct_t_ci": [0.947782278762844, 0.997980984246496], + "factor_wins": 2, + "decision": "discard" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e05-packed-params-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e05-packed-params-equivalence.json new file mode 100644 index 0000000..a55b577 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e05-packed-params-equivalence.json @@ -0,0 +1,16 @@ +{ + "aux_max_error": 0.0, + "gradient_max_error": 0.0, + "history_max_abs_errors": { + "energy_density_history": 0.0, + "entropy_history": 0.0, + "entropy_mse_history": 0.0, + "loss_history": 0.0 + }, + "loss_abs_error": 0.0, + "parameter_max_error": 0.0, + "passed": true, + "schema_version": 1, + "steps": 12, + "task_id": "02" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e05-packed-params-paired.json b/optimized_solutions/challenge-02/research/profiles/e05-packed-params-paired.json new file mode 100644 index 0000000..17ff005 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e05-packed-params-paired.json @@ -0,0 +1,33 @@ +{ + "schema_version": 1, + "task_id": "02", + "factor": "single_leaf_parameter_packing", + "parent_commit": "edf1e91", + "parent_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", + "candidate_sha256": "895ede0c511e60221400a85066b036ab57fce683df614a2cabb389e928826b70", + "raw_report_sha256": "b24d2fbeb2094e23f2353b94a71896dc6b1f506bf6eea600b14536aa7d7617fb", + "role_note": "The runner labels the new registered optimized source as reference and the explicit accepted-parent source as candidate. Factor speedup below is parent_sec/factor_sec.", + "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", + "cpus": 6, + "memory": "7g", + "passing_cells": 12, + "pairs": [ + {"pair": 1, "order": "factor->parent", "parent_sec": 4.443677, "factor_sec": 10.455023, "speedup": 0.4250279506797833}, + {"pair": 2, "order": "parent->factor", "parent_sec": 4.411176, "factor_sec": 10.728046, "speedup": 0.41118168210688133}, + {"pair": 3, "order": "factor->parent", "parent_sec": 4.529836, "factor_sec": 10.895188, "speedup": 0.4157648312264094}, + {"pair": 4, "order": "parent->factor", "parent_sec": 4.512273, "factor_sec": 10.68515, "speedup": 0.4222938377093443}, + {"pair": 5, "order": "factor->parent", "parent_sec": 4.886009, "factor_sec": 11.055362, "speedup": 0.4419583004156715}, + {"pair": 6, "order": "parent->factor", "parent_sec": 4.77443, "factor_sec": 10.56624, "speedup": 0.4518570465936794} + ], + "parent_mean_sec": 4.5929001666666665, + "parent_median_sec": 4.5210545, + "parent_stderr_sec": 0.07845060524747038, + "factor_mean_sec": 10.730834833333333, + "factor_median_sec": 10.706598, + "factor_stderr_sec": 0.08899220067939155, + "mean_paired_speedup": 0.42801394145529487, + "paired_speedup_stderr": 0.006423758488100811, + "paired_speedup_95pct_t_ci": [0.4115011445692684, 0.44452673834132134], + "factor_wins": 0, + "decision": "discard" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-equivalence.json new file mode 100644 index 0000000..18c9871 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-equivalence.json @@ -0,0 +1,15 @@ +{ + "aux_max_error": 0.0, + "gradient_max_error": 1.862645149230957e-08, + "history_max_abs_errors": { + "energy_density_history": 7.152557373046875e-07, + "entropy_history": 6.183981895446777e-07, + "entropy_mse_history": 4.172325134277344e-07, + "loss_history": 8.344650268554688e-07 + }, + "loss_abs_error": 0.0, + "passed": true, + "schema_version": 1, + "steps": 12, + "task_id": "02" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-paired.json b/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-paired.json new file mode 100644 index 0000000..1f12a21 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-paired.json @@ -0,0 +1,33 @@ +{ + "schema_version": 1, + "task_id": "02", + "factor": "checkpoint_entropy_k_vmap", + "parent_commit": "edf1e91", + "parent_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", + "candidate_sha256": "c9c7840740152f03f23ddbc50379098847508007288da397ecf592952204cdb2", + "raw_report_sha256": "a43cd8242d76503057c88e4de2ee7b702965ecf89c41643b21ba4d8664d13a97", + "role_note": "The runner labels the new registered optimized source as reference and the explicit accepted-parent source as candidate. Factor speedup below is parent_sec/factor_sec.", + "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", + "cpus": 6, + "memory": "7g", + "passing_cells": 12, + "pairs": [ + {"pair": 1, "order": "factor->parent", "parent_sec": 4.667179, "factor_sec": 4.432862, "speedup": 1.0528590784012677}, + {"pair": 2, "order": "parent->factor", "parent_sec": 4.546249, "factor_sec": 4.078218, "speedup": 1.1147636050843777}, + {"pair": 3, "order": "factor->parent", "parent_sec": 4.735712, "factor_sec": 4.389429, "speedup": 1.0788902155610673}, + {"pair": 4, "order": "parent->factor", "parent_sec": 4.890732, "factor_sec": 4.788164, "speedup": 1.021421154329718}, + {"pair": 5, "order": "factor->parent", "parent_sec": 5.01748, "factor_sec": 5.302995, "speedup": 0.9461596701486612}, + {"pair": 6, "order": "parent->factor", "parent_sec": 4.738252, "factor_sec": 4.442364, "speedup": 1.0666059782584227} + ], + "parent_mean_sec": 4.765934, + "parent_median_sec": 4.736982, + "parent_stderr_sec": 0.06795676139477703, + "factor_mean_sec": 4.572338666666667, + "factor_median_sec": 4.437613000000001, + "factor_stderr_sec": 0.17266514663314209, + "mean_paired_speedup": 1.0467832836305857, + "paired_speedup_stderr": 0.023699776989237024, + "paired_speedup_95pct_t_ci": [0.9858610673934217, 1.1077054998677496], + "factor_wins": 5, + "decision": "discard_inconclusive" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-equivalence.json new file mode 100644 index 0000000..9db78c7 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-equivalence.json @@ -0,0 +1,15 @@ +{ + "aux_max_error": 2.9803231882397085e-07, + "gradient_max_error": 1.210719347000122e-08, + "history_max_abs_errors": { + "energy_density_history": 1.0728836059570312e-06, + "entropy_history": 8.717179298400879e-07, + "entropy_mse_history": 5.662441253662109e-07, + "loss_history": 1.0728836059570312e-06 + }, + "loss_abs_error": 0.0, + "passed": true, + "schema_version": 1, + "steps": 12, + "task_id": "02" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-paired.json b/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-paired.json new file mode 100644 index 0000000..f7bf00e --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-paired.json @@ -0,0 +1,71 @@ +{ + "schema_version": 1, + "task_id": "02", + "factor": "checkpoint_vmap_plus_frobenius_purity", + "parent": "whole_training_k_jaxy_scan", + "candidate_sha256": "181c0459c8194aa259be813e23896d3c70691adf5999a26353fe57cab14d3f3d", + "raw_report_sha256": "6dd10f3c24054668734022000058391c192c87f0554d404a6d3b7d61593ee07e", + "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", + "cpus": 6, + "memory": "7g", + "passing_cells": 12, + "role_note": "The runner's registered optimized role is this factor and its explicit candidate role is the parent; ratios below are normalized as parent/factor.", + "pairs": [ + { + "pair": 1, + "order": "factor->parent", + "parent_sec": 4.455414, + "factor_sec": 4.334005, + "speedup": 1.0280131195049382 + }, + { + "pair": 2, + "order": "parent->factor", + "parent_sec": 4.565881, + "factor_sec": 4.164098, + "speedup": 1.0964874025539264 + }, + { + "pair": 3, + "order": "factor->parent", + "parent_sec": 4.534834, + "factor_sec": 4.265577, + "speedup": 1.063123230456278 + }, + { + "pair": 4, + "order": "parent->factor", + "parent_sec": 4.502713, + "factor_sec": 4.151774, + "speedup": 1.0845274815054964 + }, + { + "pair": 5, + "order": "factor->parent", + "parent_sec": 4.58468, + "factor_sec": 4.133233, + "speedup": 1.1092236997043234 + }, + { + "pair": 6, + "order": "parent->factor", + "parent_sec": 4.543243, + "factor_sec": 4.264484, + "speedup": 1.0653675802277602 + } + ], + "parent_mean_sec": 4.5311275, + "parent_median_sec": 4.5390385, + "parent_stderr_sec": 0.01895267561893742, + "factor_mean_sec": 4.218861833333333, + "factor_median_sec": 4.214291, + "factor_stderr_sec": 0.03283990947959184, + "mean_paired_speedup": 1.0744570856587872, + "paired_speedup_stderr": 0.011780750629781522, + "paired_speedup_95pct_t_ci": [ + 1.0441737020681832, + 1.1047404692493912 + ], + "candidate_wins": 6, + "decision": "keep" +} diff --git a/optimized_solutions/challenge-02/research/profiles/e08-purestate-purity-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e08-purestate-purity-equivalence.json new file mode 100644 index 0000000..38f6375 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/e08-purestate-purity-equivalence.json @@ -0,0 +1,15 @@ +{ + "aux_max_error": 2.503933501429856e-06, + "gradient_max_error": 3.771856427192688e-08, + "history_max_abs_errors": { + "energy_density_history": 1.0728836059570312e-06, + "entropy_history": 5.348585546016693e-06, + "entropy_mse_history": 3.844499588012695e-06, + "loss_history": 1.7881393432617188e-06 + }, + "loss_abs_error": 5.960464477539062e-07, + "passed": false, + "schema_version": 1, + "steps": 12, + "task_id": "02" +} diff --git a/optimized_solutions/challenge-02/research/profiles/final-equivalence.json b/optimized_solutions/challenge-02/research/profiles/final-equivalence.json new file mode 100644 index 0000000..b07c834 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/final-equivalence.json @@ -0,0 +1,16 @@ +{ + "schema_version": 1, + "task_id": "02", + "candidate_sha256": "aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30", + "steps": 12, + "loss_abs_error": 0.0, + "aux_max_error": 2.9803231882397085e-07, + "gradient_max_error": 1.210719347000122e-08, + "history_max_abs_errors": { + "energy_density_history": 1.0728836059570312e-06, + "entropy_history": 8.717179298400879e-07, + "entropy_mse_history": 5.662441253662109e-07, + "loss_history": 1.0728836059570312e-06 + }, + "passed": true +} diff --git a/optimized_solutions/challenge-02/research/profiles/final-reference-paired.json b/optimized_solutions/challenge-02/research/profiles/final-reference-paired.json new file mode 100644 index 0000000..cd4761e --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/final-reference-paired.json @@ -0,0 +1,38 @@ +{ + "schema_version": 1, + "task_id": "02", + "candidate": "whole_training_scan_plus_batched_exact_purity", + "parent": "immutable_reference", + "candidate_sha256": "aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30", + "raw_report_sha256": "27ec959f8e23156a0c8f0b15bb0f122b86e3a32e1842764888ef90eb07a842dd", + "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", + "cpus": 6, + "memory": "7g", + "passing_cells": 12, + "pairs": [ + {"pair": 1, "order": "reference->candidate", "reference_sec": 4.865151, "candidate_sec": 3.981228, "speedup": 1.2220227025430344}, + {"pair": 2, "order": "candidate->reference", "reference_sec": 4.364947, "candidate_sec": 4.042312, "speedup": 1.0798144725097913}, + {"pair": 3, "order": "reference->candidate", "reference_sec": 4.411195, "candidate_sec": 4.134876, "speedup": 1.0668264296196548}, + {"pair": 4, "order": "candidate->reference", "reference_sec": 4.457106, "candidate_sec": 4.007787, "speedup": 1.1121114969433255}, + {"pair": 5, "order": "reference->candidate", "reference_sec": 4.432053, "candidate_sec": 4.030015, "speedup": 1.0997609190040236}, + {"pair": 6, "order": "candidate->reference", "reference_sec": 4.442327, "candidate_sec": 3.990016, "speedup": 1.1133606983029642} + ], + "reference_mean_sec": 4.495463166666666, + "reference_median_sec": 4.437189999999999, + "reference_stderr_sec": 0.07508223524217374, + "candidate_mean_sec": 4.031039, + "candidate_median_sec": 4.018901, + "candidate_stderr_sec": 0.022814417538039422, + "mean_paired_speedup": 1.115649453153799, + "paired_speedup_stderr": 0.02254869005858174, + "paired_speedup_95pct_t_ci": [1.0576862000497536, 1.1736127062578445], + "paired_improvement_pct_mean": 10.192991792502323, + "candidate_wins": 6, + "first_five": { + "reference_mean_sec": 4.5060904, + "candidate_mean_sec": 4.0392436, + "mean_paired_speedup": 1.116107204123966, + "pooled_improvement_pct": 10.36035140351379 + }, + "decision": "keep" +} diff --git a/optimized_solutions/challenge-02/research/profiles/reference-profile.json b/optimized_solutions/challenge-02/research/profiles/reference-profile.json new file mode 100644 index 0000000..1aa4d21 --- /dev/null +++ b/optimized_solutions/challenge-02/research/profiles/reference-profile.json @@ -0,0 +1,128 @@ +{ + "evaluator_sha256": "0d9360d4812d033d364253dd478444f68918f1b05f04146eddcb846a3dca3a1e", + "jax": "0.10.0", + "profile": { + "energy": { + "compile_sec": 0.1393681839981582, + "stablehlo_lines": 353, + "steady": { + "mean_sec": 0.00017614391739092147, + "median_sec": 0.00015538899606326595, + "values_sec": [ + 0.0003872419911203906, + 0.00015651399735361338, + 0.00015080500452313572, + 0.0001725570036796853, + 0.00015201300266198814, + 0.0001593469933141023, + 0.0001772660034475848, + 0.00015963900659698993, + 0.00015126400103326887, + 0.0001425119990017265, + 0.00015426399477291852, + 0.0001503040111856535 + ] + } + }, + "loss": { + "cold_execute_sec": 0.0012416509998729452, + "compile_sec": 0.6459185569983674, + "lower_sec": 0.14026911799737718, + "stablehlo_lines": 5622, + "steady": { + "mean_sec": 0.0009508372483348163, + "median_sec": 0.0009437499975319952, + "values_sec": [ + 0.0009708770085126162, + 0.0009170800040010363, + 0.0009110800019698218, + 0.0009102469921344891, + 0.0008927449962357059, + 0.0009665859979577363, + 0.0009920039883581921, + 0.0010103810054715723, + 0.0009297069918829948, + 0.0010416750010335818, + 0.0009098719892790541, + 0.0009577930031809956 + ] + } + }, + "one_entropy": { + "compile_sec": 0.04879616999824066, + "stablehlo_lines": 54, + "steady": { + "mean_sec": 0.0001318761678703595, + "median_sec": 0.00012436549877747893, + "values_sec": [ + 0.0002572310040704906, + 0.00012951099779456854, + 0.00012413600052241236, + 0.0001245949970325455, + 0.00012934500409755856, + 0.00012742800754494965, + 0.00012596900342032313, + 0.000120801996672526, + 0.00011084300058428198, + 0.00011084300058428198, + 0.00011113499931525439, + 0.00011067600280512124 + ] + } + }, + "train_step": { + "cold_execute_sec": 0.0039121360023273155, + "compile_sec": 1.9297688599908724, + "lower_sec": 0.8031583569973009, + "stablehlo_lines": 15479, + "steady": { + "mean_sec": 0.002643305668849886, + "median_sec": 0.0026212515076622367, + "values_sec": [ + 0.00272540700098034, + 0.0028315410017967224, + 0.002842875008354895, + 0.002633648007758893, + 0.0026088550075655803, + 0.0025580170040484518, + 0.0025170549924951047, + 0.0025212639884557575, + 0.002743407996604219, + 0.002673277005669661, + 0.0025122210063273087, + 0.0025521000061417 + ] + } + }, + "trajectory": { + "cold_execute_sec": 0.0015485950134461746, + "compile_sec": 0.5833363940037088, + "lower_sec": 0.10015145600482356, + "stablehlo_lines": 5262, + "steady": { + "mean_sec": 0.0008888770001552378, + "median_sec": 0.0008625339978607371, + "values_sec": [ + 0.000961875994107686, + 0.0010673859942471609, + 0.0009131219994742423, + 0.0008702440100023523, + 0.0008600750006735325, + 0.0008363239903701469, + 0.000827490002848208, + 0.0008424910047324374, + 0.0009439580026082695, + 0.0008649929950479418, + 0.0008486169972456992, + 0.0008299480105051771 + ] + } + } + }, + "projected_500_train_steps_sec": 1.321652834424943, + "reference_sha256": "cd5776dfb223924edd83795bd8222032351008a584b55d747110521c709dcdd3", + "repeat": 12, + "schema_version": 1, + "task_id": "02", + "tensorcircuit": "1.8.0.dev20260726" +} diff --git a/optimized_solutions/challenge-02/solution_2_training_scan_batched_purity.py b/optimized_solutions/challenge-02/solution_2_training_scan_batched_purity.py new file mode 100644 index 0000000..ccf7a8b --- /dev/null +++ b/optimized_solutions/challenge-02/solution_2_training_scan_batched_purity.py @@ -0,0 +1,168 @@ +""" +Task Suite Problem 2: entanglement-profile-constrained VQE. + +The ansatz is scanned as three even+odd brickwork blocks. Each block output is +materialized so the half-chain Renyi-2 profile is part of the differentiable +loss. The solution returns only NumPy values consumed by evaluate_2.py. +""" + +import numpy as np +import optax + +import tensorcircuit as tc + +K = tc.set_backend("jax") +tc.set_dtype("complex64") + + +def block_count(config): + return config["n_layers"] // 2 + + +def even_bonds(config): + return list(range(0, config["n_qubits"] - 1, 2)) + + +def odd_bonds(config): + return list(range(1, config["n_qubits"] - 1, 2)) + + +def initial_parameters(config): + rng = np.random.default_rng(2026) + n_repeats = block_count(config) + n_qubits = config["n_qubits"] + n_even = len(even_bonds(config)) + n_odd = len(odd_bonds(config)) + + def normal(shape): + return K.convert_to_tensor( + rng.normal(scale=0.02, size=shape).astype(np.float32) + ) + + return { + "even": { + "ry": normal((n_repeats, n_qubits)), + "rz": normal((n_repeats, n_qubits)), + "xx": normal((n_repeats, n_even)), + "yy": normal((n_repeats, n_even)), + "zz": normal((n_repeats, n_even)), + }, + "odd": { + "ry": normal((n_repeats, n_qubits)), + "rz": normal((n_repeats, n_qubits)), + "xx": normal((n_repeats, n_odd)), + "yy": normal((n_repeats, n_odd)), + "zz": normal((n_repeats, n_odd)), + }, + } + + +def apply_layer(circuit, layer_params, bonds, config): + for i in range(config["n_qubits"]): + circuit.ry(i, theta=layer_params["ry"][i]) + circuit.rz(i, theta=layer_params["rz"][i]) + + for bond_index, i in enumerate(bonds): + circuit.rxx(i, i + 1, theta=layer_params["xx"][bond_index]) + circuit.ryy(i, i + 1, theta=layer_params["yy"][bond_index]) + circuit.rzz(i, i + 1, theta=layer_params["zz"][bond_index]) + + +def renyi2_entropy(state, config): + traceout = list(range(config["subsystem_size"], config["n_qubits"])) + rho = tc.quantum.reduced_density_matrix(state, cut=traceout) + purity = K.real(K.sum(rho * K.conj(rho))) + return -K.real(K.log(purity)) + + +def block_states(params, input_state, config): + even = even_bonds(config) + odd = odd_bonds(config) + + def block_step(state, block_params): + circuit = tc.Circuit(config["n_qubits"], inputs=state) + apply_layer(circuit, block_params["even"], even, config) + apply_layer(circuit, block_params["odd"], odd, config) + state = circuit.state() + + return state, state + + final_state, states = K.jaxy_scan(block_step, input_state, params) + entropies = K.vmap(lambda state: renyi2_entropy(state, config))(states) + return final_state, entropies + + +def build_xxz_mvp(config): + structures = [] + weights = [] + + for i in range(config["n_qubits"] - 1): + for pauli, weight in ((1, 1.0), (2, 1.0), (3, config["zz_anisotropy"])): + term = [0] * config["n_qubits"] + term[i] = pauli + term[i + 1] = pauli + structures.append(term) + weights.append(weight) + + for i in range(config["n_qubits"]): + term = [0] * config["n_qubits"] + term[i] = 3 + structures.append(term) + weights.append(config["staggered_field"] * ((-1.0) ** i)) + + return tc.quantum.PauliStringSum2MVP(structures, weights) + + +def xxz_energy(state, hamiltonian_mvp): + h_state = hamiltonian_mvp(state) + return K.real(K.tensordot(K.conj(state), h_state, 1)) + + +def observables(params, input_state, hamiltonian_mvp, config, target_entropies): + final_state, entropies = block_states(params, input_state, config) + energy_density = xxz_energy(final_state, hamiltonian_mvp) / config["n_qubits"] + entropy_mse = K.mean((entropies - target_entropies) ** 2) + loss = energy_density + config["entropy_weight"] * entropy_mse + return loss, (energy_density, entropies, entropy_mse) + + +def run_solution(config): + params = initial_parameters(config) + circuit = tc.Circuit(config["n_qubits"]) + for i in range(1, config["n_qubits"], 2): + circuit.x(i) + input_state = circuit.state() + hamiltonian_mvp = build_xxz_mvp(config) + target_entropies = K.convert_to_tensor( + np.asarray(config["target_entropies"], dtype=np.float32) + ) + optimizer = optax.adam(config["learning_rate"]) + opt_state = optimizer.init(params) + + def loss_fn(p): + return observables(p, input_state, hamiltonian_mvp, config, target_entropies) + + def train_step(carry, _): + p, state = carry + (loss, aux), grads = K.value_and_grad(loss_fn, has_aux=True)(p) + updates, state = optimizer.update(grads, state, p) + p = optax.apply_updates(p, updates) + energy_density, entropies, entropy_mse = aux + return (p, state), (loss, energy_density, entropies, entropy_mse) + + def train(carry): + return K.jaxy_scan( + train_step, carry, K.arange(config["max_steps"]) + ) + + (_, _), history = K.jit(train)((params, opt_state)) + loss_history, energy_density_history, entropy_history, entropy_mse_history = ( + history + ) + + return { + "energy_density_history": K.numpy(energy_density_history), + "loss_history": K.numpy(loss_history), + "entropy_mse_history": K.numpy(entropy_mse_history), + "entropy_history": K.numpy(entropy_history), + } From 71aeee2afb77cef94c8fbc93333fb53c5069a758 Mon Sep 17 00:00:00 2001 From: qingyunqian Date: Thu, 30 Jul 2026 11:56:16 +0800 Subject: [PATCH 2/3] Simplify Task 02 optimization evidence --- optimized_solutions/challenge-02/README.md | 62 +- .../challenge-02/factor-ablation.svg | 44 + .../research/IMPLEMENTATION_COMPARISON.md | 231 --- .../challenge-02/research/INSIGHTS.md | 88 - .../challenge-02/research/LOG.md | 335 ---- .../challenge-02/research/SURVEY.md | 155 -- .../research/check_batched_purity.py | 113 -- .../research/check_training_scan.py | 76 - .../research/figures/e01-gate-fusion.svg | 1490 ---------------- .../research/figures/e02-training-scan.svg | 1487 ---------------- .../research/figures/e03-frobenius-purity.svg | 1508 ---------------- .../research/figures/e04-sparse-xxz.svg | 1521 ----------------- .../research/figures/e05-packed-params.svg | 1474 ---------------- .../research/figures/e06-entropy-vmap.svg | 1470 ---------------- .../research/figures/e07-batched-purity.svg | 1486 ---------------- .../research/plot_factor_ablations.py | 89 - .../research/profile_reference.py | 158 -- .../profiles/e01-gate-fusion-equivalence.json | 13 - .../profiles/e01-gate-fusion-paired.json | 31 - .../e02-training-scan-equivalence.json | 18 - .../profiles/e02-training-scan-paired.json | 70 - .../profiles/e03-purity-equivalence.json | 15 - .../research/profiles/e03-purity-paired.json | 33 - .../profiles/e04-sparse-xxz-equivalence.json | 16 - .../profiles/e04-sparse-xxz-paired.json | 33 - .../e05-packed-params-equivalence.json | 16 - .../profiles/e05-packed-params-paired.json | 33 - .../e06-entropy-vmap-equivalence.json | 15 - .../profiles/e06-entropy-vmap-paired.json | 33 - .../e07-batched-purity-equivalence.json | 15 - .../profiles/e07-batched-purity-paired.json | 71 - .../e08-purestate-purity-equivalence.json | 15 - .../research/profiles/final-equivalence.json | 16 - .../profiles/final-reference-paired.json | 38 - .../research/profiles/reference-profile.json | 128 -- 35 files changed, 91 insertions(+), 12305 deletions(-) create mode 100644 optimized_solutions/challenge-02/factor-ablation.svg delete mode 100644 optimized_solutions/challenge-02/research/IMPLEMENTATION_COMPARISON.md delete mode 100644 optimized_solutions/challenge-02/research/INSIGHTS.md delete mode 100644 optimized_solutions/challenge-02/research/LOG.md delete mode 100644 optimized_solutions/challenge-02/research/SURVEY.md delete mode 100644 optimized_solutions/challenge-02/research/check_batched_purity.py delete mode 100644 optimized_solutions/challenge-02/research/check_training_scan.py delete mode 100644 optimized_solutions/challenge-02/research/figures/e01-gate-fusion.svg delete mode 100644 optimized_solutions/challenge-02/research/figures/e02-training-scan.svg delete mode 100644 optimized_solutions/challenge-02/research/figures/e03-frobenius-purity.svg delete mode 100644 optimized_solutions/challenge-02/research/figures/e04-sparse-xxz.svg delete mode 100644 optimized_solutions/challenge-02/research/figures/e05-packed-params.svg delete mode 100644 optimized_solutions/challenge-02/research/figures/e06-entropy-vmap.svg delete mode 100644 optimized_solutions/challenge-02/research/figures/e07-batched-purity.svg delete mode 100644 optimized_solutions/challenge-02/research/plot_factor_ablations.py delete mode 100644 optimized_solutions/challenge-02/research/profile_reference.py delete mode 100644 optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-equivalence.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-paired.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e02-training-scan-equivalence.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e02-training-scan-paired.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e03-purity-equivalence.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e03-purity-paired.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-equivalence.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-paired.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e05-packed-params-equivalence.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e05-packed-params-paired.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-equivalence.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-paired.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e07-batched-purity-equivalence.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e07-batched-purity-paired.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/e08-purestate-purity-equivalence.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/final-equivalence.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/final-reference-paired.json delete mode 100644 optimized_solutions/challenge-02/research/profiles/reference-profile.json diff --git a/optimized_solutions/challenge-02/README.md b/optimized_solutions/challenge-02/README.md index d4bc682..f9c6c91 100644 --- a/optimized_solutions/challenge-02/README.md +++ b/optimized_solutions/challenge-02/README.md @@ -1,19 +1,51 @@ -# Challenge 02 optimized expert solution +# Challenge 02: stage the trajectory and batch purity -This directory packages the final reviewed Task 02 campaign from Benchmark -PR [#17](https://github.com/hmyuuu/OrbitBreakersExpertBenchmarks/pull/17), -with the final tree taken from Benchmark `main` at `7e2298b`. +**Take-home insight.** Keep the full optimization trajectory inside +TensorCircuit backend transforms: one `K.jaxy_scan` removes 500 host +dispatches, while `K.vmap` evaluates the three checkpoint purities together +and replaces dense `rho @ rho` with the exact Frobenius identity. These are +the only retained factors and give a **1.116x** end-to-end speedup. -- `solution_2_training_scan_batched_purity.py` is the optimized - TensorCircuit-NG variant. -- `research/IMPLEMENTATION_COMPARISON.md` is the final report. -- `research/profiles/`, `research/figures/`, and the plotting/equivalence - scripts preserve the factor-by-factor ablation evidence. +## Factor speedups -All six matched pairs passed. Mean runtime changed from `4.495463 s` to -`4.031039 s`; mean paired speedup was `1.115649x` with a 95% t-interval of -`[1.057686x, 1.173613x]`. +Each multiplier is the measured paired speedup relative to that factor's +direct parent, so retained rows are incremental rather than cumulative. -The canonical expert under `tasks/challenge-02/solution/` is intentionally -unchanged. Benchmark-harness reproduction commands in the research record -should be run in the Benchmark repository pinned above. +| ID | Factor | Speedup vs parent | Decision | +| --- | --- | ---: | --- | +| E01 | Exact local gate fusion | 0.966x | Discard | +| E02 | Whole-training `K.jaxy_scan` | **1.036x** | **Keep** | +| E03 | Frobenius purity alone | 1.025x | Discard (inconclusive) | +| E04 | TensorCircuit sparse XXZ | 0.973x | Discard | +| E05 | Single-leaf parameter packing | 0.428x | Discard | +| E06 | Checkpoint entropy `K.vmap` alone | 1.047x | Discard (inconclusive) | +| E07 | `K.vmap` plus exact Frobenius purity | **1.074x** | **Keep** | + +![Incremental factor speedups and final cumulative result](factor-ablation.svg) + +## What the factors mean + +- **E01 — local gate fusion:** reduce 243 gate applications to 105 exact + matrices, whose dynamic construction outweighed the smaller circuit. +- **E02 — training scan:** carry parameters and Optax state through one + 500-step `K.jaxy_scan`. +- **E03 — Frobenius purity:** replace `trace(rho @ rho)` with the exact + Hermitian Frobenius identity. +- **E04 — sparse XXZ:** replace 45 termwise matrix-vector products with a + TensorCircuit sparse Hamiltonian multiplication. +- **E05 — packed parameters:** pack ten PyTree leaves into one `(3, 81)` + tensor. +- **E06 — entropy `K.vmap`:** batch the unchanged checkpoint entropy kernel. +- **E07 — batched exact purity:** combine `K.vmap` with the Frobenius identity + so the three reduced density matrices share one batch. + +## End-to-end result + +Across six alternating matched pairs, the unchanged expert averaged +`4.495463 s` and +[`solution_2_training_scan_batched_purity.py`](solution_2_training_scan_batched_purity.py) +averaged `4.031039 s`. The mean paired speedup was **1.115649x** (6/6 +candidate wins; 95% t-interval `1.057686x–1.173613x`). These timings are a +same-host, same-container comparison using the local evaluator with 6 CPUs and +a 7 GiB memory limit; absolute runtimes should not be compared across +machines. diff --git a/optimized_solutions/challenge-02/factor-ablation.svg b/optimized_solutions/challenge-02/factor-ablation.svg new file mode 100644 index 0000000..0a94919 --- /dev/null +++ b/optimized_solutions/challenge-02/factor-ablation.svg @@ -0,0 +1,44 @@ + + Task 02 factor ablation + Incremental paired speedups for seven tested factors and the cumulative end-to-end result. + + + Task 02 factor ablation + Individual factors are incremental vs their parent; final is cumulative vs the expert + + + + + + + + E01 · Gate fusion + 0.966× + E02 · Training scan + 1.036× + E03 · Frobenius purity + 1.025× + E04 · Sparse XXZ + 0.973× + E05 · Packed parameters + 0.428× + E06 · Entropy vmap + 1.047× + E07 · Batched purity + 1.074× + + + Final cumulative + 1.116× + + 0.4× + 0.6× + 0.8× + 1.0× + 1.2× + Dashed line: 1× no change · green: kept · red: discarded · blue: final cumulative + diff --git a/optimized_solutions/challenge-02/research/IMPLEMENTATION_COMPARISON.md b/optimized_solutions/challenge-02/research/IMPLEMENTATION_COMPARISON.md deleted file mode 100644 index ff80ff3..0000000 --- a/optimized_solutions/challenge-02/research/IMPLEMENTATION_COMPARISON.md +++ /dev/null @@ -1,231 +0,0 @@ -# Task 02 Human-Expert Optimization and Factor Ablation - -## Result - -The optimized implementation preserves the expert's 12-qubit -entanglement-profile-constrained VQE and is **1.11565x faster** in the final -six-pair same-machine comparison. Mean end-to-end runtime fell from -`4.495463 s` to `4.031039 s`; the candidate won all six counterbalanced -pairs. The mean paired speedup has a two-sided 95% Student-t interval of -`[1.057686x, 1.173613x]`. - -| Pair | Order | Expert (s) | Candidate (s) | Speedup | -|---:|---|---:|---:|---:| -| 1 | expert → candidate | 4.865151 | 3.981228 | 1.222023x | -| 2 | candidate → expert | 4.364947 | 4.042312 | 1.079814x | -| 3 | expert → candidate | 4.411195 | 4.134876 | 1.066826x | -| 4 | candidate → expert | 4.457106 | 4.007787 | 1.112111x | -| 5 | expert → candidate | 4.432053 | 4.030015 | 1.099761x | -| 6 | candidate → expert | 4.442327 | 3.990016 | 1.113361x | -| **Mean** | — | **4.495463** | **4.031039** | **1.115649x** | - -The requested first-five view is consistent: expert/candidate means are -`4.506090/4.039244 s`, and mean paired speedup is `1.116107x`. The sixth pair -is retained because the repository workflow predeclares six pairs and uses -their t-interval for promotion. - -Machine-readable result: -[`profiles/final-reference-paired.json`](profiles/final-reference-paired.json). - -## Optimized implementation - -Two accepted mechanisms are present. - -1. **One TensorCircuit training scan.** Parameters and Optax state are carried - through one `K.jaxy_scan`, and the complete 500-update function is compiled - once with `K.jit`. Each scan output is still the loss, energy density, - three entropies, and entropy MSE evaluated *before* its corresponding Adam - update. This removes 500 Python-to-device dispatches without removing an - update or changing history semantics. -2. **One batched exact-purity kernel.** The three block checkpoint states are - returned together. TensorCircuit's reduced density matrix is evaluated - through `K.vmap`, and order-2 Renyi entropy uses the Hermitian identity - `Tr(rho²) = sum(rho * conj(rho))`. This removes the three dense - `rho @ rho` products while keeping TensorCircuit's normalized density - matrices. - -Both nested scans use TensorCircuit backend `K.jaxy_scan`; the final source -does not directly import JAX. NumPy is used only for deterministic -initialization/input conversion and Optax supplies the unchanged Adam update. -The circuit, state evolution, density matrices, Hamiltonian action, autodiff, -JIT, vmap, and scans remain TensorCircuit-NG/backend-native. - -No parameter is tied or removed. There is no static answer, alternate quantum -framework, handwritten state-vector simulator, approximation, early stopping, -or relaxed evaluator threshold. - -## Why these changes target the measured cost - -The frozen reference profile found that one update lowers in `0.803158 s`, -compiles in `1.929769 s`, contains 15,479 StableHLO lines, and then takes -`0.002643 s` on average over 12 steady calls. Five hundred steady calls -project to `1.321653 s`, so both compilation and repeated dispatch/execution -are material. - -The forward trajectory accounts for about 93.5% of separately measured loss -time (`0.000889/0.000951 s`). A single generic entropy call is only -`0.000132 s`, and a Hamiltonian action is `0.000176 s`. These measurements -explain why removing the host training loop helps, why entropy changes need -batching to become reliable, and why replacing the Hamiltonian action does -not help at this scale. - -Reference profile: -[`profiles/reference-profile.json`](profiles/reference-profile.json). - -## Factor ablation - -Each timing-eligible factor was tested in six alternating matched pairs. -E01 and E02 compare with the immutable expert; E03–E07 compare directly with -the accepted scan parent. Ratios are therefore attribution experiments, not -numbers to multiply. A factor was promoted only when all cells passed, it won -at least five pairs, and the lower endpoint of its 95% paired-speedup -t-interval exceeded one. - -| ID | Factor | Mean paired speedup | 95% t-CI | Wins | Decision | -|---|---|---:|---:|---:|---| -| E01 | Exact local gate fusion | 0.965849x | [0.946219, 0.985478] | 0/6 | Discard | -| E02 | Whole-training `K.jaxy_scan` | 1.035580x | [1.010063, 1.061098] | 6/6 | **Keep** | -| E03 | Frobenius purity alone | 1.024675x | [0.961881, 1.087470] | 5/6 | Inconclusive | -| E04 | TensorCircuit sparse XXZ | 0.972882x | [0.947782, 0.997981] | 2/6 | Discard | -| E05 | Single-leaf parameter packing | 0.428014x | [0.411501, 0.444527] | 0/6 | Discard | -| E06 | Checkpoint entropy `K.vmap` alone | 1.046783x | [0.985861, 1.107705] | 5/6 | Inconclusive | -| E07 | `K.vmap` + exact Frobenius purity | 1.074457x | [1.044174, 1.104740] | 6/6 | **Keep** | - -### E01: exact local gate fusion - -Fusion reduced 243 gate applications to 105, but dynamic trigonometry and -matrix construction outweighed the savings. The implementation was correct -at the gate, state, gradient, and post-update-observable levels, yet was -3.4% slower by paired ratio. - -![E01 paired gate-fusion ablation](figures/e01-gate-fusion.svg) - -### E02: whole-training scan - -All four 12-step histories were bit-identical. Moving the 500 updates across -one TensorCircuit scan boundary produced the first statistically supported -gain. - -![E02 paired training-scan ablation](figures/e02-training-scan.svg) - -### E03: exact Frobenius purity alone - -Replacing `trace(rho @ rho)` was numerically valid and won five pairs, but one -unfavorable pair widened the interval across one. It is not credited as an -independent gain. - -![E03 paired purity ablation](figures/e03-frobenius-purity.svg) - -### E04: TensorCircuit sparse XXZ - -`PauliStringSum2COO(..., numpy=True)` and `K.sparse_dense_matmul` passed the -Hamiltonian and trajectory audits, but were slower than the current 45-term -MVP for this 4,096-amplitude state. - -![E04 paired sparse-XXZ ablation](figures/e04-sparse-xxz.svg) - -### E05: packed parameters - -Packing ten PyTree leaves into `(3, 81)` was bit-exact but more than doubled -runtime. Static unpack slices introduce expensive gather/scatter work in -compilation and reverse mode; the expert's PyTree is already efficient. - -![E05 paired packed-parameter ablation](figures/e05-packed-params.svg) - -### E06: checkpoint `K.vmap` alone - -Batching the unchanged generic entropy kernel won five pairs but did not pass -the confidence rule. It is retained only as the predeclared subfactor evidence -for E07. - -![E06 paired entropy-vmap ablation](figures/e06-entropy-vmap.svg) - -### E07: batched exact purity - -Combining E03 and E06 changes the shared batched kernel: the three generic -density matrices remain TensorCircuit-generated while all three second -matrix products disappear together. This combination passed with `6/6` wins -and a lower confidence bound of `1.044174x`. The defensible attribution is to -the **combination**, not to either statistically inconclusive subfactor. - -![E07 paired batched-purity ablation](figures/e07-batched-purity.svg) - -E08 attempted to batch pure-state Gram matrices directly for the contiguous -six/six cut. It was rejected before timing because the changed complex64 -contraction order caused a `5.35e-6` entropy-history difference above the -frozen tolerance. Since it was not timing-eligible, no performance chart or -speedup claim is manufactured for it. - -All plots are regenerated from the tracked paired JSON files by -[`plot_factor_ablations.py`](plot_factor_ablations.py). - -## Correctness - -The candidate preserves: - -- the 12-qubit Neel state and complex64 TensorCircuit evolution; -- three even-plus-odd blocks and all 243 independently initialized angles; -- every ordered `RY`, `RZ`, `RXX`, `RYY`, and `RZZ` gate; -- the three normalized half-chain order-2 Renyi checkpoints; -- the exact 45-term open XXZ plus staggered-field energy; -- seed 2026, Adam learning rate `0.015`, exactly 500 sequential updates, and - every pre-update history; -- the original four-key NumPy result contract. - -After the final TensorCircuit-native normalization, the 12-step audit measured: - -```text -initial loss absolute error: 0 -maximum auxiliary error: 2.98e-7 -maximum gradient-element error: 1.21e-8 -maximum 12-step history error: 1.07e-6 -``` - -Every one of the 12 final benchmark cells passed the canonical evaluator. -The candidate remains below the repository's 200-effective-line policy at -168 physical lines. - -## Reproduction and provenance - -The benchmark used a fresh evaluator process per cell in a no-network -container with six CPUs, 7 GiB memory, and a 300-second cap. The hard six-CPU -backend limit is not treated as a problem: every claim is a counterbalanced -relative comparison on the same machine and resource allocation. - -Environment: - -```text -image ID: sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833 -TensorCircuit-NG: 1.8.0.dev20260726 -JAX / JAXLIB: 0.10.0 / 0.10.0 -Optax: 0.2.8 -TensorNetwork / Quimb: 0.5.1 / 1.11.1 -candidate SHA-256: aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30 -raw final report SHA-256: 27ec959f8e23156a0c8f0b15bb0f122b86e3a32e1842764888ef90eb07a842dd -``` - -Run: - -```bash -./bench run 02 \ - --solution optimized --compare-to reference \ - --repeat 6 --engine docker --cpus 6 --memory 7g \ - --timeout 300 --no-build \ - --output results/task-02-final-20260729 -``` - -Regenerate charts: - -```bash -MPLCONFIGDIR=/tmp/task02-mplconfig \ - python3 research/task-02/plot_factor_ablations.py -``` - -The complete append-only chronology, candidate hashes, audits, raw-report -hashes, and negative results are in [`LOG.md`](LOG.md). The concise mechanism -ledger is in [`INSIGHTS.md`](INSIGHTS.md). The reusable campaign procedure is -[`EXPERT_OPTIMIZATION_WORKFLOW.md`](https://github.com/hmyuuu/OrbitBreakersExpertBenchmarks/blob/7e2298b/autoresearch/EXPERT_OPTIMIZATION_WORKFLOW.md). - -The conclusion is intentionally limited to this public canonical workload, -latest tested TensorCircuit-NG image, and same-host resource allocation. It is -not a global SOTA or scaling claim. diff --git a/optimized_solutions/challenge-02/research/INSIGHTS.md b/optimized_solutions/challenge-02/research/INSIGHTS.md deleted file mode 100644 index 42151ab..0000000 --- a/optimized_solutions/challenge-02/research/INSIGHTS.md +++ /dev/null @@ -1,88 +0,0 @@ -# Task 02 Research Insights - -Task: `task-02` - -Last consolidated: `2026-07-29` - -Evidence ledger: [`LOG.md`](LOG.md) - -## Current best - -The accepted implementation combines whole-training TensorCircuit -`K.jaxy_scan` with batched checkpoint states and exact Frobenius purity. -Against the scan-only parent, the entropy combination achieved `1.074457x` -mean paired speedup, 95% interval `[1.044174x, 1.104740x]`, and `6/6` wins. -The final immutable-reference comparison is recorded separately after source -freeze. - -## Preserved semantics - -- 12-qubit Neel input and complex64 TensorCircuit-NG evolution; -- six brickwork sublayers with all 243 independent parameters; -- three half-chain Renyi-2 checkpoints and the fixed target profile; -- the 45-term open XXZ plus staggered-field Hamiltonian; -- fixed seed 2026, Adam learning rate `0.015`, and 500 sequential updates; -- every pre-update history and the original four-key NumPy result contract. - -## Confirmed bottlenecks - -- One update lowers in `0.803158 s`, compiles in `1.929769 s`, and contains - 15,479 StableHLO lines. The 500 steady updates project to `1.321653 s`, so - both cold graph staging and steady execution are material. -- The separately compiled trajectory is about 93.5% of the forward loss - runtime (`0.000889/0.000951 s`), making exact gate-graph reduction the - highest-priority factor. -- The host dispatches one compiled optimizer update 500 times. A whole-training - scan can remove that boundary, although it cannot eliminate the steady - quantum kernel itself. -- The termwise Hamiltonian MVP traces 45 independent paths, but its separately - measured forward action is only `0.000176 s`. Sparse conversion is therefore - a secondary compile-size hypothesis, not the primary steady bottleneck. -- One generic Renyi-2 call is `0.000132 s`; its Frobenius-purity rewrite is - algebraically exact but expected to be a smaller factor than gate fusion. - -Profile: [`profiles/reference-profile.json`](profiles/reference-profile.json). - -## What worked - -- Whole-training `K.jaxy_scan` preserved the four 12-step histories - bit-for-bit and reduced canonical mean runtime from `4.724217` to - `4.563051 s` in its six-pair session. -- Returning all three block checkpoints and batching the exact - `-log(sum(rho * conj(rho)))` calculation with `K.vmap` produced a further - `1.074457x` paired gain over scan-only, with its confidence interval wholly - above one. -- The combination result is not attributed to either subfactor alone: - `K.vmap` alone (`1.046783x`) and Frobenius purity alone (`1.024675x`) both - had wide intervals crossing one. The confirmed unit is their shared kernel. - -## What did not work - -- Exact local gate fusion reduced the gate-application count but regressed to - `0.965849x`; dynamic trigonometry and matrix assembly cost more than the - saved applications. -- TensorCircuit sparse XXZ action regressed to `0.972882x`; the 45-term - termwise MVP is preferable at this size. -- Packing the ten-leaf PyTree into one tensor was bit-exact but collapsed to - `0.428014x` due to slice/gather/scatter compile and autodiff overhead. -- Frobenius purity alone and checkpoint `K.vmap` alone were inconclusive and - are not claimed independently. -- Direct batched pure-state Gram matrices were rejected before timing: a - different complex64 contraction order exceeded the frozen trajectory - tolerance despite algebraic equivalence. - -## Open hypotheses - -1. larger-qubit scaling, which is outside this frozen workload; -2. future TensorCircuit compiler changes that may alter the discarded - gate-fusion or sparse-kernel tradeoffs. - -## Evidence limits - -Evidence covers only the canonical public Task 02 configuration, one latest -TensorCircuit-NG image, and one 6-CPU/7-GiB same-host profile. It does not -establish global SOTA or scaling. End-to-end differences include cold import, -tracing, compilation, 500 updates, synchronization, and conversion. - -The final six-pair comparison records `1.115649x` mean paired speedup with a -95% Student-t interval `[1.057686x, 1.173613x]` and `6/6` wins. diff --git a/optimized_solutions/challenge-02/research/LOG.md b/optimized_solutions/challenge-02/research/LOG.md deleted file mode 100644 index f8e0e7c..0000000 --- a/optimized_solutions/challenge-02/research/LOG.md +++ /dev/null @@ -1,335 +0,0 @@ -# Task 02 Autoresearch Campaign - -Task: `task-02` - -Campaign branch: `codex/orbitbreakers/task-02/extreme-native` - -Campaign task: `task-02` - -Insights: [`INSIGHTS.md`](INSIGHTS.md) - -## Campaign objective - -Reduce evaluator-reported runtime for the immutable Task 02 human expert while -preserving all 243 trainable parameters, three block-checkpoint Renyi-2 -entropies, the 45-term XXZ energy, and exactly 500 sequential Adam updates. - -## Selection and gates - -- `2026-07-29T13:30Z`: inspected all open PRs on `sxzgroup/ORBIT-Q` and the - benchmark repository. No active Task 02 optimization was present. This - campaign and every hypothesis worktree are bound to Task 02. -- Base commit: - `d13e2591574cc1480507b00bcb33b0c6a48e6b99`. -- Public data only; no hidden or private evaluation is used. -- Reference and initial optimized sources were byte-identical at selection, - SHA-256 - `cd5776dfb223924edd83795bd8222032351008a584b55d747110521c709dcdd3`. - -## Baseline `reference-six-20260729` - -Hypothesis: the latest TensorCircuit-NG image and fixed 6-CPU/7-GiB envelope -produce a valid repeated reference suitable for paired promotion decisions. - -Command: - -`./bench run 02 --solution reference --repeat 6 --engine docker --cpus 6 ---memory 7g --timeout 300 --no-build --output -results/task-02-reference-20260729` - -Environment: - -- image ID: - `sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833`; -- TensorCircuit-NG `1.8.0.dev20260726`; -- JAX/JAXLIB `0.10.0` / `0.10.0`; -- Optax `0.2.8`; -- TensorNetwork `0.5.1`; Quimb `1.11.1`; -- host fingerprint: - `c627504db97dc65b8d998afb4b9cdf73cfc3eff2ce2ac589b4a7a4aa0c7fdc48`; -- one shared container, six CPUs, 7 GiB, no network, 300-second per-cell cap; -- evaluator SHA-256: - `0d9360d4812d033d364253dd478444f68918f1b05f04146eddcb846a3dca3a1e`; -- dependency-lock SHA-256: - `cd5ac5cb2102ea7b40bd46dc81320cc59e0ce0671ab88c597f81d82b384a824b`. - -Result: - -```text -terminal_status: SUCCESS -valid: true -timed_out: false -passing_runs: 6/6 -runtimes_sec: 4.559075, 4.986945, 4.990731, 5.188701, 4.813289, 6.035628 -mean_runtime_sec: 5.0957281667 -median_runtime_sec: 4.988838 -sample_stdev_sec: 0.5064942904 -runtime_stderr_sec: 0.2067754282 -min_runtime_sec: 4.559075 -max_runtime_sec: 6.035628 -``` - -Immutable report SHA-256: -`7d450e074cc5a4cabca72e9f6cd5787e2f5226c42c69cf6c3016ec53465b9912`. - -Decision: `baseline`. The repeated-reference promotion gate passes. No -improvement is claimed without matched candidate pairs. - -## Append-only campaign events - -- `2026-07-29T13:31Z`: inspected installed TensorCircuit sources. The expert's - Pauli MVP traces one path per Hamiltonian term; Renyi-2 forms `rho @ rho`; - and the backend's `K.jaxy_scan` delegates to `jax.lax.scan`. -- `2026-07-29T13:31Z`: completed the cited survey and canonical public workload - record. Candidate editing remains blocked until the manifest is rebound and - the fail-closed gate passes. -- `2026-07-29T13:33Z`: survey, public dataset, and repeated-reference gates all - pass. Added an immutable-reference profiler to separate lowering, - compilation, trajectory, entropy, Hamiltonian action, and steady optimizer - execution before selecting candidate factors. -- `2026-07-29T13:35Z`: immutable-reference profile completed. Report - `research/task-02/profiles/reference-profile.json`, SHA-256 - `b7d190ea225ca5586d813759b89fea0cba05c045ca41e72e8f687a8769241d40`; - profiler SHA-256 - `538a86104c32925586606394f50be069800c18b054bae45a6ebb786ac0e76a8b`. - One update lowers in `0.803158 s`, compiles in `1.929769 s`, contains - 15,479 StableHLO lines, and executes in `0.002643 s` mean over 12 steady - calls. The projected 500-update kernel time is `1.321653 s`. The forward - trajectory accounts for about 93.5% of the separately measured loss - execution (`0.000889/0.000951 s`); a Hamiltonian action is only - `0.000176 s`, and one generic entropy is `0.000132 s`. Decision: prioritize - graph reduction and host-loop removal, while treating sparse Hamiltonian and - purity rewrites as secondary measured factors. - -## Append-only corrections - -Append corrections below this heading. Never rewrite an earlier result after -it has informed another experiment. - -## Experiment `e07-batched-purity` - -Branch: `codex/orbitbreakers/task-02/e07-batched-purity` - -Parent commit: `edf1e91` (accepted whole-training scan). - -Execution note: this hypothesis uses a fresh local shared Git checkout and -independent branch at the accepted commit after worktree permission review -timed out. - -Hypothesis: the predeclared shared-kernel combination of checkpoint -`K.vmap` and exact Frobenius purity will batch the three reduced-density -matrices while removing all three dense `rho @ rho` products. The prior -single-factor reports remain the subfactor ablations; neither subfactor alone -passed the confidence rule. - -Permitted data: public Task 02 artifacts and the two completed single-factor -reports only. No hidden/private evaluation. - -Pre-evaluation correctness rule: initial loss/auxiliary values, gradient, and -all four 12-step histories must satisfy the frozen survey tolerances. - -Candidate source SHA-256: -`181c0459c8194aa259be813e23896d3c70691adf5999a26353fe57cab14d3f3d`. - -Candidate source-diff SHA-256: -`ad7f082c18273b9f8c67cab5aef8477983791011261bb604ea62f6768d3a3fcf`. - -The 12-step audit passed: initial loss error `0`, auxiliary maximum error -`2.981e-7`, gradient maximum error `1.211e-8`, and maximum history error -`1.073e-6`. Audit report SHA-256: -`107c59ce1785ee9ada91e061d01970f1522ea73f3d8fe3efea37c03138d06b53`. - -Six direct parent/factor pairs all passed. Parent/factor means were -`4.531128/4.218862 s`; factor wins `6/6`; mean paired speedup `1.074457x`, -95% Student-t interval `[1.044174x, 1.104740x]`. The runner roles were -intentionally reversed so its registered `optimized` source was the factor; -the tracked report normalizes every ratio as parent/factor. Raw report -SHA-256: -`6dd10f3c24054668734022000058391c192c87f0554d404a6d3b7d61593ee07e`. - -Decision: `keep`. The shared-kernel combination passes the confidence rule -although each predeclared subfactor was inconclusive alone. - -## Experiment `e02-training-scan` - -Branch: `codex/orbitbreakers/task-02/e02-training-scan` - -Parent commit: `77939b1` - -Hypothesis: carrying parameters and Optax state through one TensorCircuit -`K.jaxy_scan`, compiled by `K.jit`, will preserve all 500 sequential updates -and pre-update histories while removing 500 Python-to-device dispatches. - -Permitted data: public Task 02 artifacts and tracked reference profile only. -No hidden/private evaluation. - -Candidate SHA-256: -`6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a`. - -Candidate diff SHA-256: -`9b590f4cb193a39327b38165bcd255f3e051f5eb76d495b141194ebefbcbe1d8`. - -Pre-evaluation correctness rule: all four 12-step pre-update histories must -match the immutable expert within `2e-4` and retain identical shapes. - -The 12-step audit passed with bit-identical values and shapes for all four -returned histories. Audit report SHA-256: -`8864dd25031e00e1df188f705824738925e3679e4e46e06ae7078c5ccb6a1493`. - -Six alternating canonical pairs all passed. Reference/candidate means were -`4.724217/4.563051 s`; candidate wins `6/6`; mean paired speedup -`1.035580x`, 95% Student-t interval `[1.010063x, 1.061098x]`. Raw report -SHA-256: -`549e267378bc1eca2ea2b839810af4c46780ac8bdc7800eacdfc15385bc1e33b`. - -Decision: `keep`. Whole-training `K.jaxy_scan` is the first accepted parent -and removes about 3.41% of end-to-end runtime in this session. - -## Consolidated independent-factor records - -The following experiments ran on isolated branches. They are appended here -after completion so the final branch retains both successful and negative -evidence without promoting discarded code. - -### Experiment `e01-gate-fusion` - -Parent commit: `77939b1`. Candidate SHA-256: -`76917fc2292984b0102dda14ceb3b873f4ca55779554d29f2fa887ffd2f3f214`. - -Hypothesis: replace all exact `RY -> RZ` pairs and commuting -`RXX -> RYY -> RZZ` triples with one differentiable TensorCircuit unitary, -reducing circuit applications from 243 to 105 without tying parameters. - -The final audit passed: local matrix error `1.33e-7`, state error `3.07e-7`, -loss error `2.38e-7`, gradient error `7.45e-8`, and post-update physical -output error `5.36e-7`. The raw Adam parameter difference (`3.63e-4`) came -from near-zero-gradient sensitivity and did not alter observables. Audit -report SHA-256: -`0c389fba34386ab57904a833d90f1192fe174515bfc5c928e27f44fb1e670a33`. - -Six pairs: reference/candidate means `4.659226/4.825325 s`, `0/6` wins, -mean paired speedup `0.965849x`, 95% interval -`[0.946219x, 0.985478x]`. Raw report SHA-256: -`1804ebe44515690e1985411b16a51153aa6ddb88ec8a6c964d4d90fe0c365ce9`. - -Decision: `discard`. Dynamic trigonometric and matrix assembly outweighed the -smaller gate-application count. - -### Experiment `e03-purity` - -Parent: accepted scan. Candidate SHA-256: -`ab560235d23e2dcd5256467f1dba03bb4eee7d675250ccf9054c3d8a670c508e`. - -Hypothesis: use the exact Hermitian identity -`trace(rho @ rho) = sum(rho * conj(rho))`, removing three 64-by-64 matrix -products per loss. - -The audit passed with gradient error `1.70e-8` and maximum 12-step history -error `1.25e-6`. Six pairs: parent/factor means -`4.591056/4.491962 s`, `5/6` wins, mean paired speedup `1.024675x`, 95% -interval `[0.961881x, 1.087470x]`. Raw report SHA-256: -`cccabf99871f8fe7d62ac42fdedd6d77394157fdd41a490ff42f324104565184`. - -Decision: `discard_inconclusive`; the interval crosses one. - -### Experiment `e04-sparse-xxz` - -Parent: accepted scan. Candidate SHA-256: -`c5997e6147212271ec45321880a14d696849a6436fb99f16a02b72fc42992942`. - -Hypothesis: replace 45 termwise MVP traces with TensorCircuit -`PauliStringSum2COO(..., numpy=True)` plus `K.sparse_dense_matmul`. - -The audit passed with Hamiltonian-action error `1.67e-5`, gradient error -`3.91e-8`, and maximum 12-step history error `1.19e-6`. Six pairs: -parent/factor means `4.296697/4.417261 s`, `2/6` wins, mean paired speedup -`0.972882x`, 95% interval `[0.947782x, 0.997981x]`. Raw report SHA-256: -`8bfba5d0d90cde8ddb571e38d975044e5ea50001e9581a1a617a13fe9bca6c12`. - -Decision: `discard`. For this 12-qubit, 45-term workload the native sparse -construction/kernel is slower than the current termwise MVP. - -### Experiment `e05-packed-params` - -Parent: accepted scan. Candidate SHA-256: -`895ede0c511e60221400a85066b036ab57fce683df614a2cabb389e928826b70`. - -Hypothesis: pack ten parameter leaves into one `(3, 81)` tensor to shrink scan -carry, Optax state, PyTree bookkeeping, and the compiled graph. - -The audit was bit-identical for initialization, loss, auxiliary values, -gradient, and four 12-step histories. Six pairs: parent/factor means -`4.592900/10.730835 s`, `0/6` wins, mean paired speedup `0.428014x`, 95% -interval `[0.411501x, 0.444527x]`. Raw report SHA-256: -`b24d2fbeb2094e23f2353b94a71896dc6b1f506bf6eea600b14536aa7d7617fb`. - -Decision: `discard`. Static unpack slices add costly gather/scatter autodiff; -the original ten-leaf PyTree is substantially better. - -### Experiment `e06-entropy-vmap` - -Parent: accepted scan. Candidate SHA-256: -`c9c7840740152f03f23ddbc50379098847508007288da397ecf592952204cdb2`. - -Hypothesis: return all three checkpoint states, then apply unchanged -TensorCircuit reduced-density-matrix Renyi-2 kernels through `K.vmap`. - -The audit passed with gradient error `1.86e-8` and maximum 12-step history -error `8.34e-7`. Six pairs: parent/factor means -`4.765934/4.572339 s`, `5/6` wins, mean paired speedup `1.046783x`, 95% -interval `[0.985861x, 1.107705x]`. Raw report SHA-256: -`a43cd8242d76503057c88e4de2ee7b702965ecf89c41643b21ba4d8664d13a97`. - -Decision: `discard_inconclusive`. It is not retained alone; E07 separately -predeclared and measured the changed shared kernel formed by combining this -factor with exact Frobenius purity. - -## Final TensorCircuit-native normalization - -After factor selection, the inner block scan was changed from direct -`jax.lax.scan` to TensorCircuit backend `K.jaxy_scan`, and the now-unused -direct JAX import was removed. In the installed backend this is a thin -framework-native delegation to the same JAX primitive, so it is a fidelity -normalization rather than a separately claimed speedup factor. The final -source SHA-256 before confirmation is: -`aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30`. - -The full E07 equivalence audit and final immutable-reference timing are rerun -after this normalization; no earlier factor result is reused as final timing. - -## Experiment `e08-purestate-purity` - -Parent commit: `0501d90`. Candidate source SHA-256: -`950e86b9c0db25497034ce0ff385619262bbdecfee56e35bcf832f13f95da7e3`. - -Hypothesis: exploit the contiguous six/six public half-chain cut by reshaping -all checkpoint pure states to `(3, 64, 64)`, constructing retained-half Gram -matrices in one backend `K.einsum`, and computing their purities together. - -The audit failed the frozen gate before timing. Initial loss error was -`5.96e-7` and gradient error `3.77e-8`, but the changed complex64 contraction -order produced auxiliary error `2.50e-6` and 12-step entropy-history error -`5.35e-6`, above the predeclared tolerance. Audit report SHA-256: -`d032009a567fcf2ec1da244318e27a8f1788a20c19af029b6afb8cc0eaa08b4d`. - -Decision: `discard_before_timing`. No performance claim or chart is produced -for a candidate that failed correctness. - -## Final immutable-reference confirmation - -Final candidate SHA-256: -`aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30`. - -The post-normalization 12-step audit reproduced the E07 values: loss error -`0`, auxiliary error `2.981e-7`, gradient error `1.211e-8`, and maximum -history error `1.073e-6`. - -All twelve cells in six alternating immutable-reference/candidate pairs -passed. Reference/candidate means were `4.495463/4.031039 s`; candidate wins -`6/6`; mean paired speedup `1.115649x`, 95% Student-t interval -`[1.057686x, 1.173613x]`; mean paired improvement `10.192992%`. The first -five pairs independently give mean runtimes `4.506090/4.039244 s` and mean -paired speedup `1.116107x`. Raw report SHA-256: -`27ec959f8e23156a0c8f0b15bb0f122b86e3a32e1842764888ef90eb07a842dd`. - -Decision: `final_keep`. diff --git a/optimized_solutions/challenge-02/research/SURVEY.md b/optimized_solutions/challenge-02/research/SURVEY.md deleted file mode 100644 index 6dc081e..0000000 --- a/optimized_solutions/challenge-02/research/SURVEY.md +++ /dev/null @@ -1,155 +0,0 @@ -# ORBIT-Q Task 02 Runtime Optimization Survey - -**Status: READY** - -Campaign task: `task-02` - -Survey freeze: `2026-07-29T13:31:00Z` - -Reference commit: `d13e2591574cc1480507b00bcb33b0c6a48e6b99` - -This campaign covers only Task 02. The immutable expert, public canonical -workload, semantic constraints, optimization hypotheses, and measurement rule -are frozen before the first candidate edit. - -## Evidence and claim boundary - -The immutable human expert is `references/task-02/solution_2.py` -(`sha256:cd5776dfb223924edd83795bd8222032351008a584b55d747110521c709dcdd3`). -The public contract and evaluator are `tasks/task-02/problem.md` -(`sha256:e3e9b7517cd8aa1d0fad4fe4bce13cd61cde94d94c21b0324df95e80dd581a39`) -and `tasks/task-02/evaluator/evaluate_2.py` -(`sha256:0d9360d4812d033d364253dd478444f68918f1b05f04146eddcb846a3dca3a1e`). - -At `2026-07-29T13:30Z`, the six open PRs on `sxzgroup/ORBIT-Q` were -repository infrastructure, agent-axis results, and the Task 07 design report; -none targeted Task 02. The separate benchmark repository likewise had no -active Task 02 optimization PR. - -The immutable reference passed six fresh evaluator processes at -`4.559075`, `4.986945`, `4.990731`, `5.188701`, `4.813289`, and -`6.035628` seconds. Its mean is `5.095728` seconds, median `4.988838` -seconds, sample standard deviation `0.506494` seconds, and standard error -`0.206775` seconds. No external result uses this exact evaluator, target -profile, initialization, 500-step Adam trajectory, image, and hardware -allocation. Claims are limited to same-machine gains over the bundled expert -on the canonical public workload. - -## Framework and environment - -Measurements use image -`sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833` -with six CPUs, 7 GiB memory, no network, and a fresh evaluator process per -cell. The dependency lock is -`envs/tensorcircuit-py311/requirements.lock` -(`sha256:cd5ac5cb2102ea7b40bd46dc81320cc59e0ce0671ab88c597f81d82b384a824b`). -No TensorCircuit downgrade is used. - -| Component | Version | Inspected source | -| --- | --- | --- | -| TensorCircuit-NG | `1.8.0.dev20260726` | `quantum.py` (`sha256:fcaee21ba5ccde1b89c46e2f5424c48d342e3bfaedf72adba672ab6bd4ded703`), `circuit.py` (`sha256:5c4d569325369d957dc60bbeca8a581508549ff9813a7a163de61a6294864662`), and `gates.py` (`sha256:6db54dab1390360273ef527a1fadc4f36ba169d7e961dcc4bd049b6b2a43cbe4`) | -| JAX / JAXLIB | `0.10.0` / `0.10.0` | TensorCircuit JAX backend (`sha256:88657aebf8e5d566ac4e653abe327083da0253f02a3a297a134b871ffe4baab9`) | -| Optax | `0.2.8` | Adam with the required `0.015` learning rate and exactly 500 updates | -| TensorNetwork / Quimb | `0.5.1` / `1.11.1` | Installed support stack; the dense state path does not invoke OMECo | - -TensorCircuit documents sparse, dense, vmap, termwise, and MPO alternatives -for Pauli-sum expectation values: -. -Its public quantum source documents both `PauliStringSum2MVP` and -`PauliStringSum2COO`, and implements order-2 Renyi entropy as -`-log(trace(rho @ rho))`: -. -TensorCircuit's FAQ describes the same reduced-density-matrix and Renyi APIs -used by the expert: -. -JAX documents that `lax.scan` lowers a fixed loop to one WhileOp rather than -unrolling it: -. - -## Task 02: entanglement-profile-constrained VQE - -The expert evolves a dense 12-qubit complex64 state from the Neel basis state. -Each of three blocks applies one even and one odd brickwork sublayer. Every -sublayer applies independent `RY -> RZ` rotations, followed by independent -`RXX -> RYY -> RZZ` gates on its bonds. After each complete block it computes -the left-half Renyi-2 entropy. The final state is evaluated against the -45-term open XXZ plus staggered-field Hamiltonian. Reverse-mode differentiation -updates all 243 independent float32 parameters with Adam for exactly 500 steps. - -Every viable candidate must preserve: - -- the 12-qubit Neel input, six trainable sublayers, and all 243 independent - parameters initialized from the fixed NumPy seed 2026; -- the exact TensorCircuit gate convention and every ordered - `RY -> RZ -> RXX -> RYY -> RZZ` operation; -- the normalized state after each complete block and the three half-chain - order-2 Renyi entropies; -- the exact 45-term XXZ/staggered-field energy, entropy weight `0.25`, target - profile `[0.30, 0.60, 0.80]`, and complex64 semantics; -- exactly 500 sequential Adam updates and every pre-update energy, loss, - entropy MSE, and three-entropy row; -- TensorCircuit-NG as the central quantum framework and the original four-key - NumPy output contract. - -## Source-supported cost model - -One loss contains 243 parameterized TensorCircuit gates, three 64-by-64 -reduced-density matrices, three dense `rho @ rho` products, and one -45-term Hamiltonian action on 4,096 amplitudes. Reverse mode differentiates -through all of these operations. The expert stages one update once, but then -dispatches the compiled update from Python 500 times. - -The installed `PauliStringSum2MVP` loops over all 45 Pauli terms in Python -during tracing and emits a separate mask/flip/multiply/accumulate path per -term. `PauliStringSum2COO` instead creates one native backend sparse operator. -The installed pure-state reduced-density-matrix path reshapes the amplitude -vector to 64-by-64 and forms `rho = w @ w.adjoint()`. For a Hermitian density -matrix, `trace(rho @ rho) = sum(abs(rho) ** 2)`, so the second dense matrix -product is algebraically removable without changing the requested entropy. - -The three Pauli rotations on a bond commute. Their product is one exact -parity-preserving 4-by-4 TensorCircuit gate. Likewise, each `RY -> RZ` -sequence is one exact 2-by-2 gate. This can reduce 81 gate applications per -block to 35 while keeping every angle independent. - -## Frozen experiments - -1. **Whole-training TensorCircuit scan.** Carry parameters and Optax state - through `K.jaxy_scan` and return all pre-update observables. This tests host - dispatch independently. -2. **Exact Renyi-2 purity reduction.** Keep TensorCircuit's reduced density - matrix but replace `trace(rho @ rho)` with `sum(abs(rho) ** 2)`. Require - state, entropy, loss, gradient, one-update, and short-history agreement. -3. **Native sparse XXZ action.** Compare TensorCircuit - `PauliStringSum2COO` plus backend sparse-dense multiplication against the - expert's termwise MVP. Retain only if canonical timing improves. -4. **Exact local gate fusion.** Replace each parameterized `RY -> RZ` pair - and commuting `RXX -> RYY -> RZZ` triple with its exact differentiable - TensorCircuit unitary. Audit random gate matrices and end-to-end gradients. -5. **Initial-state constant construction.** Build the same Neel amplitude - vector without eight circuit nodes only if profiling shows a measurable - residual; this is expected to be negligible. -6. **MPS or truncated Schmidt simulation.** Reject for the canonical - campaign: the entropy checkpoint and unconstrained entanglers do not give a - static small exact bond bound, and truncation would change semantics. - -Each retained factor will receive six alternating matched pairs against its -accepted parent, plus one chart. The final combination will be remeasured -against the immutable expert. - -## Correctness and measurement rule - -Before canonical timing, compare reference and candidate block states, -entropies, energy, complete loss, gradient leaves, one Adam update, and a -short physical history. Frozen complex64 tolerances are `2e-6` for gates, -states, observables, and initial loss; `1e-5` for gradient elements; and -`2e-4` for post-update and short-history physical outputs. Raw Adam parameter -differences caused only by theoretical-zero complex64 gradients must be -reported and cannot replace the physical-output checks. - -Final evidence uses six counterbalanced canonical pairs in one no-network -container. Odd pairs run reference then candidate; even pairs reverse order. -Every cell is a fresh evaluator process with a 300-second cap. Promotion -requires all 12 cells to pass, candidate wins at least five of six pairs, -candidate mean and median are lower, and the lower endpoint of a two-sided -95% Student-t interval for mean pairwise speedup exceeds `1.0`. diff --git a/optimized_solutions/challenge-02/research/check_batched_purity.py b/optimized_solutions/challenge-02/research/check_batched_purity.py deleted file mode 100644 index 9e9761d..0000000 --- a/optimized_solutions/challenge-02/research/check_batched_purity.py +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env python3 -"""Audit the batched exact Renyi-2 kernel for Task 02.""" - -from __future__ import annotations - -import argparse -import importlib.util -import json -from pathlib import Path - -import numpy as np -import tensorcircuit as tc - - -ROOT = Path(__file__).resolve().parents[2] -REFERENCE = ROOT / "references" / "task-02" / "solution_2.py" -CANDIDATE = ROOT / "src" / "solutions" / "task-02" / "solution_2.py" -EVALUATOR = ROOT / "tasks" / "task-02" / "evaluator" / "evaluate_2.py" -K = tc.set_backend("jax") -tc.set_dtype("complex64") - - -def load(path: Path, name: str): - spec = importlib.util.spec_from_file_location(name, path) - if spec is None or spec.loader is None: - raise RuntimeError(path) - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - return module - - -def tree_error(a, b): - aa = K.tree_flatten(a)[0] - bb = K.tree_flatten(b)[0] - return max( - float(np.max(np.abs(K.numpy(x) - K.numpy(y)))) - for x, y in zip(aa, bb) - ) - - -def main() -> None: - parser = argparse.ArgumentParser() - parser.add_argument("--steps", type=int, default=12) - parser.add_argument("--output", type=Path) - args = parser.parse_args() - reference = load(REFERENCE, "task02_reference_batched_purity_audit") - candidate = load(CANDIDATE, "task02_candidate_batched_purity_audit") - evaluator = load(EVALUATOR, "task02_evaluator_batched_purity_audit") - config = dict(evaluator.DEFAULT_CONFIG) - config["target_entropies"] = np.asarray( - config["target_entropies"], dtype=np.float32 - ) - params = reference.initial_parameters(config) - circuit = tc.Circuit(config["n_qubits"]) - for i in range(1, config["n_qubits"], 2): - circuit.x(i) - input_state = circuit.state() - target = K.convert_to_tensor(config["target_entropies"]) - href = reference.build_xxz_mvp(config) - hcand = candidate.build_xxz_mvp(config) - - def ref_loss(p): - return reference.observables(p, input_state, href, config, target) - - def cand_loss(p): - return candidate.observables(p, input_state, hcand, config, target) - - (ref_loss_value, ref_aux), ref_grad = K.value_and_grad( - ref_loss, has_aux=True - )(params) - (cand_loss_value, cand_aux), cand_grad = K.value_and_grad( - cand_loss, has_aux=True - )(params) - config["max_steps"] = args.steps - expected = reference.run_solution(config) - actual = candidate.run_solution(config) - history_errors = { - key: float( - np.max( - np.abs( - np.asarray(expected[key], dtype=float) - - np.asarray(actual[key], dtype=float) - ) - ) - ) - for key in sorted(expected) - } - report = { - "schema_version": 1, - "task_id": "02", - "steps": args.steps, - "loss_abs_error": float( - abs(K.numpy(ref_loss_value - cand_loss_value)) - ), - "aux_max_error": tree_error(ref_aux, cand_aux), - "gradient_max_error": tree_error(ref_grad, cand_grad), - "history_max_abs_errors": history_errors, - } - report["passed"] = ( - report["loss_abs_error"] <= 2e-6 - and report["aux_max_error"] <= 2e-6 - and report["gradient_max_error"] <= 1e-5 - and max(history_errors.values()) <= 2e-4 - ) - encoded = json.dumps(report, indent=2, sort_keys=True) + "\n" - if args.output: - args.output.write_text(encoded, encoding="utf-8") - print(encoded, end="") - raise SystemExit(0 if report["passed"] else 1) - - -if __name__ == "__main__": - main() diff --git a/optimized_solutions/challenge-02/research/check_training_scan.py b/optimized_solutions/challenge-02/research/check_training_scan.py deleted file mode 100644 index 5ff2509..0000000 --- a/optimized_solutions/challenge-02/research/check_training_scan.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python3 -"""Compare Task 02 Python-dispatched and K.jaxy_scan training histories.""" - -from __future__ import annotations - -import argparse -import importlib.util -import json -from pathlib import Path - -import numpy as np - - -ROOT = Path(__file__).resolve().parents[2] -REFERENCE = ROOT / "references" / "task-02" / "solution_2.py" -CANDIDATE = ROOT / "src" / "solutions" / "task-02" / "solution_2.py" -EVALUATOR = ROOT / "tasks" / "task-02" / "evaluator" / "evaluate_2.py" - - -def load(path: Path, name: str): - spec = importlib.util.spec_from_file_location(name, path) - if spec is None or spec.loader is None: - raise RuntimeError(path) - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - return module - - -def main() -> None: - parser = argparse.ArgumentParser() - parser.add_argument("--steps", type=int, default=12) - parser.add_argument("--output", type=Path) - args = parser.parse_args() - reference = load(REFERENCE, "task02_reference_scan_audit") - candidate = load(CANDIDATE, "task02_candidate_scan_audit") - evaluator = load(EVALUATOR, "task02_evaluator_scan_audit") - config = dict(evaluator.DEFAULT_CONFIG) - config["target_entropies"] = np.asarray( - config["target_entropies"], dtype=np.float32 - ) - config["max_steps"] = args.steps - - expected = reference.run_solution(config) - actual = candidate.run_solution(config) - errors = { - key: float( - np.max( - np.abs( - np.asarray(expected[key], dtype=float) - - np.asarray(actual[key], dtype=float) - ) - ) - ) - for key in sorted(expected) - } - shapes_match = { - key: np.shape(expected[key]) == np.shape(actual[key]) - for key in sorted(expected) - } - report = { - "schema_version": 1, - "task_id": "02", - "steps": args.steps, - "max_abs_errors": errors, - "shapes_match": shapes_match, - "passed": all(shapes_match.values()) and max(errors.values()) <= 2e-4, - } - encoded = json.dumps(report, indent=2, sort_keys=True) + "\n" - if args.output: - args.output.write_text(encoded, encoding="utf-8") - print(encoded, end="") - raise SystemExit(0 if report["passed"] else 1) - - -if __name__ == "__main__": - main() diff --git a/optimized_solutions/challenge-02/research/figures/e01-gate-fusion.svg b/optimized_solutions/challenge-02/research/figures/e01-gate-fusion.svg deleted file mode 100644 index cbfd6af..0000000 --- a/optimized_solutions/challenge-02/research/figures/e01-gate-fusion.svg +++ /dev/null @@ -1,1490 +0,0 @@ - - - - - - - - image/svg+xml - - - Matplotlib v3.10.8, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/optimized_solutions/challenge-02/research/figures/e02-training-scan.svg b/optimized_solutions/challenge-02/research/figures/e02-training-scan.svg deleted file mode 100644 index 31f6fa1..0000000 --- a/optimized_solutions/challenge-02/research/figures/e02-training-scan.svg +++ /dev/null @@ -1,1487 +0,0 @@ - - - - - - - - image/svg+xml - - - Matplotlib v3.10.8, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/optimized_solutions/challenge-02/research/figures/e03-frobenius-purity.svg b/optimized_solutions/challenge-02/research/figures/e03-frobenius-purity.svg deleted file mode 100644 index bba7075..0000000 --- a/optimized_solutions/challenge-02/research/figures/e03-frobenius-purity.svg +++ /dev/null @@ -1,1508 +0,0 @@ - - - - - - - - image/svg+xml - - - Matplotlib v3.10.8, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/optimized_solutions/challenge-02/research/figures/e04-sparse-xxz.svg b/optimized_solutions/challenge-02/research/figures/e04-sparse-xxz.svg deleted file mode 100644 index ba53338..0000000 --- a/optimized_solutions/challenge-02/research/figures/e04-sparse-xxz.svg +++ /dev/null @@ -1,1521 +0,0 @@ - - - - - - - - image/svg+xml - - - Matplotlib v3.10.8, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/optimized_solutions/challenge-02/research/figures/e05-packed-params.svg b/optimized_solutions/challenge-02/research/figures/e05-packed-params.svg deleted file mode 100644 index 6c1147d..0000000 --- a/optimized_solutions/challenge-02/research/figures/e05-packed-params.svg +++ /dev/null @@ -1,1474 +0,0 @@ - - - - - - - - image/svg+xml - - - Matplotlib v3.10.8, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/optimized_solutions/challenge-02/research/figures/e06-entropy-vmap.svg b/optimized_solutions/challenge-02/research/figures/e06-entropy-vmap.svg deleted file mode 100644 index 2546747..0000000 --- a/optimized_solutions/challenge-02/research/figures/e06-entropy-vmap.svg +++ /dev/null @@ -1,1470 +0,0 @@ - - - - - - - - image/svg+xml - - - Matplotlib v3.10.8, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/optimized_solutions/challenge-02/research/figures/e07-batched-purity.svg b/optimized_solutions/challenge-02/research/figures/e07-batched-purity.svg deleted file mode 100644 index 29d04ad..0000000 --- a/optimized_solutions/challenge-02/research/figures/e07-batched-purity.svg +++ /dev/null @@ -1,1486 +0,0 @@ - - - - - - - - image/svg+xml - - - Matplotlib v3.10.8, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/optimized_solutions/challenge-02/research/plot_factor_ablations.py b/optimized_solutions/challenge-02/research/plot_factor_ablations.py deleted file mode 100644 index fca4f7f..0000000 --- a/optimized_solutions/challenge-02/research/plot_factor_ablations.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python3 -"""Render one paired-speedup SVG for every measured Task 02 factor.""" - -import json -from pathlib import Path - -import matplotlib - -matplotlib.use("Agg") -import matplotlib.pyplot as plt - - -ROOT = Path(__file__).resolve().parent -PROFILES = ROOT / "profiles" -FIGURES = ROOT / "figures" - -FACTORS = [ - ("e01-gate-fusion-paired.json", "e01-gate-fusion.svg", "Exact local gate fusion"), - ("e02-training-scan-paired.json", "e02-training-scan.svg", "Whole-training K.jaxy_scan"), - ("e03-purity-paired.json", "e03-frobenius-purity.svg", "Exact Frobenius purity"), - ("e04-sparse-xxz-paired.json", "e04-sparse-xxz.svg", "TensorCircuit sparse XXZ"), - ("e05-packed-params-paired.json", "e05-packed-params.svg", "Single-leaf parameter packing"), - ("e06-entropy-vmap-paired.json", "e06-entropy-vmap.svg", "Checkpoint entropy K.vmap"), - ("e07-batched-purity-paired.json", "e07-batched-purity.svg", "K.vmap + exact purity"), -] - - -def render_factor(profile_name, output_name, title): - data = json.loads((PROFILES / profile_name).read_text()) - ratios = [pair["speedup"] for pair in data["pairs"]] - mean = data["mean_paired_speedup"] - low, high = data["paired_speedup_95pct_t_ci"] - decision = data["decision"] - color = "#2E7D32" if decision == "keep" else "#B26A00" - if decision == "discard": - color = "#B3261E" - - fig, ax = plt.subplots(figsize=(7.2, 4.3)) - ax.axhline(1.0, color="#303030", linewidth=1.0) - ax.scatter(range(1, 7), ratios, color=color, s=42, zorder=3) - ax.errorbar( - 7, - mean, - yerr=[[mean - low], [high - mean]], - fmt="D", - color=color, - capsize=6, - markersize=7, - linewidth=2, - ) - span = max(max(ratios + [high, 1.0]) - min(ratios + [low, 1.0]), 0.08) - ax.set_ylim( - min(ratios + [low, 1.0]) - 0.16 * span, - max(ratios + [high, 1.0]) + 0.22 * span, - ) - ax.set_xticks(range(1, 8), ["1", "2", "3", "4", "5", "6", "mean"]) - ax.set_xlabel("Alternating matched pair") - ax.set_ylabel("Speedup (parent runtime / factor runtime)") - fig.suptitle(title, y=0.96, fontsize=13) - ax.grid(axis="y", color="#D0D0D0", linewidth=0.6) - ax.text( - 0.02, - 0.94, - f"mean {mean:.4f}× · 95% t-CI [{low:.4f}, {high:.4f}] · {decision}", - transform=ax.transAxes, - ha="left", - va="top", - fontsize=9, - ) - ax.text(6.85, 1.0, "no change", ha="right", va="bottom", fontsize=8) - fig.subplots_adjust(left=0.14, right=0.98, bottom=0.16, top=0.82) - fig.savefig( - FIGURES / output_name, - bbox_inches="tight", - metadata={"Date": None}, - ) - plt.close(fig) - - -def main(): - FIGURES.mkdir(parents=True, exist_ok=True) - plt.rcParams["svg.hashsalt"] = "task-02-factor-ablations" - plt.rcParams["font.family"] = "DejaVu Sans" - for args in FACTORS: - render_factor(*args) - - -if __name__ == "__main__": - main() diff --git a/optimized_solutions/challenge-02/research/profile_reference.py b/optimized_solutions/challenge-02/research/profile_reference.py deleted file mode 100644 index cd5478e..0000000 --- a/optimized_solutions/challenge-02/research/profile_reference.py +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/env python3 -"""Profile the immutable Task 02 expert without changing benchmark code.""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib.util -import json -import statistics -import time -from pathlib import Path - -import jax -import numpy as np -import optax -import tensorcircuit as tc - - -ROOT = Path(__file__).resolve().parents[2] -REFERENCE = ROOT / "references" / "task-02" / "solution_2.py" -EVALUATOR = ROOT / "tasks" / "task-02" / "evaluator" / "evaluate_2.py" - - -def load_module(path: Path, name: str): - spec = importlib.util.spec_from_file_location(name, path) - if spec is None or spec.loader is None: - raise RuntimeError(f"cannot load {path}") - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - return module - - -def sha256(path: Path) -> str: - return hashlib.sha256(path.read_bytes()).hexdigest() - - -def sync(value): - return jax.block_until_ready(value) - - -def timed_calls(fn, args, repeat: int): - values = [] - for _ in range(repeat): - start = time.perf_counter() - sync(fn(*args)) - values.append(time.perf_counter() - start) - return { - "values_sec": values, - "mean_sec": statistics.mean(values), - "median_sec": statistics.median(values), - } - - -def main() -> None: - parser = argparse.ArgumentParser() - parser.add_argument("--repeat", type=int, default=12) - parser.add_argument("--output", type=Path) - args = parser.parse_args() - - expert = load_module(REFERENCE, "task02_reference_profile") - evaluator = load_module(EVALUATOR, "task02_evaluator_profile") - config = dict(evaluator.DEFAULT_CONFIG) - config["target_entropies"] = np.asarray( - evaluator.DEFAULT_CONFIG["target_entropies"], dtype=np.float32 - ) - - K = tc.set_backend("jax") - tc.set_dtype("complex64") - params = expert.initial_parameters(config) - circuit = tc.Circuit(config["n_qubits"]) - for i in range(1, config["n_qubits"], 2): - circuit.x(i) - input_state = circuit.state() - hamiltonian_mvp = expert.build_xxz_mvp(config) - target = K.convert_to_tensor(config["target_entropies"]) - optimizer = optax.adam(config["learning_rate"]) - opt_state = optimizer.init(params) - - def loss_fn(p): - return expert.observables( - p, input_state, hamiltonian_mvp, config, target - ) - - def train_step(p, state): - (loss, aux), grads = K.value_and_grad(loss_fn, has_aux=True)(p) - updates, state = optimizer.update(grads, state, p) - p = optax.apply_updates(p, updates) - return p, state, loss, aux - - def trajectory(p): - return expert.block_states(p, input_state, config) - - trajectory_jit = K.jit(trajectory) - loss_jit = K.jit(loss_fn) - step_jit = K.jit(train_step) - - profile = {} - for name, fn, fn_args in ( - ("trajectory", trajectory_jit, (params,)), - ("loss", loss_jit, (params,)), - ("train_step", step_jit, (params, opt_state)), - ): - start = time.perf_counter() - lowered = fn.lower(*fn_args) - lower_sec = time.perf_counter() - start - stablehlo = str(lowered.compiler_ir(dialect="stablehlo")) - start = time.perf_counter() - compiled = lowered.compile() - compile_sec = time.perf_counter() - start - start = time.perf_counter() - sync(compiled(*fn_args)) - cold_execute_sec = time.perf_counter() - start - profile[name] = { - "lower_sec": lower_sec, - "compile_sec": compile_sec, - "cold_execute_sec": cold_execute_sec, - "stablehlo_lines": len(stablehlo.splitlines()), - "steady": timed_calls(compiled, fn_args, args.repeat), - } - - final_state, _ = trajectory_jit(params) - sync(final_state) - energy_jit = K.jit(lambda s: expert.xxz_energy(s, hamiltonian_mvp)) - entropy_jit = K.jit(lambda s: expert.renyi2_entropy(s, config)) - for name, fn in (("energy", energy_jit), ("one_entropy", entropy_jit)): - lowered = fn.lower(final_state) - stablehlo = str(lowered.compiler_ir(dialect="stablehlo")) - start = time.perf_counter() - compiled = lowered.compile() - compile_sec = time.perf_counter() - start - profile[name] = { - "compile_sec": compile_sec, - "stablehlo_lines": len(stablehlo.splitlines()), - "steady": timed_calls(compiled, (final_state,), args.repeat), - } - - report = { - "schema_version": 1, - "task_id": "02", - "reference_sha256": sha256(REFERENCE), - "evaluator_sha256": sha256(EVALUATOR), - "jax": jax.__version__, - "tensorcircuit": tc.__version__, - "repeat": args.repeat, - "profile": profile, - "projected_500_train_steps_sec": ( - profile["train_step"]["steady"]["mean_sec"] * config["max_steps"] - ), - } - encoded = json.dumps(report, indent=2, sort_keys=True) + "\n" - if args.output: - args.output.write_text(encoded, encoding="utf-8") - print(encoded, end="") - - -if __name__ == "__main__": - main() diff --git a/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-equivalence.json deleted file mode 100644 index 2b7ddee..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-equivalence.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "aux_max_error": 2.384185791015625e-07, - "entropy_max_error": 0.0, - "gradient_max_error": 7.450580596923828e-08, - "loss_abs_error": 2.384185791015625e-07, - "max_gate_matrix_error": 1.3328003944934608e-07, - "one_update_parameter_max_error": 0.0003634784370660782, - "passed": true, - "post_update_aux_max_error": 5.364418029785156e-07, - "schema_version": 1, - "state_max_error": 3.071953074140765e-07, - "task_id": "02" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-paired.json b/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-paired.json deleted file mode 100644 index db6d2ab..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e01-gate-fusion-paired.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "schema_version": 1, - "task_id": "02", - "factor": "exact_local_gate_fusion", - "parent": "immutable_reference", - "candidate_sha256": "76917fc2292984b0102dda14ceb3b873f4ca55779554d29f2fa887ffd2f3f214", - "raw_report_sha256": "1804ebe44515690e1985411b16a51153aa6ddb88ec8a6c964d4d90fe0c365ce9", - "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", - "cpus": 6, - "memory": "7g", - "passing_cells": 12, - "pairs": [ - {"pair": 1, "order": "reference->candidate", "reference_sec": 4.675749, "candidate_sec": 4.718604, "speedup": 0.9909178646904889}, - {"pair": 2, "order": "candidate->reference", "reference_sec": 4.589206, "candidate_sec": 4.696532, "speedup": 0.9771478188586812}, - {"pair": 3, "order": "reference->candidate", "reference_sec": 4.706527, "candidate_sec": 4.962863, "speedup": 0.948349168614971}, - {"pair": 4, "order": "candidate->reference", "reference_sec": 4.57895, "candidate_sec": 4.807351, "speedup": 0.9524892191146435}, - {"pair": 5, "order": "reference->candidate", "reference_sec": 4.663297, "candidate_sec": 4.922267, "speedup": 0.9473880632643455}, - {"pair": 6, "order": "candidate->reference", "reference_sec": 4.741629, "candidate_sec": 4.844332, "speedup": 0.9787993473609984} - ], - "reference_mean_sec": 4.659226333333333, - "reference_median_sec": 4.669523, - "reference_stderr_sec": 0.026245163462584452, - "candidate_mean_sec": 4.825324833333333, - "candidate_median_sec": 4.825841499999999, - "candidate_stderr_sec": 0.043579732377499014, - "mean_paired_speedup": 0.9658485803173548, - "paired_speedup_stderr": 0.007636222471772435, - "paired_speedup_95pct_t_ci": [0.9462190455385387, 0.9854781150961708], - "candidate_wins": 0, - "decision": "discard" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e02-training-scan-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e02-training-scan-equivalence.json deleted file mode 100644 index 4b0e6e9..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e02-training-scan-equivalence.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "max_abs_errors": { - "energy_density_history": 0.0, - "entropy_history": 0.0, - "entropy_mse_history": 0.0, - "loss_history": 0.0 - }, - "passed": true, - "schema_version": 1, - "shapes_match": { - "energy_density_history": true, - "entropy_history": true, - "entropy_mse_history": true, - "loss_history": true - }, - "steps": 12, - "task_id": "02" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e02-training-scan-paired.json b/optimized_solutions/challenge-02/research/profiles/e02-training-scan-paired.json deleted file mode 100644 index 16e4664..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e02-training-scan-paired.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "schema_version": 1, - "task_id": "02", - "factor": "whole_training_k_jaxy_scan", - "parent": "immutable_reference", - "candidate_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", - "raw_report_sha256": "549e267378bc1eca2ea2b839810af4c46780ac8bdc7800eacdfc15385bc1e33b", - "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", - "cpus": 6, - "memory": "7g", - "passing_cells": 12, - "pairs": [ - { - "pair": 1, - "order": "reference->candidate", - "reference_sec": 4.64709, - "candidate_sec": 4.622549, - "speedup": 1.0053089756322757 - }, - { - "pair": 2, - "order": "candidate->reference", - "reference_sec": 4.725854, - "candidate_sec": 4.547981, - "speedup": 1.039110321700992 - }, - { - "pair": 3, - "order": "reference->candidate", - "reference_sec": 4.690144, - "candidate_sec": 4.655539, - "speedup": 1.0074330813252772 - }, - { - "pair": 4, - "order": "candidate->reference", - "reference_sec": 4.723182, - "candidate_sec": 4.531975, - "speedup": 1.042190656391529 - }, - { - "pair": 5, - "order": "reference->candidate", - "reference_sec": 4.808917, - "candidate_sec": 4.522497, - "speedup": 1.0633322697615941 - }, - { - "pair": 6, - "order": "candidate->reference", - "reference_sec": 4.750113, - "candidate_sec": 4.497762, - "speedup": 1.0561059033359257 - } - ], - "reference_mean_sec": 4.724216666666667, - "reference_median_sec": 4.724518, - "reference_stderr_sec": 0.022329343375428128, - "candidate_mean_sec": 4.5630505, - "candidate_median_sec": 4.539978, - "candidate_stderr_sec": 0.025294363838280938, - "mean_paired_speedup": 1.0355802013579323, - "paired_speedup_stderr": 0.009926813991785015, - "paired_speedup_95pct_t_ci": [ - 1.0100625136249093, - 1.0610978890909553 - ], - "candidate_wins": 6, - "decision": "keep" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e03-purity-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e03-purity-equivalence.json deleted file mode 100644 index 4cdb3bd..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e03-purity-equivalence.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "aux_max_error": 2.9803231882397085e-07, - "gradient_max_error": 1.6996636986732483e-08, - "history_max_abs_errors": { - "energy_density_history": 1.2516975402832031e-06, - "entropy_history": 8.568167686462402e-07, - "entropy_mse_history": 6.258487701416016e-07, - "loss_history": 1.1920928955078125e-06 - }, - "loss_abs_error": 0.0, - "passed": true, - "schema_version": 1, - "steps": 12, - "task_id": "02" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e03-purity-paired.json b/optimized_solutions/challenge-02/research/profiles/e03-purity-paired.json deleted file mode 100644 index 3fa73d8..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e03-purity-paired.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "schema_version": 1, - "task_id": "02", - "factor": "exact_frobenius_purity", - "parent_commit": "edf1e91", - "parent_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", - "candidate_sha256": "ab560235d23e2dcd5256467f1dba03bb4eee7d675250ccf9054c3d8a670c508e", - "raw_report_sha256": "cccabf99871f8fe7d62ac42fdedd6d77394157fdd41a490ff42f324104565184", - "role_note": "The runner labels the new registered optimized source as reference and the explicit accepted-parent source as candidate. Factor speedup below is parent_sec/factor_sec.", - "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", - "cpus": 6, - "memory": "7g", - "passing_cells": 12, - "pairs": [ - {"pair": 1, "order": "factor->parent", "parent_sec": 4.512375, "factor_sec": 4.422352, "speedup": 1.0203563624062488}, - {"pair": 2, "order": "parent->factor", "parent_sec": 4.525156, "factor_sec": 4.983842, "speedup": 0.9079653809249972}, - {"pair": 3, "order": "factor->parent", "parent_sec": 4.536363, "factor_sec": 4.385974, "speedup": 1.0342886209539772}, - {"pair": 4, "order": "parent->factor", "parent_sec": 4.623152, "factor_sec": 4.35917, "speedup": 1.0605578584914102}, - {"pair": 5, "order": "factor->parent", "parent_sec": 4.600339, "factor_sec": 4.314358, "speedup": 1.066285876137307}, - {"pair": 6, "order": "parent->factor", "parent_sec": 4.748949, "factor_sec": 4.486073, "speedup": 1.0585982439429762} - ], - "parent_mean_sec": 4.591055666666667, - "parent_median_sec": 4.568351, - "parent_stderr_sec": 0.0363186640555208, - "factor_mean_sec": 4.4919615, - "factor_median_sec": 4.4041630000000005, - "factor_stderr_sec": 0.10119889970473989, - "mean_paired_speedup": 1.0246753904761527, - "paired_speedup_stderr": 0.024428152166625212, - "paired_speedup_95pct_t_ci": [0.9618808262384664, 1.0874699547138391], - "factor_wins": 5, - "decision": "discard_inconclusive" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-equivalence.json deleted file mode 100644 index fc08935..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-equivalence.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "aux_max_error": 0.0, - "gradient_max_error": 3.91155481338501e-08, - "hamiltonian_action_max_error": 1.665520539972931e-05, - "history_max_abs_errors": { - "energy_density_history": 1.1920928955078125e-06, - "entropy_history": 5.662441253662109e-07, - "entropy_mse_history": 5.662441253662109e-07, - "loss_history": 1.1920928955078125e-06 - }, - "loss_abs_error": 0.0, - "passed": true, - "schema_version": 1, - "steps": 12, - "task_id": "02" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-paired.json b/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-paired.json deleted file mode 100644 index f09ffc9..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e04-sparse-xxz-paired.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "schema_version": 1, - "task_id": "02", - "factor": "tensorcircuit_sparse_xxz", - "parent_commit": "edf1e91", - "parent_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", - "candidate_sha256": "c5997e6147212271ec45321880a14d696849a6436fb99f16a02b72fc42992942", - "raw_report_sha256": "8bfba5d0d90cde8ddb571e38d975044e5ea50001e9581a1a617a13fe9bca6c12", - "role_note": "The runner labels the new registered optimized source as reference and the explicit accepted-parent source as candidate. Factor speedup below is parent_sec/factor_sec.", - "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", - "cpus": 6, - "memory": "7g", - "passing_cells": 12, - "pairs": [ - {"pair": 1, "order": "factor->parent", "parent_sec": 4.298455, "factor_sec": 4.516255, "speedup": 0.9517742022981429}, - {"pair": 2, "order": "parent->factor", "parent_sec": 4.283501, "factor_sec": 4.439776, "speedup": 0.9648011521301976}, - {"pair": 3, "order": "factor->parent", "parent_sec": 4.380654, "factor_sec": 4.363093, "speedup": 1.004024897016864}, - {"pair": 4, "order": "parent->factor", "parent_sec": 4.221151, "factor_sec": 4.393876, "speedup": 0.9606896052596842}, - {"pair": 5, "order": "factor->parent", "parent_sec": 4.206659, "factor_sec": 4.410758, "speedup": 0.9537270011186285}, - {"pair": 6, "order": "parent->factor", "parent_sec": 4.389762, "factor_sec": 4.379807, "speedup": 1.002272931204503} - ], - "parent_mean_sec": 4.296697, - "parent_median_sec": 4.290978, - "parent_stderr_sec": 0.03146486750541519, - "factor_mean_sec": 4.417260833333334, - "factor_median_sec": 4.402317, - "factor_stderr_sec": 0.022533574087594568, - "mean_paired_speedup": 0.97288163150467, - "paired_speedup_stderr": 0.00976407457404015, - "paired_speedup_95pct_t_ci": [0.947782278762844, 0.997980984246496], - "factor_wins": 2, - "decision": "discard" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e05-packed-params-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e05-packed-params-equivalence.json deleted file mode 100644 index a55b577..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e05-packed-params-equivalence.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "aux_max_error": 0.0, - "gradient_max_error": 0.0, - "history_max_abs_errors": { - "energy_density_history": 0.0, - "entropy_history": 0.0, - "entropy_mse_history": 0.0, - "loss_history": 0.0 - }, - "loss_abs_error": 0.0, - "parameter_max_error": 0.0, - "passed": true, - "schema_version": 1, - "steps": 12, - "task_id": "02" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e05-packed-params-paired.json b/optimized_solutions/challenge-02/research/profiles/e05-packed-params-paired.json deleted file mode 100644 index 17ff005..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e05-packed-params-paired.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "schema_version": 1, - "task_id": "02", - "factor": "single_leaf_parameter_packing", - "parent_commit": "edf1e91", - "parent_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", - "candidate_sha256": "895ede0c511e60221400a85066b036ab57fce683df614a2cabb389e928826b70", - "raw_report_sha256": "b24d2fbeb2094e23f2353b94a71896dc6b1f506bf6eea600b14536aa7d7617fb", - "role_note": "The runner labels the new registered optimized source as reference and the explicit accepted-parent source as candidate. Factor speedup below is parent_sec/factor_sec.", - "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", - "cpus": 6, - "memory": "7g", - "passing_cells": 12, - "pairs": [ - {"pair": 1, "order": "factor->parent", "parent_sec": 4.443677, "factor_sec": 10.455023, "speedup": 0.4250279506797833}, - {"pair": 2, "order": "parent->factor", "parent_sec": 4.411176, "factor_sec": 10.728046, "speedup": 0.41118168210688133}, - {"pair": 3, "order": "factor->parent", "parent_sec": 4.529836, "factor_sec": 10.895188, "speedup": 0.4157648312264094}, - {"pair": 4, "order": "parent->factor", "parent_sec": 4.512273, "factor_sec": 10.68515, "speedup": 0.4222938377093443}, - {"pair": 5, "order": "factor->parent", "parent_sec": 4.886009, "factor_sec": 11.055362, "speedup": 0.4419583004156715}, - {"pair": 6, "order": "parent->factor", "parent_sec": 4.77443, "factor_sec": 10.56624, "speedup": 0.4518570465936794} - ], - "parent_mean_sec": 4.5929001666666665, - "parent_median_sec": 4.5210545, - "parent_stderr_sec": 0.07845060524747038, - "factor_mean_sec": 10.730834833333333, - "factor_median_sec": 10.706598, - "factor_stderr_sec": 0.08899220067939155, - "mean_paired_speedup": 0.42801394145529487, - "paired_speedup_stderr": 0.006423758488100811, - "paired_speedup_95pct_t_ci": [0.4115011445692684, 0.44452673834132134], - "factor_wins": 0, - "decision": "discard" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-equivalence.json deleted file mode 100644 index 18c9871..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-equivalence.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "aux_max_error": 0.0, - "gradient_max_error": 1.862645149230957e-08, - "history_max_abs_errors": { - "energy_density_history": 7.152557373046875e-07, - "entropy_history": 6.183981895446777e-07, - "entropy_mse_history": 4.172325134277344e-07, - "loss_history": 8.344650268554688e-07 - }, - "loss_abs_error": 0.0, - "passed": true, - "schema_version": 1, - "steps": 12, - "task_id": "02" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-paired.json b/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-paired.json deleted file mode 100644 index 1f12a21..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e06-entropy-vmap-paired.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "schema_version": 1, - "task_id": "02", - "factor": "checkpoint_entropy_k_vmap", - "parent_commit": "edf1e91", - "parent_sha256": "6e44df512170e071655eee7697f7a0c084704dd34c266f441b2755cb1f29bc1a", - "candidate_sha256": "c9c7840740152f03f23ddbc50379098847508007288da397ecf592952204cdb2", - "raw_report_sha256": "a43cd8242d76503057c88e4de2ee7b702965ecf89c41643b21ba4d8664d13a97", - "role_note": "The runner labels the new registered optimized source as reference and the explicit accepted-parent source as candidate. Factor speedup below is parent_sec/factor_sec.", - "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", - "cpus": 6, - "memory": "7g", - "passing_cells": 12, - "pairs": [ - {"pair": 1, "order": "factor->parent", "parent_sec": 4.667179, "factor_sec": 4.432862, "speedup": 1.0528590784012677}, - {"pair": 2, "order": "parent->factor", "parent_sec": 4.546249, "factor_sec": 4.078218, "speedup": 1.1147636050843777}, - {"pair": 3, "order": "factor->parent", "parent_sec": 4.735712, "factor_sec": 4.389429, "speedup": 1.0788902155610673}, - {"pair": 4, "order": "parent->factor", "parent_sec": 4.890732, "factor_sec": 4.788164, "speedup": 1.021421154329718}, - {"pair": 5, "order": "factor->parent", "parent_sec": 5.01748, "factor_sec": 5.302995, "speedup": 0.9461596701486612}, - {"pair": 6, "order": "parent->factor", "parent_sec": 4.738252, "factor_sec": 4.442364, "speedup": 1.0666059782584227} - ], - "parent_mean_sec": 4.765934, - "parent_median_sec": 4.736982, - "parent_stderr_sec": 0.06795676139477703, - "factor_mean_sec": 4.572338666666667, - "factor_median_sec": 4.437613000000001, - "factor_stderr_sec": 0.17266514663314209, - "mean_paired_speedup": 1.0467832836305857, - "paired_speedup_stderr": 0.023699776989237024, - "paired_speedup_95pct_t_ci": [0.9858610673934217, 1.1077054998677496], - "factor_wins": 5, - "decision": "discard_inconclusive" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-equivalence.json deleted file mode 100644 index 9db78c7..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-equivalence.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "aux_max_error": 2.9803231882397085e-07, - "gradient_max_error": 1.210719347000122e-08, - "history_max_abs_errors": { - "energy_density_history": 1.0728836059570312e-06, - "entropy_history": 8.717179298400879e-07, - "entropy_mse_history": 5.662441253662109e-07, - "loss_history": 1.0728836059570312e-06 - }, - "loss_abs_error": 0.0, - "passed": true, - "schema_version": 1, - "steps": 12, - "task_id": "02" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-paired.json b/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-paired.json deleted file mode 100644 index f7bf00e..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e07-batched-purity-paired.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "schema_version": 1, - "task_id": "02", - "factor": "checkpoint_vmap_plus_frobenius_purity", - "parent": "whole_training_k_jaxy_scan", - "candidate_sha256": "181c0459c8194aa259be813e23896d3c70691adf5999a26353fe57cab14d3f3d", - "raw_report_sha256": "6dd10f3c24054668734022000058391c192c87f0554d404a6d3b7d61593ee07e", - "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", - "cpus": 6, - "memory": "7g", - "passing_cells": 12, - "role_note": "The runner's registered optimized role is this factor and its explicit candidate role is the parent; ratios below are normalized as parent/factor.", - "pairs": [ - { - "pair": 1, - "order": "factor->parent", - "parent_sec": 4.455414, - "factor_sec": 4.334005, - "speedup": 1.0280131195049382 - }, - { - "pair": 2, - "order": "parent->factor", - "parent_sec": 4.565881, - "factor_sec": 4.164098, - "speedup": 1.0964874025539264 - }, - { - "pair": 3, - "order": "factor->parent", - "parent_sec": 4.534834, - "factor_sec": 4.265577, - "speedup": 1.063123230456278 - }, - { - "pair": 4, - "order": "parent->factor", - "parent_sec": 4.502713, - "factor_sec": 4.151774, - "speedup": 1.0845274815054964 - }, - { - "pair": 5, - "order": "factor->parent", - "parent_sec": 4.58468, - "factor_sec": 4.133233, - "speedup": 1.1092236997043234 - }, - { - "pair": 6, - "order": "parent->factor", - "parent_sec": 4.543243, - "factor_sec": 4.264484, - "speedup": 1.0653675802277602 - } - ], - "parent_mean_sec": 4.5311275, - "parent_median_sec": 4.5390385, - "parent_stderr_sec": 0.01895267561893742, - "factor_mean_sec": 4.218861833333333, - "factor_median_sec": 4.214291, - "factor_stderr_sec": 0.03283990947959184, - "mean_paired_speedup": 1.0744570856587872, - "paired_speedup_stderr": 0.011780750629781522, - "paired_speedup_95pct_t_ci": [ - 1.0441737020681832, - 1.1047404692493912 - ], - "candidate_wins": 6, - "decision": "keep" -} diff --git a/optimized_solutions/challenge-02/research/profiles/e08-purestate-purity-equivalence.json b/optimized_solutions/challenge-02/research/profiles/e08-purestate-purity-equivalence.json deleted file mode 100644 index 38f6375..0000000 --- a/optimized_solutions/challenge-02/research/profiles/e08-purestate-purity-equivalence.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "aux_max_error": 2.503933501429856e-06, - "gradient_max_error": 3.771856427192688e-08, - "history_max_abs_errors": { - "energy_density_history": 1.0728836059570312e-06, - "entropy_history": 5.348585546016693e-06, - "entropy_mse_history": 3.844499588012695e-06, - "loss_history": 1.7881393432617188e-06 - }, - "loss_abs_error": 5.960464477539062e-07, - "passed": false, - "schema_version": 1, - "steps": 12, - "task_id": "02" -} diff --git a/optimized_solutions/challenge-02/research/profiles/final-equivalence.json b/optimized_solutions/challenge-02/research/profiles/final-equivalence.json deleted file mode 100644 index b07c834..0000000 --- a/optimized_solutions/challenge-02/research/profiles/final-equivalence.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "schema_version": 1, - "task_id": "02", - "candidate_sha256": "aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30", - "steps": 12, - "loss_abs_error": 0.0, - "aux_max_error": 2.9803231882397085e-07, - "gradient_max_error": 1.210719347000122e-08, - "history_max_abs_errors": { - "energy_density_history": 1.0728836059570312e-06, - "entropy_history": 8.717179298400879e-07, - "entropy_mse_history": 5.662441253662109e-07, - "loss_history": 1.0728836059570312e-06 - }, - "passed": true -} diff --git a/optimized_solutions/challenge-02/research/profiles/final-reference-paired.json b/optimized_solutions/challenge-02/research/profiles/final-reference-paired.json deleted file mode 100644 index cd4761e..0000000 --- a/optimized_solutions/challenge-02/research/profiles/final-reference-paired.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "schema_version": 1, - "task_id": "02", - "candidate": "whole_training_scan_plus_batched_exact_purity", - "parent": "immutable_reference", - "candidate_sha256": "aef3652f8d80ec6f3e414f9496295b8b852db2b256ec414f4146b3a636485b30", - "raw_report_sha256": "27ec959f8e23156a0c8f0b15bb0f122b86e3a32e1842764888ef90eb07a842dd", - "environment_image_id": "sha256:b059c5fa7f75702f9afbf94ec7866e102ac32afd59d25634ec0aca0fd56e2833", - "cpus": 6, - "memory": "7g", - "passing_cells": 12, - "pairs": [ - {"pair": 1, "order": "reference->candidate", "reference_sec": 4.865151, "candidate_sec": 3.981228, "speedup": 1.2220227025430344}, - {"pair": 2, "order": "candidate->reference", "reference_sec": 4.364947, "candidate_sec": 4.042312, "speedup": 1.0798144725097913}, - {"pair": 3, "order": "reference->candidate", "reference_sec": 4.411195, "candidate_sec": 4.134876, "speedup": 1.0668264296196548}, - {"pair": 4, "order": "candidate->reference", "reference_sec": 4.457106, "candidate_sec": 4.007787, "speedup": 1.1121114969433255}, - {"pair": 5, "order": "reference->candidate", "reference_sec": 4.432053, "candidate_sec": 4.030015, "speedup": 1.0997609190040236}, - {"pair": 6, "order": "candidate->reference", "reference_sec": 4.442327, "candidate_sec": 3.990016, "speedup": 1.1133606983029642} - ], - "reference_mean_sec": 4.495463166666666, - "reference_median_sec": 4.437189999999999, - "reference_stderr_sec": 0.07508223524217374, - "candidate_mean_sec": 4.031039, - "candidate_median_sec": 4.018901, - "candidate_stderr_sec": 0.022814417538039422, - "mean_paired_speedup": 1.115649453153799, - "paired_speedup_stderr": 0.02254869005858174, - "paired_speedup_95pct_t_ci": [1.0576862000497536, 1.1736127062578445], - "paired_improvement_pct_mean": 10.192991792502323, - "candidate_wins": 6, - "first_five": { - "reference_mean_sec": 4.5060904, - "candidate_mean_sec": 4.0392436, - "mean_paired_speedup": 1.116107204123966, - "pooled_improvement_pct": 10.36035140351379 - }, - "decision": "keep" -} diff --git a/optimized_solutions/challenge-02/research/profiles/reference-profile.json b/optimized_solutions/challenge-02/research/profiles/reference-profile.json deleted file mode 100644 index 1aa4d21..0000000 --- a/optimized_solutions/challenge-02/research/profiles/reference-profile.json +++ /dev/null @@ -1,128 +0,0 @@ -{ - "evaluator_sha256": "0d9360d4812d033d364253dd478444f68918f1b05f04146eddcb846a3dca3a1e", - "jax": "0.10.0", - "profile": { - "energy": { - "compile_sec": 0.1393681839981582, - "stablehlo_lines": 353, - "steady": { - "mean_sec": 0.00017614391739092147, - "median_sec": 0.00015538899606326595, - "values_sec": [ - 0.0003872419911203906, - 0.00015651399735361338, - 0.00015080500452313572, - 0.0001725570036796853, - 0.00015201300266198814, - 0.0001593469933141023, - 0.0001772660034475848, - 0.00015963900659698993, - 0.00015126400103326887, - 0.0001425119990017265, - 0.00015426399477291852, - 0.0001503040111856535 - ] - } - }, - "loss": { - "cold_execute_sec": 0.0012416509998729452, - "compile_sec": 0.6459185569983674, - "lower_sec": 0.14026911799737718, - "stablehlo_lines": 5622, - "steady": { - "mean_sec": 0.0009508372483348163, - "median_sec": 0.0009437499975319952, - "values_sec": [ - 0.0009708770085126162, - 0.0009170800040010363, - 0.0009110800019698218, - 0.0009102469921344891, - 0.0008927449962357059, - 0.0009665859979577363, - 0.0009920039883581921, - 0.0010103810054715723, - 0.0009297069918829948, - 0.0010416750010335818, - 0.0009098719892790541, - 0.0009577930031809956 - ] - } - }, - "one_entropy": { - "compile_sec": 0.04879616999824066, - "stablehlo_lines": 54, - "steady": { - "mean_sec": 0.0001318761678703595, - "median_sec": 0.00012436549877747893, - "values_sec": [ - 0.0002572310040704906, - 0.00012951099779456854, - 0.00012413600052241236, - 0.0001245949970325455, - 0.00012934500409755856, - 0.00012742800754494965, - 0.00012596900342032313, - 0.000120801996672526, - 0.00011084300058428198, - 0.00011084300058428198, - 0.00011113499931525439, - 0.00011067600280512124 - ] - } - }, - "train_step": { - "cold_execute_sec": 0.0039121360023273155, - "compile_sec": 1.9297688599908724, - "lower_sec": 0.8031583569973009, - "stablehlo_lines": 15479, - "steady": { - "mean_sec": 0.002643305668849886, - "median_sec": 0.0026212515076622367, - "values_sec": [ - 0.00272540700098034, - 0.0028315410017967224, - 0.002842875008354895, - 0.002633648007758893, - 0.0026088550075655803, - 0.0025580170040484518, - 0.0025170549924951047, - 0.0025212639884557575, - 0.002743407996604219, - 0.002673277005669661, - 0.0025122210063273087, - 0.0025521000061417 - ] - } - }, - "trajectory": { - "cold_execute_sec": 0.0015485950134461746, - "compile_sec": 0.5833363940037088, - "lower_sec": 0.10015145600482356, - "stablehlo_lines": 5262, - "steady": { - "mean_sec": 0.0008888770001552378, - "median_sec": 0.0008625339978607371, - "values_sec": [ - 0.000961875994107686, - 0.0010673859942471609, - 0.0009131219994742423, - 0.0008702440100023523, - 0.0008600750006735325, - 0.0008363239903701469, - 0.000827490002848208, - 0.0008424910047324374, - 0.0009439580026082695, - 0.0008649929950479418, - 0.0008486169972456992, - 0.0008299480105051771 - ] - } - } - }, - "projected_500_train_steps_sec": 1.321652834424943, - "reference_sha256": "cd5776dfb223924edd83795bd8222032351008a584b55d747110521c709dcdd3", - "repeat": 12, - "schema_version": 1, - "task_id": "02", - "tensorcircuit": "1.8.0.dev20260726" -} From ade2f77a48be18c08d96bd49a3d80c2046361889 Mon Sep 17 00:00:00 2001 From: qingyunqian Date: Thu, 30 Jul 2026 13:34:05 +0800 Subject: [PATCH 3/3] Clarify Task 02 factor attribution --- optimized_solutions/challenge-02/README.md | 7 +- .../challenge-02/factor-ablation.svg | 613 ++++++++++++++++-- 2 files changed, 576 insertions(+), 44 deletions(-) diff --git a/optimized_solutions/challenge-02/README.md b/optimized_solutions/challenge-02/README.md index f9c6c91..6232d88 100644 --- a/optimized_solutions/challenge-02/README.md +++ b/optimized_solutions/challenge-02/README.md @@ -21,7 +21,12 @@ direct parent, so retained rows are incremental rather than cumulative. | E06 | Checkpoint entropy `K.vmap` alone | 1.047x | Discard (inconclusive) | | E07 | `K.vmap` plus exact Frobenius purity | **1.074x** | **Keep** | -![Incremental factor speedups and final cumulative result](factor-ablation.svg) +![Task 02 direct factor-removal and rejected-variant comparisons](factor-ablation.svg) + +*Figure — Each panel normalizes its recommended direct parent to `1.0x`. +Removing the two accepted factors causes modest slowdowns; packing the +parameter PyTree is the largest measured regression. Ratios come from direct +matched-parent experiments and are not multiplied.* ## What the factors mean diff --git a/optimized_solutions/challenge-02/factor-ablation.svg b/optimized_solutions/challenge-02/factor-ablation.svg index 0a94919..5434b25 100644 --- a/optimized_solutions/challenge-02/factor-ablation.svg +++ b/optimized_solutions/challenge-02/factor-ablation.svg @@ -1,44 +1,571 @@ - - Task 02 factor ablation - Incremental paired speedups for seven tested factors and the cumulative end-to-end result. - - - Task 02 factor ablation - Individual factors are incremental vs their parent; final is cumulative vs the expert - - - - - - - - E01 · Gate fusion - 0.966× - E02 · Training scan - 1.036× - E03 · Frobenius purity - 1.025× - E04 · Sparse XXZ - 0.973× - E05 · Packed parameters - 0.428× - E06 · Entropy vmap - 1.047× - E07 · Batched purity - 1.074× - - - Final cumulative - 1.116× - - 0.4× - 0.6× - 0.8× - 1.0× - 1.2× - Dashed line: 1× no change · green: kept · red: discarded · blue: final cumulative + + + + + + + + image/svg+xml + + + Matplotlib v3.10.8, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + With factor + + + + + + + + + + Without factor + + + + + + + + + + + + + + + + + + 0.0 + + + + + + + + + + + + + 0.2 + + + + + + + + + + + + + 0.4 + + + + + + + + + + + + + 0.6 + + + + + + + + + + + + + 0.8 + + + + + + + + + + + + + 1.0 + + + + Runtime normalized to recommended + + + + + + + + + + + + + + + + 6 matched pairs + + + a + + + 1.000× + + + 1.074× + + + Batched exact purity → generic entropy + + + + + + + + + + + + + + + + + + With factor + + + + + + + + + + Without factor + + + + + + + + + + + + + + + 0.0 + + + + + + + + + + + + + 0.2 + + + + + + + + + + + + + 0.4 + + + + + + + + + + + + + 0.6 + + + + + + + + + + + + + 0.8 + + + + + + + + + + + + + 1.0 + + + + + + + + + + + + + + + + + 6 matched pairs + + + b + + + 1.000× + + + 1.036× + + + Training scan → Python dispatch + + + + + + + + + + + + + + + + + + Recommended + + + + + + + + + + Rejected variant + + + + + + + + + + + + + + + 0.0 + + + + + + + + + + + + + 0.5 + + + + + + + + + + + + + 1.0 + + + + + + + + + + + + + 1.5 + + + + + + + + + + + + + 2.0 + + + + + + + + + + + + + 2.5 + + + + + + + + + + + + + + + + + 6 matched pairs + + + c + + + 1.000× + + + 2.336× + + + PyTree parameters → packed leaf + + + + + + + Task 02 factor ablations — two modest gains; packed parameters strongly regress + + + Direct matched-parent ratios; final end-to-end speedup 1.116×. The third panel shows the rejected packed-parameter variant. + + + + + + + + + + + + +