Optimise Davidson Hv: precompute connected pairs, vmap element kernel, batched MGS#8
Draft
Copilot wants to merge 3 commits into
Draft
Optimise Davidson Hv: precompute connected pairs, vmap element kernel, batched MGS#8Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
Agent-Logs-Url: https://github.com/jphaupt/CIPSIpy/sessions/041213a4-3359-43a6-833d-411eaa4193d8 Co-authored-by: jphaupt <10662835+jphaupt@users.noreply.github.com>
Agent-Logs-Url: https://github.com/jphaupt/CIPSIpy/sessions/041213a4-3359-43a6-833d-411eaa4193d8 Co-authored-by: jphaupt <10662835+jphaupt@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
jphaupt
April 3, 2026 10:14
View session
Owner
|
@copilot If you're going to use acronyms, please always define it at least once (when first using it). For example, I am not sure what MGS is in this context. |
Agent-Logs-Url: https://github.com/jphaupt/CIPSIpy/sessions/7362fbc9-cf5d-4c0b-8db7-788edf8585c1 Co-authored-by: jphaupt <10662835+jphaupt@users.noreply.github.com>
Contributor
Author
Done — "MGS" is now written out as "modified Gram-Schmidt (MGS)" on its first use in |
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.
Profiling showed
hamiltonian_vector_product(three Python loops over connected pairs, called ~14×/diagonalisation) dominated runtime at 72% of total wall time. This PR eliminates those loops by precomputing the pair structure once and replacing the inner loop with a single JIT+vmap scatter-add.Changes
determinants.py— JAX-native bitwise helpers + pair precomputationjax_popcount,excitation_level_jax,first_set_bit_pos_jax,two_set_bit_pos_jax,phase_single_jax,phase_double_jax: pure-JAX implementations of the scalar kernels using only bitwise ops andjnp.where— no Pythonif/else, fully vmappable.precompute_connections(dets_alpha, dets_beta, norb)→(row_idx, col_idx): runs the existing sort/generator logic once per diagonalisation and returns all three connection types (β singles/doubles, opposite-spin doubles, α singles/doubles) as flat JAXint32index arrays with no duplicates.hamiltonian.py— vmappable element kernel + JIT-compiled matvec_single_excitation_element_spin_jax,_double_same_spin_element_jax,_double_opposite_spin_element_jax: branch-free sub-kernels safe forjax.vmap.hamiltonian_element_batch: top-level vmappable element function; selects the correct sub-kernel via nestedjnp.where(all five excitation types evaluated; wrong branches produce finite values masked out, no NaN propagation).precompute_h_vals(dets_alpha, dets_beta, row_idx, col_idx, norb, h_core, eri): JIT-compiled, computes allH_ijin onejax.vmapcall — called once before Davidson starts.scatter_add_matvec(coeffs, diag_h, h_vals, row_idx, col_idx): JIT-compiled matvec using scatter-add, zero Python loops:cipsi.py— wire up fast path in_diagonalise_variational_spaceReplaced the
hamiltonian_vector_productclosure with:h_valsis computed once; all ~14 Davidson matvec calls reuse it.diagonaliser.py— batched MGS projectionReplaced the
for k in range(m)Gram-Schmidt loop (O(m) Python iterations growing with subspace size) with a single batched projection, valid becauseV_mmaintains orthonormal columns throughout: