Rayon topphatt#195
Merged
Merged
Conversation
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
Contributor
Merging this PR will improve performance by 6.99%
|
| 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)
Footnotes
-
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. ↩
0068586 to
a4fb184
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_whileand there is no built in rayon fold_while.It's actually possible to have each use the single thread fold_while.