feat: CAS active-space support for 40-58 qubit molecules (Issue #21 Phase 1)#22
Conversation
…uantumNoLab#21 Phase 1) Add CASSCF/CASCI support to compute_molecular_integrals via `cas` and `casci` parameters. When `cas=(nelecas, ncas)` is provided, runs CASSCF (or CASCI for ncas>=15 / >50M configs) and returns active-space integrals with nuclear_repulsion=e_core (frozen-core energy, NOT mol.energy_nuc()). New molecule factories: - _make_n2_cas: N₂ CAS with auto-CASCI for large active spaces - _make_cr2: Cr₂ with fix_spin_(ss=0) for singlet ground state - _make_benzene: Benzene CAS(6,15) Registry additions (12 new entries, 24→24 total): - N₂-CAS(10,12/15/17/20/26): 24-52 qubits - Cr₂ + Cr₂-CAS(12,18/20/26/28/29): 24-58 qubits - Benzene CAS(6,15): 30 qubits Cache: CAS integrals bypass joblib cache (CASSCF non-deterministic). TDD: 21 new tests (19 integrals + 2 registry completeness). All verified: N₂ CAS(10,8) e_core=-77.38 Ha (not E_nuc=23.57 Ha).
There was a problem hiding this comment.
Pull request overview
Adds CAS active-space integral generation and registers new large-qubit benchmark molecules, enabling 40–58 qubit workflows via PySCF CASSCF/CASCI integration.
Changes:
- Extend
compute_molecular_integrals/cached_compute_molecular_integralswithcas=(nelecas, ncas)andcascito produce active-space integrals (with auto-CASCI switching for large spaces). - Add CAS-capable molecule factories + 12 CAS registry entries (N₂-CAS variants, Cr₂ variants, Benzene).
- Add new PySCF-marked slow tests for CAS integrals and CAS molecule factories/registry entries.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
src/qvartools/hamiltonians/integrals.py |
Introduces CAS/CASCI codepath and cache-bypass behavior for CAS in the cached helper. |
src/qvartools/molecules/registry.py |
Adds CAS geometries/factories and registers N₂/Cr₂/Benzene CAS entries. |
tests/test_hamiltonians/test_cas_integrals.py |
Adds CAS integral tests (shapes, e_core semantics, CASCI fallback, cache behavior). |
tests/test_hamiltonians/test_cas_factories.py |
Adds tests for new CAS factories and registry completeness. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix test_is_cas_flag_present: lowercase key comparison (was "CAS"→"cas") - Fix test_valid_config_count: use integrals fixture, not hardcoded value - Fix typo: TestCacheBypasForCAS → TestCacheBypassForCAS - Update docstring: RHF/CASSCF non-convergence warns, not raises - Add CAS electron/orbital validation in _compute_cas_integrals - Use shared _FCI_CONFIG_LIMIT constant in _make_cr2 (was hardcoded 50M) - Add ROHF non-convergence warning in _make_cr2 - Add comment explaining N₂ CAS 1.10 Å vs full-space 1.0977 Å
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/qvartools/molecules/registry.py:34
registry.pyimports_FCI_CONFIG_LIMITfromqvartools.hamiltonians.integrals. Since the name is underscore-prefixed (private), this creates a fragile cross-module dependency and makes refactors harder. Consider exporting a public constant (e.g.FCI_CONFIG_LIMIT) or moving the threshold into a shared config module, or avoid importing it here by delegating the CASCI decision entirely tocompute_molecular_integrals.
from qvartools.hamiltonians.integrals import _FCI_CONFIG_LIMIT
from qvartools.hamiltonians.molecular import (
MolecularHamiltonian,
compute_molecular_integrals,
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Previously deferred 3 items — all now fixed: #1: Cr₂ singlet test: assert e_core in [-2040, -2030] Ha range (septet would give different e_core, catches missing fix_spin_) QuantumNoLab#4: get_integral_cache() now returns CAS-aware wrapper that bypasses joblib when cas is not None (was a real cache-escape bug) QuantumNoLab#7: Add test_cache_actually_bypassed_for_cas using mock.patch to verify compute_molecular_integrals is called directly Also from new comment: QuantumNoLab#13: Remove dead tuple/list branch for nelecas in _compute_cas_integrals (public API is tuple[int, int], nelecas is always int)
…mNoLab#22 audit) - Issue 7: Replace module-level pytest.importorskip("pyscf") with importlib.util.find_spec check so TestCASParameterSignature runs without PySCF installed - Issue 8: Add Raises section to _compute_cas_integrals docstring - Issue 9: Add full NumPy-style docstrings (Parameters, Returns, Raises) to _make_n2_cas, _make_cr2, _make_benzene factory functions - Issue 10: Update CHANGELOG.md [Unreleased] > Added with CAS entries - Issue 11: Update AGENTS.md Section 4 molecule table from 12 to 24 molecules (12 full-space + 12 CAS active-space)
Merge with upstream/main brought in _MOLECULE_INFO_REGISTRY consistency check (from PR QuantumNoLab#18). Our 12 CAS molecules were in MOLECULE_REGISTRY but missing from _MOLECULE_INFO_REGISTRY, causing import-time RuntimeError.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code reviewFound 2 issues:
🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
George930502
left a comment
There was a problem hiding this comment.
Code review: 2 inline issues found.
7 fixes from owner code reviews on PRs QuantumNoLab#20/QuantumNoLab#22/QuantumNoLab#23: 1. Cr₂ CASCI path now has fix_spin_(ss=0) — was missing, causing large CAS (ncas>=15) to converge to septet instead of singlet 2. README.md molecule table updated with all 24 molecules (12 full-space + 12 CAS active-space) 3. AGENTS.md Section 5 error handling: 10K → 50K for matrix_elements_fast 4. test_sparse_diag.py: add @pytest.mark.pyscf to 3 test classes that use h2_hamiltonian fixture (importorskip alone is insufficient) 5. Validation ordering: check shape/binary on raw initial_basis BEFORE .to(dtype=torch.long) cast (fail-fast, error shows original shape) 6. float("inf") → RuntimeError when all batches produce non-finite energies (convention per AGENTS.md: non-finite = RuntimeError) 7. ADR-004 TDD plan: note _MOLECULE_INFO_REGISTRY sync requirement
Summary
Closes Phase 1 of #21. Adds CASSCF/CASCI support to
compute_molecular_integralsand 12 new CAS molecules to the registry, enabling 40-58 qubit systems.Key changes:
compute_molecular_integrals(..., cas=(nelecas, ncas), casci=False)— new params_compute_cas_integrals()helper — CASSCF/CASCI with auto-fallback at >50M configsnuclear_repulsion = e_core(frozen-core), NOTmol.energy_nuc()— verified: N₂ CAS(10,8) e_core=-77.38 vs E_nuc=23.57fix_spin_(ss=0)to enforce singlet (prevents septet convergence)Files changed (4):
src/qvartools/hamiltonians/integrals.py—cas/casciparams +_compute_cas_integralssrc/qvartools/molecules/registry.py— 3 factory functions + 12 registry entriestests/test_hamiltonians/test_cas_integrals.py— 19 tests (new)tests/test_hamiltonians/test_cas_factories.py— 10 tests (new)Test plan
ruff check+ruff formatcleanRemaining Phases (separate PRs)