Skip to content

Fix magnetic-field sign, add fast HF Fock path, and restore green CI - #9

Open
skilledwolf wants to merge 6 commits into
mainfrom
claude/great-borg-168d60
Open

skilledwolf wants to merge 6 commits into
mainfrom
claude/great-borg-168d60

Conversation

@skilledwolf

Copy link
Copy Markdown
Owner

Summary

  • bcc1f14 Fix magnetic-field sign convention in exchange kernels
  • 80470b3 Add fast HF-convention Fock-apply path
  • 6affdb7 Inline the MacDonald-Ritchie Eq. (13) reference in tests/test_symmetric_onebody.py. It used to load the untracked playground/ helper, which broke collection in CI.
  • 35f6efe Give compare_exchange_backends, plot_form_factors_radial and plot_exchange_kernels_radial valid RST titles, and fix the list indentation and the bare |G|, which docutils read as a substitution, so sphinx -W passes
  • e3cb20f Fix ruff errors: drop the unused full-tensor imports in fock.py, sort the imports (I001), and fix PERF401 with itertools.product
  • 958093a Bump actions/checkout to v5 and actions/setup-python to v6 (Node 24)

Verification

Checked locally in a clean clone without playground/:

  • ruff check . passes
  • mypy passes
  • pytest -m "not release" passes
  • python -m sphinx -W --keep-going -b html docs <tmp> exits 0

🤖 Generated with Claude Code

skilledwolf and others added 6 commits April 24, 2026 17:02
Versions <= 1.1.x silently inverted sign_magneticfield relative to the
analytic convention documented in docs/conventions.md: a caller-supplied
sign_magneticfield=X produced results corresponding to sigma=-X. This
affected every backend (laguerre, ogata, hankel, legendre) and the fast
Fock-apply path. For Hermitian single-LL densities the hidden identity
X^sigma[a,b,p,q] = X^{-sigma}[p,q,a,b] masked the bug, but multi-LL
contractions and anything reading the literal kernel values were wrong
(~1% on representative hex WC benchmarks).

Fixes in this release:

- _evaluate_exchange_kernels_laguerre_numba and _ogata_q_evaluate_numba:
  relabel d_in = m2 - n2, d_out = m1 - n1 and access
  phase_in[d_in] * phase_out[d_out], matching the analytic phase
  i^{a_tot} (-1)^{d_in} exp(i sigma (d_out - d_in) theta).
- exchange_ogata, exchange_hankel, exchange_legendre: invert the gating
  of the post-hoc sign-flip branch so sign_magneticfield=X yields sigma=X.
- _exchange_fock_numba: restructure so it applies X as the canonical
  (n1,m1) -> (n2,m2) linear map used throughout the rest of the library
  (including _build_compressed_constructor) instead of the transposed
  (n2,m2) -> (n1,m1) map it was silently implementing.

Added tests/test_coulomb_analytic_general.py, which gates every backend
x sign_magneticfield = +/-1 against an mpmath closed-form Coulomb
integral, plus cross-backend and form-factor <-> exchange-kernel
consistency checks.

Docs/README now carry a prominent warning about the historical bug and
link to CHANGELOG.md. Callers that must reproduce pre-1.2.0 numerics
should pin quantumhall-matrixelements<1.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The HF-convention exchange Fock apply (used by quantumhall_hf) lacked
a counterpart to the Numba-JIT fast path that exists for the standard
convention. Previously get_fockmatrix_constructor_hf always built the
compressed (values, select) representation and applied it via vectorized
np.add.at — fast at nmax=1,2 but bottlenecked at nmax >= 3.

For the default method='laguerre' case, get_fockmatrix_constructor_hf
now materializes the full kernel tensor once and applies via BLAS-backed
np.einsum (with a precomputed contraction path). Measured ~3.4x speedup
at nmax=4, ~10x at nmax=8; roughly tied at nmax=1,2. Falls back to the
compressed apply if the full tensor would exceed memory limits.

Also adds ExchangeFockPrecompute.exchange_fock_hf, a Numba HF apply
that mirrors exchange_fock for the HF index pattern (cost O(nmax^4 * Nq)
per G; useful as a reference / for memory-constrained workloads).

New test cross-checks the fast HF path against the existing compressed
apply for nmax in {1..4} and both sign_magneticfield choices.

100/100 matrixelements tests pass; 144/144 quantumhall_hf tests pass.
The test loaded a helper from the untracked playground/ directory at
import time, so collection failed in CI. Inline the independent Eq. (13)
closed form instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sphinx-gallery requires a titled docstring; sphinx -W failed on three
examples without one. Also fix the list indentation and bare |G| that
docutils parsed as a substitution.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop unused full-tensor imports from fock.py, sort imports in the HF
constructor test, and build the exhaustive select list with
itertools.product.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant