Repository navigation
Fix LR optical spin weights, binary density input, and CSR header parsing - #8253
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Keep the singlet sqrt(2) amplitude factor while stripping the KS nspin=1 degeneracy from spatial integration weights. Use the corresponding spin block for polarized weights. This removes an extra factor two in velocity-gauge dipoles and four in absorption intensities. Validation: MODULE_LR_spectrum_weights CTest passed (three tests covering spin settings, nonuniform weights, and singlet versus explicit-spin intensity); git diff --check and staged governance checks passed without blockers.
Recognize the compact save_sparse format while preserving cell-aware CSR input. Validate dimensions and CSR data instead of silently loading zero-sized exchange matrices, and reject basis mismatches. Add real/complex, multi-R and malformed-input regression coverage. Validation: CSR and EXX restart CTest targets pass; Si HSE 1x1x2 SCF-to-NSCF maximum band difference is 2.20e-5 eV and all 48 LAPACK LR roots are positive. No user-input documentation change is needed: this restores reading the existing restart writer format; the reader interface comment documents compatibility.
Separate compact and cell-aware header parsing, then use one validated CSR block reader for both formats. Remove duplicated value/index loops and share comment, whitespace, empty-block and malformed-input handling. Output formats and writers remain unchanged. Validation: 24 focused reader tests pass, C++11 standalone build passes, and actual HexxR plus cell-aware matrix files read successfully. No user-facing documentation change is needed: existing file formats remain supported; interface comments describe the shared validation.
Prefer a complete cube set for standalone LR. Otherwise reuse read_rhog and transform each spin channel onto the real-space grid; report an error when neither density source is readable. Add restart FFT and missing-file tests and document read_file_dir behavior. Validation: 13 single-process charge IO tests, two new tests with two MPI ranks, and HPC integration checks for cube priority, restart/cube eigenvalue agreement, and missing-density failure.
ABACUS-PR-BOT
left a comment
There was a problem hiding this comment.
Please guard density-restart indices and reject leftover CSR data: the paths below can write out of bounds or silently change a matrix entry. Static review of 361ed24e; whitespace and governance checks passed with explained warnings. No build, runtime or CI verification was performed.
Non-blocking: Please add the exact commands and tested commit for the reported checks, including the MPI invocation and test selection.
Address PR deepmodeling#8253 review: guard PW indices outside the active cutoff, reject invalid or excess restart spin channels before output writes, and reject non-comment tokens after the CSR row pointers. Preserve existing supported missing-spin handling and gamma-only diagnostics. Exercise the production cube-set selection and velocity transition contraction, including LR/BSE spatial weights, distinct spin blocks, and full-BSE deexcitation signs. Document recoverable versus fatal binary read failures. The complex header is required by the inline production contraction; API contracts are documented inline, with no new INPUT behavior requiring separate user documentation. Validation: CMake MODULE_CHARGE_rhog_io (18 tests) and MODULE_BASE_csr_reader (28 tests) passed; seven restart/source-selection tests passed with two MPI ranks and OMP_NUM_THREADS=1. Seven spectrum tests passed. EXX/MPI syntax compilation passed for esolver_lr_orb.cpp and lr_spectrum_velocity.cpp. No full ABACUS spectrum rerun.
|
Addressed all six inline findings from the AI review in 3b5e054 and replied individually. The PR description now includes the tested commit, exact build/test commands and MPI filter. Validation: 18 charge tests, 28 CSR tests, 7 spectrum tests, and 7 selected tests on each of two MPI ranks passed; production syntax checks passed. No full spectrum rerun is claimed. |
ABACUS-PR-BOT
left a comment
There was a problem hiding this comment.
Static recheck of 3b5e054cc confirms the cutoff guard, excess-spin rejection, tests through production routines, and corrected failure contract. Wrapped CSR leftovers and lower-spin restarts in standalone LR remain open in their existing threads. No builds or runtime tests were run.
Non-blocking: Include the complete mpicxx syntax-check commands, with defines and include paths, so the two production-file checks can be repeated.
Reject leftover data across lines after CSR frames while preserving comments and unconsumed next-frame headers. Require exact stored/requested spin counts for read_rho_restart, sharing the decoder with read_rhog while preserving the latter legacy conversion policy. Add wrapped-tail, trailing-data and consecutive-frame regressions for both CSR headers, a 1-to-2 restart rejection preserving buffers, and a retained complex +/-G pair with an analytic sine/cosine real density alongside the cutoff sentinel. Name cube fixture paths once for creation and cleanup. API contracts are documented inline; no new INPUT options or separate user docs are needed. Validation: 34 CSR tests and 19 charge tests passed via CTest; eight selected charge tests passed with two MPI ranks, OMP_NUM_THREADS=1. Full EXX/MPI syntax commands for esolver_lr_orb.cpp and lr_spectrum_velocity.cpp passed and are recorded in the PR follow-up. No full spectrum rerun.
|
Addressed the four new inline findings in 3efe8ed and replied in their respective threads. For the review-summary request, the PR description now includes the complete successful |
ABACUS-PR-BOT
left a comment
There was a problem hiding this comment.
Static recheck of 3efe8ed0e: the previous parser, spin-count and test follow-ups are addressed in source, and the PR now records the complete syntax-check commands. Two non-blocking test/documentation suggestions remain below. No builds or runtime tests were run for this review; the author-reported results were not independently verified.
Use step 8 and value 2.5 for the second CSR frame, retaining step 7 and value 1.0 for the first, in both header formats. Document the exact nspin-match prerequisite in the user-facing read_file_dir input metadata. Generated documentation is not edited. Validation: all 34 MODULE_BASE_csr_reader tests passed; read_inp_sys.cpp passed EXX/MPI syntax compilation. git diff --check passed. No runtime spectrum behavior changes.
The Makefile job fails before checkout because the Intel image exhausts hosted-runner disk during container initialization. Run on the host long enough to remove unused preinstalled SDKs/images, then run the same Intel image and build arguments with the workspace mounted. Mark the mount safe for git metadata queries. Validation: workflow YAML and bash syntax passed; post-merge CSR (34) and charge (19) tests passed locally. Container execution requires GitHub CI; no local Docker runtime is available. The previous failure occurred before compilation, not in PR source.
|
Reading the charge density is a unified, fundamental operation. Regardless of where in the calculation it is read, and regardless of the circumstances under which it is read, it should be an operation that does not need to know the concept of "restart". So why attach a "restart" label to this read_rho concept? What is the difference between the charge density read in on restart and the charge density read in normally? |
|
If nowhere else needs to read in the "restart" charge density, and only the LR code needs this "restart" operation, then it is very likely that the LR code is over-engineered. |
Rename the new read_rho_restart helper to read_rho_from_binary and describe its inverse FFT explicitly. The legacy .restart filename is retained as a file-format convention; this operation restores no solver or iteration state and does not depend on module_restart. Clarify this in read_file_dir help. Expand the optical contraction conditional and use explicit types in spectrum tests as requested by the maintainer. Validation: 19 charge tests, 8 selected tests with two MPI ranks, and 7 spectrum tests passed. esolver_lr_orb.cpp and read_inp_sys.cpp passed syntax compilation. No physical or numerical changes.
|
Regarding the density-read naming and LR-only restart concern: I agree that reading charge density should not depend on the concept of resuming a calculation. The name was misleading. In 297c265 I renamed the helper to This path reads the existing reciprocal-space ground-state density file and performs inverse FFT. The separate edits to |
|
The exx restart function will be removed in near future, would it be possible to restart calculations without touching these codes? |
|
Replacing/removing the EXX restart workflow is independent of this PR. This PR does not introduce a calculation-restart mechanism: it enables ordinary LR ground-state density input from the existing binary format and fixes the existing CSR import. The HexxR reader fixes keep the currently supported import working; they do not require preserving that restart workflow in the future. The existing route for continuing hybrid SCF without loading saved Hexx is
For example, save wavefunctions in the preceding LCAO SCF: Then start a new SCF using the same structure, basis, k-point mesh, spin setup and hybrid-functional parameters: Here DMR alone is not the same direct SCF continuation path in the present code. This is source-path verification, not a new runtime test. The wavefunction route resumes self-consistency from an available saved electronic state; it does not restore mixing history, outer-loop counters or an exact interrupted iteration. In particular, the inspected LCAO wavefunction output is in Possible follow-up: SCF continuation directly from a density-matrix snapshot (not implemented by this PR). Currently
This would resume self-consistency from a saved DM without storing Hexx or wavefunctions. Exact restoration of the interrupted iteration trajectory would additionally require mixing histories and loop state. |
mohanchen
left a comment
There was a problem hiding this comment.
OK, please keep in mind that the restart mechanism may be changed in near future.
nspin=1: remove the doubled degeneracy factor included in KS k weights at the LR/spectrum boundary. BSE already supplies spatial weights and retains its original normalization; shared k-point data is unchanged.STEPand cell-awareIonic stepheaders with shared block parsing, and reject malformed data instead of silently misreading the values.chg.cube/chgs*.cubeset inread_file_dir; otherwise read{suffix}-CHARGE-DENSITY.restartthrough the existing reciprocal-space reader and FFT every spin channel onto the real-space grid. Fail explicitly if neither source is readable. Theread_file_dirinput description now documents the fallback; no new input parameter is introduced.Validation:
RestartDensityTransformsEverySpinandMissingRestartPreservesRealDensitytests also passed with two MPI ranks andOMP_NUM_THREADS=1.Review follow-up
Tested tree committed as
3b5e054cc0997b074e93d90aed5343117e2d5d6e:Exact commands, run from the repository root unless noted:
Results: 18 charge tests, 28 CSR tests, 7 selected tests on each of two MPI ranks, and 7 spectrum tests passed. The two modified orchestration/production files (
esolver_lr_orb.cpp,lr_spectrum_velocity.cpp) also passedmpicxx -std=c++14 -fopenmp -fsyntax-onlywith the existing EXX/MPI build's defines and include directories. No full executable link or end-to-end optical spectrum rerun. Cube tests cover the real source-selection routine and restart FFT, not parsing synthetic cube contents.Governance warnings:
<complex>is needed by the inline production contraction. Function contracts are documented inline; this follow-up adds no INPUT parameters or workflow options requiring separate user documentation.Second review follow-up
Tested tree committed as
3efe8ed0ef8caf069bfd4a308e1c9d3ca295ac26. CSR frame-tail validation now continues across lines through whitespace/comments to EOF or an unconsumed next-frame header. Standalone LR restart loading requires an exact spin-count match; the shared decoder retains the existing low-levelread_rhogcompatibility policy for other callers. Added both-header wrapped-tail and next-frame tests, 1-to-2 rejection with unchanged buffers, and a retained complex ±G pair checking an analytic sine/cosine density while preserving the out-of-cutoff sentinel. Cube fixture paths are named once and reused.Validation: 34 CSR tests and 19 charge tests passed; 8 selected charge tests passed on each of two MPI ranks. Exact commands (same CMake configuration as above):
Both production syntax checks also passed. Here are the complete commands, including all defines and include paths (the existing build directory supplies generated configuration headers):
No full executable or spectrum rerun. The strict LR spin-count contract is documented in
chg_rhog_io.h; no new INPUT parameter is introduced. The remaining governance documentation warning is covered by these API notes.Latest test/documentation follow-up
Tested commit
31c4b337e870eac63943eede6c12f16fd0039ef9: consecutive-frame tests now assert distinct first/second steps (7/8) and values (1.0/2.5) for both headers. The user-facingread_file_dirmetadata now states that the restart spin count must exactly match requestednspin; generated docs are not manually edited.Validation:
cmake --build /tmp/lr-density-develop-build --target MODULE_BASE_csr_reader -j 12andOMP_NUM_THREADS=1 ctest --test-dir /tmp/lr-density-develop-build -R '^MODULE_BASE_csr_reader$' --output-on-failurepassed (34 tests).read_inp_sys.cppalso passed syntax compilation using the complete EXX/MPI command above with that source as its final argument. No spectrum runtime changes or rerun.Maintainer follow-up: density input terminology
In
297c26519d4aaf8e37ada166fb46273208829fe4, the new helper is namedread_rho_from_binary(previouslyread_rho_restart). It reads reciprocal-space ground-state density and performs inverse FFT; it does not resume SCF/LR iterations or restore solver state. The existing{suffix}-CHARGE-DENSITY.restartfilename is retained for compatibility. The helper lives in module_charge and does not depend on module_restart. The separate EXX CSR changes validate existing input; they introduce no new restart state or lifecycle. Updated read_file_dir help, expanded the one-line conditional, and replaced auto in spectrum tests with explicit types.Validation: 19 charge tests, 8 selected tests on two MPI ranks, 7 spectrum tests, and syntax checks for esolver_lr_orb.cpp and read_inp_sys.cpp passed. No physical/numerical changes.