Skip to content

Port #439 to qp3: TC-SCF fixes, Jastrow-derivative reuse, and plugin CI - #440

Merged
scemama merged 26 commits into
qp3from
port/pr439
Dec 2, 2026
Merged

scemama merged 26 commits into
qp3from
port/pr439

Conversation

@scemama

@scemama scemama commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Port of #439 to qp3, plus the pre-existing plugin fixes it took to compile it.

origin/dev-stable received PR #439 ("Fix TC-SCF orbital convergence and reuse
Jastrow derivatives in save-memory integration", by Matteo Peria) as merge
commit 38b1b86c on 2026-12-01. This branch brings its 17 files to qp3,
which split from dev-stable at 1b289747.

The port

The 13 non-merge commits of #439 are cherry-picked with -x, so each keeps its
author and carries its upstream SHA. Ten applied clean; three conflicted in
plugins/local/non_h_ints_mu/ because the qp3 size_t conversion (PR #437)
rewrote the integer kinds of the same regions. File by file: src/symmetry_det
gets the Intel-critical rename pg_label_msg → pg_label_lock; tc_scf gets
the circular-buffer DIIS history, biorthogonal orbital rescaling, level-shift
retries that restore the incoming orbitals, orbital-residual convergence in
orthonormal AO coordinates, and the three-electron double-counting fix;
non_h_ints_mu gets the QMCkl block integrator and the single-pass save-memory
path; non_hermit_dav restores lapack_diagd for degenerate eigenspaces.

Two adaptation commits follow the cherry-picks:

  • non_h_ints_mu re-applies the qp3 conventions
    (docs/source/programmers_guide/conventions.rst, "Integer kinds") to the
    ported code: integer(size_t) for grid counts and indices, int(x, 4) at the
    BLAS/IO boundary, integer*8/int(x, 8) removed from the new QMCkl routine.
  • tc_scf re-applies the yyjson logging on the ported rh_tcscf_diis.irp.f,
    which upstream still writes with the json_unit/json_*_fmt API that qp3
    deleted in 5a721280. Same /results/tc_scf/<key> paths as in the fix below,
    plus the ported AO residual value.

Apart from those two adaptations, every ported file is byte-identical to its
dev-stable blob (checked mechanically, 17/17).

Pre-existing qp3 fixes carried by this branch

The plugins are not part of the default build, so the qp3 CI never compiles
them: the TC plugin closure has not built since the size_t conversion (#437)
and the JSON rewrite (5a721280). Compiling the ported code means reaching
those modules, so this branch fixes them first, one commit per file, boundary
casts and statement placement only — no logic change:

  • Convert system-size integers to integer(size_t) (64-bit) #437 leftovers — mixed-kind ior() in the AO cache index; two use sizet
    statements mangled into a continued argument list; size_t literals at a call
    site; a 32-bit local used in a DEFAULT(NONE) OpenMP region but missing from
    its SHARED clause; int(n_core_orb, 4) at a dgemm argument; use sizet
    missing inside four hand-written procedures that declare integer(size_t);
    the Cholesky rank passed to the interface-less dgemm in
    tc_scf/fock_tc_core.irp.f, now through a cholesky_ao_num_4 boundary
    temporary as conventions.rst prescribes (gfortran warned
    Type mismatch (INTEGER(8)/INTEGER(4)) there).
  • 5a721280 leftovers — tc_scf.irp.f and rh_tcscf_diis.irp.f logged through
    the deleted JSON API; they now use json_init + json_add on
    /results/tc_scf/<key> (fixed paths, last value wins, as in
    src/casscf_cipsi/casscf.irp.f).

Verification

  • Build of the plugin closure (qp plugins install tc_scf non_h_ints_mu non_hermit_dav, 12 modules) green on the base, before the port — that is
    what separates pre-existing breakage from port breakage.
  • Green again after the port (ninja, 88/88 edges, exit 0), on macOS arm64
    with gfortran 16.2.
  • The port's new sources are in the graph (diis_history.f90,
    biorthogonal_scaling.f90) and their programs were linked
    (diis_history_qp_test, biorthogonal_scaling_provider).
  • Fidelity gate: 17/17 ported files at their expected content.
  • No Type mismatch warning remains in the closure.
  • Plugins uninstalled and the core graph restored afterwards, so the tree is as
    before.

Not run: the numerical TC-SCF / save-memory paths, and the two unit tests
committed under plugins/local/tc_scf/tests/ (they build standalone with
gfortran -llapack -lblas, which works on this machine).

CI: the plugin layer is compiled from now on

The ten defects above were invisible because nothing compiles a plugin. This
branch adds the missing coverage:

  • ci/plugins.txt — the plugin list (tc_scf, non_h_ints_mu,
    non_hermit_dav; qp plugins install resolves the 12-module NEED closure).
    Growing coverage later is one line per plugin.

  • .github/workflows/plugins.yml — a qp3-only job that builds the core, then
    installs and compiles the closure on a cold tree, then:

    • fails on any Type mismatch warning (the silent-corruption class no build
      gate catches today);
    • runs the two tc_scf unit tests and diis_history_qp_test.

The build step is a keep-going cascade, and the reason is measured: IRPF90's
per-module graph declares no .mod outputs, and exactly one program stub edge
has no dependency that would build the sizet.mod it reads, so a cold module
build can compile the stub before sizet.f90. A serial retry cannot fix it
(ninja runs independent edges in graph order even at -j1), and the wrapper's
"Compiling all modules" edge is itself a sub-ninja that does not inherit -k 0.
The cascade (-k 0 at the wrapper, -k 0 on config/build.ninja, two
keep-going passes per inner graph, then a plain ninja as the real gate) makes
the cold build deterministic without touching the generated graphs; it was
proven from a fully cleaned plugin tree, and it carries a TODO pointing at the
IRPF90 fix that would let it go.

First run on this PR: green in 9 m 56 s
(Compilation (plugins), run 46787494568). The gate is not vacuous — before the
cholesky_ao_num_4 commit the same build emitted five Type mismatch warnings
in tc_scf/fock_tc_core.irp.f, and zero after it.

Not covered yet, by design: the two files still on the deleted JSON API
(fci_tc_bi, cipsi_tc_bi_ortho) and the rest of plugins/local. Add them to
ci/plugins.txt as they are fixed.

Known and left out

  • plugins/local/fci_tc_bi/fci_tc_bi_ortho.irp.f and
    plugins/local/cipsi_tc_bi_ortho/write_cipsi_json.irp.f still call the deleted
    JSON API; they are outside the closure and deserve a separate commit.

scemama and others added 26 commits December 1, 2026 21:14
…ing, from #437)

The cache index ii is a 32-bit packed value (six bits per AO); the size_t
conversion made i, j, k, l 64-bit, and gfortran 16 rejects mixed-kind ior()
arguments. Down-cast the index differences at the nine sites; no logic change.
…(pre-existing, from #437)

The size_t batch inserted 'use sizet' inside the continued argument list of
get_cxcycz_j1(); no compiler accepts that. get_cxcycz_j1 declares
integer(size_t) :: ii, so the statement belongs in its body (conventions.rst,
placement of use sizet).
…(pre-existing, from #437)

Same mangled insertion as two_e_1bgauss_j1.irp.f, in get_cxcycz_j2().
… (pre-existing, from #437)

The callee takes integer(size_t) arguments; the literal 1 at two call sites
made gfortran infer 32-bit dummies and warn on the size_t l. Spell 1_size_t.
…on (pre-existing, from #437)

The size_t batch replaced 4*n_points_final_grid by the 32-bit local n_points4
in four dgemm calls without adding it to the SHARED clause. n_points4 is
assigned before the region and only read inside it: SHARED is the only
correct clause.
…ing, from #437)

n_core_orb is integer(size_t) after the conversion; BLAS stays 32-bit.
… from #437)

The procedure declares integer(size_t) in its body; the file-level use sizet
is not hoisted into hand-written procedures (conventions.rst).
…ject.irp.f (pre-existing, from #437)

h_non_hermite, exp_tau_H and project_phi0 each declare integer(size_t) in
their body; the file-level use sizet is not hoisted into them.
The TC-SCF plugin still wrote its JSON with json_unit/json_*_fmt, deleted when
the result logging moved to a yyjson document. Start the document once with
json_init('tc_scf') in the program and log the per-iteration values with
json_add on /results/tc_scf/<key>, following src/casscf_cipsi/casscf.irp.f.
Fixed paths, last value wins: the per-iteration array is not recreated.
lock_io/unlock_io and the convergence control flow are unchanged.
(cherry picked from commit de40841)
Use an OpenMP critical name distinct from the pg_label_msg variable. Intel Fortran rejects the previous shared name; changing the lock label leaves the protected region and behavior unchanged.

(cherry picked from commit d35b9b1)
Reuse each block of Jastrow derivatives for both the gradient and gradient-squared AO integrals. Keep the bounded QMCkl batches and the existing one-shot integration path.

(cherry picked from commit bd48e00)
…code

The qp3 branch converted integer kinds with PR #437 (see
docs/source/programmers_guide/conventions.rst, "Integer kinds"), which the
dev-stable code of PR #439 predates.

Adapt the three files the conversion and the port both touch:

- tc_integ.irp.f: keep use sizet and the 64-bit grid-index declarations of
  the surviving providers.
- tc_integ_num.irp.f: n_blocks, n_this, ii, i_blocks and the grid indices are
  integer(size_t); int(x, 4) at the dgemm and write_int boundaries; the
  memory bound is computed in double precision then converted once.
- jast_deriv_utils_vect.irp.f: the new get_grad1_u12_withsq_qmckl_block takes
  64-bit grid counts and indices, uses 64-bit loop counters and size_t
  literals, and drops the integer*8/int(x,8) spellings.

No logic change: the diff against the dev-stable blobs contains integer kinds
and casts only.
…s.irp.f

The dev-stable version of the file (PR #439) still logs with json_unit and
json_*_fmt, which qp3 does not have. Re-apply the conversion made in
7340201 to the ported text: same paths, plus the new AO residual value as
/results/tc_scf/ao_residual and the DIIS history size as
/results/tc_scf/diis_size. No other change to the ported code.
…-existing, from #437)

The Cholesky rank became integer(size_t) in #437, but it is passed to the
interface-less dgemm at ten argument positions, and gfortran then infers the
dummy kind from whichever call it saw first: it warns 'Type mismatch
(INTEGER(8)/INTEGER(4))' and reads 32 bits of a 64-bit actual. Introduce the
conventions.rst idiom, a cholesky_ao_num_4 boundary temporary per subroutine,
and use it at every dgemm position; array bounds and loop limits keep the
size_t value.
The plugins are not in the default build and no workflow installs them, so a
plugin module can stay uncompilable for months: between the size_t conversion
(#437) and the yyjson rewrite (5a72128) the TC closure accumulated ten
defects -- all fixed earlier in this branch -- and nothing would have reported
any of them.

ci/plugins.txt lists what to build; `qp plugins install` resolves each name's
NEED closure (three names, twelve modules), and growing coverage later is one
line per plugin. The new workflow builds the core, installs and compiles the
closure on a cold tree, then fails on any "Type mismatch" warning -- integer
kinds across a call boundary are silent value corruption and no build gate
sees them -- and runs the two tc_scf unit tests plus diis_history_qp_test.
It is limited to qp3, where json_init/json_add exist.

The build step is a keep-going cascade, measured rather than guessed: IRPF90's
per-module graph declares no .mod outputs, and one program stub edge has no
dependency that builds the sizet.mod it reads, so a cold module can compile
the stub first. A serial retry cannot fix that (ninja runs independent edges
in graph order even at -j1, so it fails the same way every run), and the
wrapper's "Compiling all modules" edge is itself a sub-ninja that does not
inherit -k 0. `-k 0` at the wrapper, `-k 0` on config/build.ninja, two
keep-going passes per inner graph and a plain ninja as the real gate make the
cold build deterministic without touching the generated graphs; it was proven
from a fully cleaned plugin tree. TODO: fix the IRPF90 stub edge, then delete
the cascade.
@scemama scemama changed the title Port #439 to qp3: TC-SCF orbital convergence, Jastrow-derivative reuse Port #439 to qp3: TC-SCF fixes, Jastrow-derivative reuse, and plugin CI Dec 2, 2026
@scemama
scemama merged commit c6c3206 into qp3 Dec 2, 2026
4 checks passed
@scemama
scemama deleted the port/pr439 branch December 2, 2026 10:11
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