Skip to content

feat(librpa): strict 2D/3D Coulomb kernels and 2D reader-v1 producer outputs - #8176

Open
AroundPeking wants to merge 19 commits into
deepmodeling:developfrom
AroundPeking:abacus-librpa-strict2d-oct17
Open

AroundPeking wants to merge 19 commits into
deepmodeling:developfrom
AroundPeking:abacus-librpa-strict2d-oct17

Conversation

@AroundPeking

Copy link
Copy Markdown

Problem

  • After the module_rpa split (Title: refactor(rpa): move LibRPA producer into module_rpa #8154), develop still lacks strict-2D support: the Ewald short-range tail machinery, direct 2D mixed-Fourier / 3D reciprocal Coulomb kernels, the strict-2D head normalization, and the 2D reader-v1 producer outputs needed by LibRPA's 2D (slab) GW/RPA pipeline.
  • Two latent defects surface once this machinery runs test geometries: the Ewald tail completeness check bounds the projected Gaussian tensor by the raw gaussianized-aux radius sum instead of the RI pipeline's integral support, so rpa_scf_gamma's guard shell always fails coverage in warn mode; and Symmetry_rotation_k::wigner_d overflows int factorials for l>=5, producing NaN rotation matrices.

Change

  • module_ri: port the strict-2D/3D kernels, Ewald tail planner/checker, Gaussian 2D integrals, MPI shell-key distribution, and LRI_CV extensions (adapted to develop's p_info_ri/timer conventions); restore the empty-abfs construction branch in Exx_LRI::init_spencer; bound the tail check's Gaussian support by min(cal_V_Rcut); evaluate wigner_d factorials in double.
  • module_rpa: port the strict-2D head sidecar and direct-Coulomb output wiring into output_ewald_coulomb with v1 naming, plus the LibRPA io writers (head / structure symmetry / BZ sampling) and ABFS preorthogonalization.
  • Input parameters and Exx_Info_RI / XC functional fields for all of the above, with read_input unit tests.
  • Tests: new 61_librpa_2d_reader_v1 producer contract (including the head sidecar) with single-rank-layout references; regenerated Ewald far-field coulomb_mat references for rpa_scf_gamma / rpa_scf_shrink_multik (energies unchanged to 4e-13 eV); unit tests for the kernels, tail utilities, io writers, and symmetry rotation.

Validation

  • ctest -R "MODULE_RI|MODULE_RPA|read_input|op_exx" — 24/24 pass, including the
    direct 2D/3D Coulomb kernels, the Ewald tail planner and utilities, the Gaussian
    2D integrals, the reader-v1 io writers, and the symmetry rotation tests.
  • 08_RI integration suite (4 MPI ranks): rpa_scf_gamma and rpa_scf_shrink_multik
    pass with the regenerated Ewald far-field references; bse_lr_multik,
    rt_tddft_pbe0_gamma, and the LibRPA producer contract (cases 60/61/64, including
    the strict-2D head sidecar) pass. The hse / lr_tddft / lr_relax failures seen
    locally are LibXC-dependent cases under an ENABLE_LIBXC=OFF build; CI builds
    with LibXC enabled.

…strict-2D RI-EXX

Add the strict-2D/3D Ewald Coulomb controls (ewald dimension, lambda, tail
check mode with tolerances and adaptive expansion limits, direct
mixed-Fourier 2D and reciprocal 3D Coulomb output selection with quadrature
orders, RPA ABFS preorthogonalization, EXX V-matrix screening thresholds)
to the input parameters, wire them through the EXX reading path, and extend
Exx_Info_RI and the XC functional type so downstream RI modules can consume
them. read_input unit tests cover the new keywords.
…metry wiring

Port the strict-2D RI-EXX machinery: direct mixed-Fourier 2D and reciprocal
3D bare-Coulomb kernels, the Ewald short-range tail planner with its
completeness check, Gaussian auxiliary-basis 2D integrals, MPI shell-key
distribution, and the extended LRI_CV pipeline, adapted to develop's
p_info_ri and timer conventions. Restore the empty-abfs construction
branch in Exx_LRI::init_spencer that the signature unification dropped.
The tail completeness check now bounds the projected Gaussian tensor by
the RI integral pipeline's own support min(cal_V_Rcut) instead of the raw
gaussianized-aux radius sum, which demanded identically-zero blocks and
failed coverage in warn mode. Evaluate wigner_d factorials in double so
high-L (l>=5) rotation matrices no longer overflow int and produce NaN.
Wire the EXX LCAO operator, LR-TDDFT esolver, RDMFT, and center2orbital
paths to the extended interfaces, and add unit tests for the kernels,
tail utilities, and symmetry rotation.
…s in module_rpa

Port the master_ghj output wiring that the module_rpa split dropped: the
strict-2D Coulomb head normalization sidecar written next to the reader-v1
Ewald outputs, the direct mixed-Fourier 2D / reciprocal 3D Coulomb output
block with its reader-v1 basis export, and the LibRPA io writers (2D head,
structure symmetry, BZ sampling) plus RPA ABFS preorthogonalization, all
using develop's v1 output naming. Unit tests cover the new io writers.
…cker kinds

Add tests/08_RI/61_librpa_2d_reader_v1 exercising the strict-2D Ewald
reader-v1 producer contract including the Coulomb head sidecar, with
references generated at the producer's single-rank layout, and register it
in the LibRPA producer case list. Extend check_librpa_producer.py with the
strict_2d_head kind and its self-test. Regenerate the Ewald far-field
coulomb_mat references of rpa_scf_gamma and rpa_scf_shrink_multik for the
ported tail machinery (energies unchanged to 4e-13 eV).
…il sources

Comment the construction the ported kernels implement: the positive Gram
quadrature of the direct mixed-Fourier route (the tan-mapped kz rule and
the Massidda-constrained Gamma plane), the analytic 2D Gaussian
compensation integrals, the Ewald tail planner decision table, the
Gaussian decay exponent search, and the strict-2D head normalization.
The new sources carried essentially no comments, repeating the review
finding from the reader-v1 producer PR.

Also drop the INTERFACE OpenMP link added to the device object library
during the port: this PR's OpenMP usage lives in the module_ri targets,
and develop links the same device objects without publishing OpenMP, so
the hunk was unrelated to this PR's scope.
The new operator_exx_nscf_cell_nearest test target referenced
lcao_set_mat2d.cpp with one ../ level too many, which only surfaces
when ENABLE_LIBRI=ON (the CI test configuration), breaking CMake
generate. Two new headers used #pragma once, which the repository
governance checker rejects; use traditional include guards, matching
the guard style of the neighboring headers.
…rmat

The operator cell-nearest test target never compiled under GNU CI
toolchain before: its AddTest source list missed the translation
units providing ModuleIO::save_sparse and hamilt::transferSerial2Parallels,
and ri OBJECT-library members were duplicated on the link line.

- complete the source list (hs_sparse_io, lat_r_csr, hcontainer
  transfer sources, center2orb, orb_read, elem_basis_idx_orb,
  restart) and link the ri object library instead of re-listing
  its members
- drop tmp_mocks entries now provided by the real translation units
- write the CSR fixtures in the sparse-file format the develop
  csrFileReader parses (SR.csr-style header with lattice block)
- relax the high-L Gamma closed-form check from 2e-11 to 1e-9
  relative: the degree-14 Hermite reference agrees with the kernel
  to a constant 2.09e-11 relative on glibc, so the old bound was
  knife-edge across libms
…x restart CSR

The symmetry entry derived case metadata positionally, which broke when
the strict-2D case joined the producer list: the generic 3D meshes
tripped the nkz = 1 guard of the 2D Ewald path, and the nspin pairing
appended nupdown to an unpolarized case. Derive the mesh variants and
nspin from each case's INPUT instead, and iterate every listed case so
the nspin = 2 coverage is kept.

write_Hexxs_csr emitted the bare save_sparse layout, which
read_Hexxs_csr cannot parse back. Emit the sparse-file layout shared
with the DM(R) restart files (header, lattice block, CSR blocks per R)
and pin the contract with a read-back unit test. List ucell_io.cpp in
the two test targets that now reference UcellIO::write_ucell.
Comment thread source/source_hamilt/module_xc/exx_info_ri.h Outdated
Comment thread source/source_hamilt/module_xc/xc_functional.cpp Outdated
mohanchen and others added 2 commits October 20, 2026 11:08
- resolve_runtime_xc_type now takes the input functional explicitly;
  the Exx_LRI_Interface call sites pass PARAM.inp.dft_functional from
  their own scope, so module_xc no longer includes parameter.h
- align the Exx_Info_RI member declarations with the surrounding
  4-space struct indentation

@ABACUS-PR-BOT ABACUS-PR-BOT 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.

Static review of acbe254 against ffc4d0d. No build or runtime tests were run; CI diagnostics were unavailable. The inline findings are source/analytic conclusions. Finite-mesh Gamma equivalence, compensation-tail error bounds, and sparse-restart/symmetry edge cases remain unresolved; this is not full numerical acceptance.

Comment thread source/source_lcao/module_ri/exx_lri.hpp Outdated
Comment thread source/source_lcao/module_ri/direct_2d_coulomb_ewald.hpp Outdated
Comment thread source/source_io/module_parameter/read_inp_exx_dftu.cpp
Comment thread source/source_lcao/module_ri/exx_lri.h Outdated
Comment thread source/source_lcao/module_ri/gaussian_abfs.cpp Outdated
Comment thread source/source_lcao/module_rpa/rpa_abfs_preorthogonalization.h Outdated
Comment thread source/source_lcao/module_ri/module_exx_symmetry/test/CMakeLists.txt Outdated
Comment thread source/source_lcao/module_ri/exx_lri.h Outdated
Comment thread source/source_lcao/module_rpa/rpa_lri_overlap_io.cpp Outdated
Comment thread source/source_lcao/module_rpa/rpa_lri.h Outdated
…, and review fixes

- Extend Parallel_Reduce/Parallel_Common with sub-communicator overloads
  (reduce_all/max/min, reduce_max_loc, gather_int_all, bcast from an
  arbitrary root, my_rank/nproc/barrier) plus MPI_Type<unsigned long long>,
  and route the new tail reductions, direct-output drivers, eigenvector
  guards and raw-overlap writer through them instead of raw MPI calls.
- Remove the unused symmetry_rotation_/use_spacegroup_symmetry_ members of
  RPA_LRI together with the now-unneeded symmetry-header dependency.
- Construct the cut/full-coulomb Exx_LRI helpers with an explicit
  ExxLriRuntime at the remaining callers and drop the factory-delegating
  single-argument constructor.
- Rename abf_rotation_test.cpp and nspin4_restore_test.cpp to the
  test_<module_name>.cpp convention and update the CMake entries.
- Complete the INPUT metadata of the new registrations: strict-2D slab,
  k-mesh and force restrictions; tail-mode warn abort conditions on
  incomplete coverage or a failed Hermitian check; direct quadrature
  convergence notes; missing guard-shell tolerance descriptions.
- Fix the dangling default argument on cal_ewald_coulomb, un-nest the
  ExxLriDetail void_t block that shadowed the enclosing namespace, and
  qualify RpaAbfsPreorthReport at the production call site in rpa_lri.cpp.
…d close gamma-dipole test link

Removing the factory-delegating single-argument Exx_LRI constructor
missed three call sites, so every ENABLE_LIBRI configuration failed to
compile: the LR workspace in exx_workspace.cpp and both esolver_lr_init
constructions. The workspace now copies the owning solver's runtime, and
the esolver sites call make_exx_lri_runtime() like the interface, RDMFT
and RPA paths.

The new gamma-dipole unit test linked cell without the libraries its
members depend on; add neighbor_search, domain_decomposition and
neighbor so the mdcell_reader, record_adj and domain_decomposition
symbols resolve.
@mohanchen

mohanchen commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

If you have fixed specific issues, please reply to each comment. @AroundPeking

@AroundPeking

Copy link
Copy Markdown
Author

Thanks for the detailed review. All inline comments have been addressed and replied to individually:

  • The LibRI C++14 compatibility (void_t), the reader-v1 output path, the preorthogonalization wiring, the z-image removal in the strict-2D real-space sum, the dual-lattice Massidda bound, the scaled-erfc evaluation, the direct-3D Carrier q-mesh population, the removed interface defaults, the test renames, and the MPI wrapper routing all landed in de29636.
  • The deterministic Eexx initializer, the explicit ExxLriRuntime construction sites, and the gamma-dipole test link closure landed in d691c13.
  • The INPUT registration metadata (strict-2D slab/k-mesh/force restrictions, tail-mode warn abort conditions, direct-quadrature convergence notes) is complete; docs/parameters.yaml and input-main.md regenerate through the CI documentation pipeline after merge.

CI is green on d691c13 (16/16 checks).

AroundPeking and others added 2 commits October 21, 2026 10:00
…rict2d-oct17

# Conflicts:
#	source/source_lcao/module_operator_lcao/test/CMakeLists.txt
#	source/source_lcao/module_ri/CMakeLists.txt
#	source/source_lcao/module_ri/module_exx_symmetry/test/CMakeLists.txt
#	source/source_lcao/module_rpa/CMakeLists.txt
#	source/source_lcao/module_rpa/module_librpa_io/unittests/CMakeLists.txt
#	source/source_lcao/module_rpa/unittests/CMakeLists.txt

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.

You added so many lines of code to this file — you must have misunderstood how the scripts in this folder are meant to be used. The purpose of this folder is to compare files: if the comparison results differ, it reports an error. This folder must not involve any physics-related knowledge. For example, given an output filea.txt , this folder's only job is to find the pre-stored reference answera.txt.ref , compare them, and report the result. That is the entire scope of this folder.

If you want to construct a lattice, that involves physics knowledge; if your output distinguishes between EXX, RI, GW, or any other physical algorithm, that's wrong — that's not what this folder is supposed to do. Please move your redundant design elsewhere.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in bcc4bd9: the mock-data unit tests were removed from validation_tools. The folder now only holds the generic comparison tooling: check_librpa_producer.py compares each produced file against the stored reference in the case's producer_reference/ directory and reports mismatches. The 2D producer contract remains covered end-to-end by the integration case tests/08_RI/61_librpa_2d_reader_v1 (manifest-driven comparison against producer_reference/) and by the module_librpa_io unit tests, which is where the physics-aware checks belong.

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.

Non-blocking: Please relocate the deleted rejection cases for missing required files, incomplete strict-2D head metadata, generic nonfinite numeric data, and LRI payload mismatches to an appropriate test directory outside validation_tools. The retained wavefunction tests and C++ writer tests do not cover these parser paths. This can be a follow-up while keeping this folder within the requested comparison-only scope.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in fcebd02: the rejection cases (missing required file, incomplete strict-2D head metadata, nonfinite numeric data, LRI payload mismatch) now live in tests/integrate/producer_contract/test_check_librpa_producer.py, outside validation_tools, and are registered with CTest as librpa_producer_contract.

…rict2d-oct17

# Conflicts:
#	source/source_io/test/CMakeLists.txt
#	source/source_lcao/module_operator_lcao/test/CMakeLists.txt
#	source/source_lcao/module_ri/unittests/CMakeLists.txt
…tools

validation_tools only compares produced files against stored references.
The 2D producer contract is exercised end-to-end by
tests/08_RI/61_librpa_2d_reader_v1 (manifest-driven comparison against
producer_reference) and by the module_librpa_io unit tests, so the
mock-data unit test file is removed from this folder.
The merge resolution took the upstream version of source_io/test/CMakeLists.txt
wholesale, which dropped the ucell_io.cpp entry that the Hexx restart
round-trip test needs for ModuleIO::UcellIO::write_ucell.
@mohanchen mohanchen added Features Needed The features are indeed needed, and developers should have sophisticated knowledge Refactor Refactor ABACUS codes labels Oct 23, 2026

@ABACUS-PR-BOT ABACUS-PR-BOT 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.

Incremental static review of 84d0923 against 370ba68. Source inspection confirms the earlier numerical fixes and most cleanup; residual source-rule items and bounded follow-ups are tracked in their existing threads. The new inline comments cover test repeatability and declaration style. No build, ABACUS/CTest run, or documentation generation was performed; CI diagnostics were unavailable. Earlier finite-mesh Gamma, compensation-tail and sparse-restart/symmetry verification limits remain open.

// need no path special case. Exercise it with a non-default
// directory.
const std::string nondefault_directory = "nondefault_rpa_outdir/";
require(mkdir(nondefault_directory.c_str(), 0755) == 0,

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.

[P2] Make the direct-output test repeatable

The first successful run leaves nondefault_rpa_outdir/ behind, while CTest reuses this binary directory, so a second run fails at mkdir with EEXIST before testing the output. Please use an owned temporary directory with cleanup, or safely reuse and clean this fixture, and verify two consecutive runs of the selected test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in fcebd02: the direct-output case now owns a mkdtemp directory and removes it through an RAII guard, so consecutive CTest runs are independent. Verified locally by running the built test twice: both runs pass and no output directory is left behind.

Comment thread source/source_base/parallel_reduce.cpp Outdated
{
double value;
int rank;
} local{value, rank}, global{};

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.

Non-blocking: Please finish the MaxLoc type definition and declare local and global in separate statements to follow the one-variable-per-line rule. This small cleanup can be a follow-up.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in fcebd02: MaxLoc is now a complete type definition followed by separate local and global declarations.

…iene

- Route the remaining sub-communicator collectives in exx_lri.hpp and the
  raw-overlap writer through Parallel_Common/Parallel_Reduce, adding a
  gatherv_int_all wrapper, and split the reduce_max_loc locals.
- Drop the default threshold on read_Cs_ao_all and pass 0.0 explicitly at
  the LR/BSE call sites.
- Make the direct-output test own a mkdtemp directory with RAII cleanup so
  repeated CTest runs stay independent, and add erfcx-crossover and
  large-separation regressions for the scaled-erfc helpers.
- State the active-only scope of rpa_abfs_preorth under shrink in the INPUT
  description and cover it in the preorth unit test.
- Relocate the producer-checker rejection cases out of validation_tools into
  tests/integrate/producer_contract and register them with CTest.

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

Features Needed The features are indeed needed, and developers should have sophisticated knowledge Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants