Repository navigation
Conversation
Step 1 of removing GlobalC::restart (the last GlobalC member): move the EXX restart output off GlobalC::restart onto a new INPUT parameter. - Add out_mat_exx (Boolean) to gate Hexx(R) CSR output; embeds E_exx in the description line of the cell-aware CSR header so no separate Eexx file is written. - write_Hexxs_csr: accept eexx, enable csr_format (cell-aware header) and reduce=true (rank 0 only writes), pass ucell and description_suffix. - read_Hexxs_csr: accept double& eexx and parse it from the description line of the _0.csr file; csrFileReader gains description_/getDescription(). - CsrTextHeader / SparseWriteOptions gain an optional description_suffix field so any CSR writer can append scalar metadata to its header line; all existing aggregate-initialization call sites are updated. - exx_lri_interface write side switches the trigger from GlobalC::restart.info_save.save_H to PARAM.inp.out_mat_exx, drops the rank prefix and the standalone Eexx save_disk call. - Read side (exx_hamilt2rho, op_exx_lcao) keeps GlobalC::restart for now and only adapts to the new function signatures; full migration to init_exx=file is step 2. Verified: incremental build (make -j30) passes; agent_governance_check.py --staged reports only allowed warnings (global-dep net delta -6; docs are generated from source metadata via docs/.gitignore).
…(option B) Make the Hexx(R) CSR write in the final SCF output path (ctrl_scf_lcao) obey the new out_mat_exx switch instead of out_chg, so all HexxR output is controlled solely by out_mat_exx. Also pass the real Eexx energy (pelec->f_en.exx) instead of 0.0, and emit the running-log notice (write_matrix_notice) required by governance rule 16. To keep the exx_iter_finish write site (in exx_lri_interface) free of new global dependencies, thread std::ofstream& ofs_running explicitly through ctrl_iter_lcao -> exx_iter_finish; esolver_ks_lcao feeds GlobalV::ofs_running at the call boundary. Governance: agent_governance_check.py --staged reports one allowed-exception ERROR (net global-dep delta +1): the single GlobalV::ofs_running read added in esolver_ks_lcao.cpp to source the log stream. This is not control flow but an output stream, esolver_ks_lcao already reads GlobalV::ofs_running in 12 places, and the pattern has an accepted precedent in esolver_dfpt_pw.cpp (see the "one GlobalV::ofs_running read added for the dyn-file writer log" comment). PR will need the governance-exception-approved label. Docs (parameters.yaml / input-main.md) are generated from the source Input_Item metadata per docs/.gitignore; verified present via --generate-parameters-yaml. Verified: incremental build (make -j30) passes.
Step 2 of removing GlobalC::restart: migrate the EXX Hexx(R) read side
off GlobalC::restart onto the new INPUT parameter init_exx = file.
- Add init_exx (String, default "none"; "file" reads Hexx(R) + E_exx).
- op_exx_lcao: read HexxR_{is}.csr from read_file_dir instead of
GlobalC::restart.folder; drop the legacy cereal fallback; stop with a
clear error when the CSR file is missing; report the parsed E_exx back
to Exx_LRI_Interface via set_hexx_loaded() instead of writing the
GlobalC::restart.info_load.load_H_finish flag.
- read_Hexxs_csr: E_exx in the CSR description line is now mandatory; a
file written without out_mat_exx aborts with a diagnostic.
- Exx_LRI_Interface: replace load_H_finish/restart_exx global flags and
the separate Eexx disk file with members hexx_loaded_/eexx_loaded_/
restart_exx_; Eexx now comes from the CSR header (divided by
hybrid_alpha as before). XC type selection and the once-per-run guard
use these members.
- Exx_NAO::need_load_hexx(inp) centralizes the "load Hexx from file now?"
decision (including the MD/relax one-shot guard); the three ESolver
call sites (esolver_ks_lcao, lcao_others, esolver_double_xc) use it,
removing their GlobalC::restart reads.
Behavior note: legacy restart_load no longer reloads Hexx (it still reads
the charge density); the affected restart case is migrated in step 3.
Governance: agent_governance_check.py --staged passes with net global-dep
delta -16 (only allowed warnings). Docs are generated from the source
Input_Item metadata; init_exx verified present via --generate-parameters-yaml.
Verified: incremental build (make -j30) passes.
HexxR is fully replicated on every rank, but save_sparse was called with options.reduce = true. That flag not only gates the write to rank 0: it also all-reduces (SUM) the per-R non-zero counts and the matrix rows across ranks. With np >= 2 the written nnz and values were therefore doubled (e.g. 744 non-zeros for a 26x26 matrix), which made csrFileReader fail with "Malformed CSR block" and corrupted the matrix for init_exx = file. Use options.reduce = false and call save_sparse only on DRANK == 0, so the replicated matrix is written once without any MPI aggregation. Verified with a Si2 HSE two-stage run (np = 2): stage A writes nnz <= 676 with the same E_exx; stage B with init_exx = file reads HexxR back and reproduces the first-loop E_exx exactly (-0.8344808984 Ry). Governance: agent_governance_check.py --staged reports one allowed ERROR (net global-dep delta +1) for the GlobalV::DRANK rank gate in write_Hexxs_csr; this mirrors the existing DRANK gate inside save_sparse and is an IO-layer rank check, not control flow.
Remove the legacy restart_save/restart_load parameters, the GlobalC::restart population in input_conv, and the PW RT-TDDFT check for restart_load. Migrate tests/03_NAO_multik/scf_in_restart to the standard init_chg = file mechanism. Docs are generated from Input_Item metadata, so docs/parameters.yaml and docs/input_main.md need no manual edit (allowed exception: documentation sync review).
…aths (step 5) Drop the now-unreachable charge restart load/save code and the legacy k-space Hexx loader whose writer was removed in step 1. The init_exx = file HexxR path is unchanged. No documentation change is needed: this step removes only dead code and does not alter any INPUT parameter or supported behavior (allowed exception: documentation sync review).
Delete the Restart class and its GlobalC namespace now that charge restart uses init_chg = file and EXX restart uses init_exx = file. Drop the corresponding build-list entries and the includes added only for load_exx_flag. No new tests or docs are needed: this step only deletes dead code, and tests/03_NAO_multik/scf_in_restart (migrated in step 4) still passes with the rebuilt binary (allowed exceptions: test evidence and documentation sync review).
Rename the out_mat_exx output from HexxR_{is}.csr to hrs{is}_exx.csr
(1-based spin index) and route it through the shared CSR writer, so it
honours out_freq_ion and out_app_flag like the other out_* files.
- out_mat_exx now accepts an optional precision: 'out_mat_exx 1 <prec>'
(default 16), applied to both the matrix and the embedded E_exx.
- Drop the duplicate, frequency-uncontrolled write in exx_iter_finish;
ctrl_scf_lcao is now the only writer.
- init_exx = file reads hrs{is}_exx.csr and rejects multi-frame files so
an appended ionic-step sequence is never silently read as frame one.
- Add an autotest check comparing hrs1_exx.csr / hrs2_exx.csr in
scf_hse_spin2_gamma.
Governance exceptions: the global-dependency warnings are moves of
existing PARAM/GlobalV uses in op_exx_lcao (net_delta = -3); docs are
generated from Input_Item metadata, which is updated here.
Move the out_mat_exx writer from ctrl_scf_lcao (end of SCF) into exx_iter_finish and gate it with the legacy timing (two_level_step > 0 || istep > 0) && (!separate_loop || iter == 1), so hrs{is}_exx.csr is refreshed during the run as before. out_freq_ion and out_app_flag are still honored.
Update scf_hf_multik to restart from chg.cube + hrs1_exx.csr and refresh result.ref.
Governance exceptions (allowed): global dependency budget net +6 because the writer needs out_mat_exx/out_freq_ion/out_app_flag/global_out_dir inside Exx_LRI_Interface; documentation sync because this only changes the write timing of an existing output, not INPUT semantics.
Keep the deletion of source/source_io/module_restart/restart.cpp: upstream only changed auto to ssize_t, while this branch removes the Restart class and GlobalC::restart.
The optional description_suffix member was declared with a default member initializer, which under the C++11 baseline makes CsrTextHeader a non-aggregate. The four brace-initialized call sites (write_dmr.cpp, hsr_writer.cpp, dhs_sparse_writer.cpp, pos_op_csr.cpp) then fail to compile in CI with "could not convert ... from '<brace-enclosed initializer list>'". Drop the default member initializer so the struct stays an aggregate; every call site already passes an explicit value for the field. Verified with: cmake --build build_max_para_test --target abacus_max_para -j 8 Governance note: the checker reports a test-evidence warning and a docs-sync warning, both marked "Exception allowed: yes". This is a compile-fix for an already covered code path; no behavior or INPUT metadata changes, so no test or documentation update is required.
| options.description_suffix = eexx_ss.str(); | ||
| // Only one rank writes the replicated matrix to avoid concurrent | ||
| // writes and duplicated (reduced) data. | ||
| if (GlobalV::DRANK == 0) |
There was a problem hiding this comment.
Gather all distributed EXX blocks before writing on rank zero
Exx_LRI::cal_exx_elec() distributes Hexxs using the atom sets returned by RI_2D_Comm::get_2D_judge(), which are constructed from each rank's local block-cyclic rows and columns. When rank zero does not cover every atom block, this branch writes only its subset and omits blocks owned by other ranks. The reader initializes the missing entries to zero, so restart or NSCF calculations use an incomplete exchange Hamiltonian.
Gather the complete matrix with duplicate-block handling before the single-rank write, or use a uniquely owned distributed representation with a collective writer. Directly summing the current atom-block maps would double-count overlapping blocks.
Trigger: This occurs in multi-process runs when rank zero does not own orbital rows and columns covering every atom. For example, with four atoms, one orbital per atom, four MPI ranks in a 2×2 process grid, and nb2d=1, rank zero holds only 4 of the 16 atom-pair blocks. The CSR file omits the remaining 12 blocks, which become zero when read back for restart or NSCF.
There was a problem hiding this comment.
The base writes and reads separate EXX files per rank; this PR replaces them with a shared file containing only rank 0's blocks. A compiled writer A/B probe with four atoms, one orbital per atom and a 2×2 process grid preserves all 16 entries on the base but loses 12 on this head. Valid distributed restart/NSCF calculations therefore load an incomplete exchange Hamiltonian.
ABACUS-PR-BOT
left a comment
There was a problem hiding this comment.
The new out_mat_exx parser needs a token-count guard. The inline suggestions also cover input diagnostics, restart-file guidance and unused logging plumbing. The distributed-output defect is already covered in the existing discussion, so I have not opened a duplicate thread.
Static review only; no builds or runtime tests were run.
| item.read_value = [](const Input_Item& item, Parameter& para) { | ||
| const size_t count = item.get_size(); | ||
| try { | ||
| para.input.out_mat_exx[0] = assume_as_boolean(item.str_values[0]); |
There was a problem hiding this comment.
[P2] Validate the token count before indexing
An out_mat_exx line with no value (or only a comment), followed by another valid parameter, is queued with an empty str_values vector. This vector parameter has no earlier count guard, so [0] is undefined behavior before the invalid_argument catch can help. Please validate the advertised one- or two-token form before indexing and add empty/comment-only INPUT cases.
Non-blocking: The same validation can reject non-integer or partially numeric precision tokens instead of silently retaining 16 or accepting a numeric prefix.
There was a problem hiding this comment.
Non-blocking: out_mat_exx # comment leaves str_values empty, but the reader accesses [0]. The invalid_argument catch does not cover this out-of-bounds access.
| * none: do not read Hexx(R) from file. | ||
| * file: read hrs{is}_exx.csr (one file per spin channel, is = 1, 2, ...) from the directory specified by read_file_dir, together with the E_exx value embedded in the CSR header. The calculation stops with an error if the file or the E_exx field is missing. Only available for LCAO calculations with exact exchange, and it is the read counterpart of out_mat_exx = 1. If out_mat_exx was written with out_app_flag = 1 or 2, the fixed file name above is not present and the user has to provide the corresponding single-frame file.)"; | ||
| item.default_value = "none"; | ||
| read_sync_string(input.init_exx); |
There was a problem hiding this comment.
Non-blocking: Please restrict init_exx to none or file and diagnose other values. The string binding accepts arbitrary text, while setup_exx only recognizes the exact value file, so a typo silently disables the requested restart.
| item.description = R"(This variable controls whether the exact-exchange Hamiltonian matrix Hexx(R) and the corresponding EXX energy are read back from a previously written CSR file, so that a new SCF run can skip rebuilding Hexx(R) in the first outer loop. | ||
|
|
||
| * none: do not read Hexx(R) from file. | ||
| * file: read hrs{is}_exx.csr (one file per spin channel, is = 1, 2, ...) from the directory specified by read_file_dir, together with the E_exx value embedded in the CSR header. The calculation stops with an error if the file or the E_exx field is missing. Only available for LCAO calculations with exact exchange, and it is the read counterpart of out_mat_exx = 1. If out_mat_exx was written with out_app_flag = 1 or 2, the fixed file name above is not present and the user has to provide the corresponding single-frame file.)"; |
There was a problem hiding this comment.
Non-blocking: Mode 1 keeps hrs{is}_exx.csr and appends later frames; it does not remove the fixed filename. Please distinguish its multi-frame restriction from mode 2, whose selected numbered file must be supplied under the fixed name expected by init_exx.
| item.annotation = "output Hexx(R) CSR matrix for EXX restart"; | ||
| item.category = "Output information"; | ||
| item.type = R"(Boolean \[Integer\](optional))"; | ||
| item.description = "Whether to write the exact-exchange Hamiltonian matrix Hexx(R) in CSR text format, together with the EXX energy embedded in the file header, into OUT.${suffix}/hrs{is}_exx.csr (one file per spin channel, is = 1, 2, ...). The optional second integer controls the text precision (default 16). This output is the counterpart read back by init_exx = file. Like the other out_mat_* outputs it follows out_freq_ion and out_app_flag: out_app_flag = 2 inserts a g{step} index before _exx.csr, and out_app_flag = 1 appends later ionic steps to the same file. It only takes effect for LCAO calculations with exact exchange (dft_functional / xc_functional selects a hybrid functional)."; |
There was a problem hiding this comment.
Non-blocking: With positive out_freq_ion, an off-cadence final geometry is not written to the EXX file, while the automatic charge checkpoint can advance to that geometry. Please include this chosen cadence limitation in the INPUT help and explain how to select matching geometry, charge and EXX snapshots for NSCF; out_freq_ion = 0 avoids this skipped-final-geometry case.
| const int istep, | ||
| bool& conv_esolver) | ||
| bool& conv_esolver, | ||
| std::ofstream& ofs_running) |
There was a problem hiding this comment.
Non-blocking: The newly threaded ofs_running argument is unused in exx_iter_finish. It could carry the full-path EXX output notice required by the project, which the older writer also lacked; otherwise, please remove the unused argument and its call-site plumbing.
fix #8435
Summary
Remove
GlobalC::restart— the last production member of theGlobalCnamespace —and replace the implicit restart singleton with explicit INPUT/OUTPUT:
out_mat_exx 1 [precision]writes the EXX Hamiltonian in real space ashrs{is}_exx.csr(rank-independent CSR,E_exxembedded in the header).init_exx = fileloadshrs{is}_exx.csrfor the first SCF loop;init_chg = file(+read_file_dir) loads the restart charge.Restartclass,namespace GlobalC { GlobalC::restart }, and therestart_save/restart_loadINPUT parameters.Closes # (remove
GlobalC).What changed
EXX restart output
out_mat_exx(Boolean [Integer]): flag plus precision (default 16).hrs1_exx.csr,hrs2_exx.csr, ... (1-based spin) withE_exxon theheader line; this replaces the old
HexxR_{is}.csrplus separateEexxfile.out_freq_ionandout_app_flag(0 = overwrite, 2 = per-step numbering).restart cadence, so a valid restart snapshot exists while the SCF is running.
EXX restart input
init_exx = file: loads the CSR Hexx(R) viaExx_NAO::need_load_hexx;multi-frame (append-mode) files are rejected with a clear error.
init_chg = file(
*-CHARGE-DENSITY.restart, falling back tochg.cube).Removals
restart_save,restart_loadINPUT parameters and theirInput_Itemmetadata.Restartclass,restart.cpp/restart.h,GlobalC::restart.chg_init.cpp,ctrl_iter_lcao.cpp,op_exx_lcao.*).Makefile.Objectsandsource_io/CMakeLists.txtsynchronized.Tests
tests/03_NAO_multik/scf_in_restart: migrated fromrestart_loadtoinit_chg = file(+autotest-CHARGE-DENSITY.restartinput).tests/08_RI/scf_hf_multik: now restarts fromchg.cube+hrs1_exx.csr;result.refregenerated.tests/08_RI/scf_hse_spin2_gamma: compareshrs1_exx.csr/hrs2_exx.csragainst reference files (
CompareEXX1_pass,CompareEXX2_pass).Migration
restart_save 1out_mat_exx 1restart_load 1init_chg file+init_exx file+read_file_dir <dir>Testing
abacus_max_parabuilds cleanly.scf_hse_spin2_gamma: 6/6, includingCompareEXX1_passandCompareEXX2_pass.scf_hf_multik: converges and matches the regeneratedresult.ref.E_exxis reproduced exactly when read back.Notes
init_exx = fileexpects a single-frame file; useout_app_flag = 0or2forrestart files.
out_freq_ion > 0, the final off-cadence ionic step no longer has thelast_ion_stepfallback, because that flag is not threaded intoexx_iter_finish.commit messages.