Skip to content

lno: compatibility with pyscf >= 2.14 (dfccsd._contract_vvvv_t2 signature) and NumPy 2 (_cp) - #212

Open
thebreadishard wants to merge 1 commit into
pyscf:masterfrom
thebreadishard:lno-pyscf214-compat
Open

thebreadishard wants to merge 1 commit into
pyscf:masterfrom
thebreadishard:lno-pyscf214-compat

Conversation

@thebreadishard

@thebreadishard thebreadishard commented Sep 21, 2026 •

Copy link
Copy Markdown

Summary

Two small compatibility fixes in pyscf/lno/lnoccsd.py, both hit in production LNO-CCSD(T) runs (benzene and naphthalene, cc-pVDZ/cc-pVTZ, pyscf 2.14.0, NumPy 2):

  1. DFLNOCCSD / _DFChemistsERIs._contract_vvvv_t2: pyscf 2.14 changed dfccsd._contract_vvvv_t2 to (mycc, mol, vvL, VVL, t2, out=None, verbose=None). The existing six-argument call shifts the arguments (t2 arrives as out) and every DF-LNO-CCSD run fails. The call now inspects the installed signature and passes vvL twice on pyscf ≥ 2.14, keeping the old call for older pyscf.
  2. _cp: np.array(a, copy=False, order='C') raises under NumPy 2 when a copy is unavoidable, which happens on the out-of-core path when the fragment's Lov block is an h5py slice (max_memory below its size). np.asarray(a, order='C') keeps the NumPy 1.x meaning.

Test plan

  • python -m py_compile pyscf/lno/lnoccsd.py
  • DF-LNO-CCSD(T) on benzene and naphthalene with pyscf 2.14.0 / NumPy 2 (thresholds 1e-5/1e-6 and 1e-6/1e-7; in-core and out-of-core) since 2026-09-10 — identical energies to the patched local copy we have been running.
  • The shipped pyscf/lno/test suite in a clean environment (Python 3.12, pyscf 2.14.0, NumPy 2.5.3, this branch built from source against the installed pyscf headers with CMAKE_CONFIGURE_ARGS=-DPYSCF_SOURCE_DIR=<site-packages>/pyscf, BUILD_OCCRI=OFF): 5 passed in 183 s, pytest -q pyscf/lno/test.

🤖 Generated with Claude Code

- DFLNOCCSD._contract_vvvv_t2: pyscf 2.14 changed dfccsd._contract_vvvv_t2 to a
  seven-argument signature (mycc, mol, vvL, VVL, t2, out, verbose). The old
  six-argument call shifted the arguments, so t2 arrived as out and every
  DF-LNO-CCSD run crashed. The call now adapts to the installed signature.
- _cp: np.array(a, copy=False, ...) raises under NumPy 2 when a copy is
  unavoidable, which it is for an h5py slice on the out-of-core path
  (max_memory below the fragment's Lov block). np.asarray keeps the intended
  behaviour on both NumPy 1 and 2.

Both fixes have been running in production LNO-CCSD(T) calculations on benzene
and naphthalene (cc-pVDZ/cc-pVTZ, pyscf 2.14.0, NumPy 2) since 2026-09-10.
@thebreadishard
thebreadishard marked this pull request as draft September 21, 2026 05:18
@thebreadishard
thebreadishard marked this pull request as ready for review September 21, 2026 05:55
@MatthewRHermes

Copy link
Copy Markdown
Collaborator

Can you show simple example inputs that raise the two errors you describe, assuming pyscf 2.14.0 and numpy 2 are installed? On my machine, which has pyscf 2.14.0 and numpy 2.2.5, all the lno tests pass without incident, including the "main" block of pyscf/lno/lnoccsd.py.

Comment thread pyscf/lno/lnoccsd.py
# pyscf >= 2.14 changed the signature to (mycc, mol, vvL, VVL, t2, out, verbose);
# with the six-argument call t2 arrives as `out` and the DF-LNO path crashes.
import inspect
if len(inspect.signature(dfccsd._contract_vvvv_t2).parameters) >= 7:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to simply inspect the version of PySCF directly, which would both render the commentary in lines 399 and 400 unnecessary and make it clear that if something similar happens in the future, it's probably because the calling signature was changed (if it changed in the past, it might change in the future).

@MatthewRHermes MatthewRHermes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add regression tests for these two bugs, since currently the entire test suite passes on pyscf:master with PySCF 2.14.0 and NumPy 2 installed.

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