Skip to content

Rayon topphatt#195

Merged
MIWdlB merged 3 commits into
mainfrom
rayon-topphatt
Jun 16, 2026
Merged

Rayon topphatt#195
MIWdlB merged 3 commits into
mainfrom
rayon-topphatt

Conversation

@MIWdlB

@MIWdlB MIWdlB commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Converts the inner loop of topphatt to use a rayon thread pool, rather than manually splitting the work between threads.

The rationale for doing the original implementation was that we use an early exit in fold_while and there is no built in rayon fold_while.

It's actually possible to have each use the single thread fold_while.

claude added 2 commits June 14, 2026 08:51
Replace the manual scoped-thread pool and its Mutex-on-iterator /
RwLock-on-selection with a rayon parallel iterator over the materialised
cartesian product, reduced by an associative, deterministic combine.

The branch-and-bound early-exit is preserved by sharing the running minimum
weight in a lock-free AtomicUsize (Relaxed): every combination reads it to
prune work and lowers it via fetch_min, while the authoritative winner is
chosen by the reduction. Pruning only abandons combinations whose partial
weight already exceeds the bound, so no tying or winning combination is ever
discarded and the result stays reproducible. Tie-breaking is factored into
packed_leaf_indices, reproducing the previous little-endian ordering without
unsafe transmute.

Drops the now-unused num_cpus dependency in favour of rayon's global pool.

https://claude.ai/code/session_01T4QxUoLeq6s48R4pSAfftB
Adds a new MajoranaSparse pyclass exposed from ferrmion.core, and
FermionHamiltonian.to_majorana_sparse() to obtain one. topphatt now
takes this directly rather than converting from FermionHamiltonian
internally, letting callers reuse a single conversion across calls.

https://claude.ai/code/session_01P7kgYKgnK3DWAVnJa8eRjv
@codspeed-hq

codspeed-hq Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 6.99%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 8 improved benchmarks
❌ 3 (👁 3) regressed benchmarks
✅ 45 untouched benchmarks
⏩ 64 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation test_benchmark_batch_pauli_weights[1000-JordanWigner] 9.2 s 8.1 s +13.26%
Simulation test_benchmark_batch_pauli_weights[1000-BravyiKitaev] 9.2 s 8.1 s +13.25%
Simulation test_benchmark_batch_pauli_weights[500-JordanWigner] 4.6 s 4.1 s +13.16%
Simulation test_benchmark_batch_pauli_weights[500-BravyiKitaev] 4.6 s 4.1 s +13.15%
Simulation test_benchmark_batch_pauli_weights[100-JordanWigner] 973.6 ms 866.2 ms +12.39%
Simulation test_benchmark_batch_pauli_weights[100-BravyiKitaev] 973.9 ms 866.7 ms +12.37%
Simulation test_benchmark_batch_pauli_weights[10-BravyiKitaev] 154.2 ms 143.4 ms +7.48%
Simulation test_benchmark_batch_pauli_weights[10-JordanWigner] 154.3 ms 143.6 ms +7.47%
👁 Simulation test_benchmark_encode_topphatt[h2_6-31g-bravyi_kitaev] 7.9 ms 8.1 ms -3.07%
👁 Simulation test_benchmark_encode_topphatt[h2_6-31g-jkmn] 8.6 ms 9.1 ms -5.84%
👁 Simulation test_benchmark_encode_topphatt[h2o_6-31g-jkmn] 4.5 s 4.7 s -3.85%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing rayon-topphatt (cb3bf1d) with main (07ce869)

Open in CodSpeed

Footnotes

  1. 64 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@MIWdlB MIWdlB force-pushed the rayon-topphatt branch 4 times, most recently from 0068586 to a4fb184 Compare June 16, 2026 12:25
@MIWdlB MIWdlB merged commit 061eaa5 into main Jun 16, 2026
5 checks passed
@MIWdlB MIWdlB deleted the rayon-topphatt branch June 16, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants