Skip to content

Remove GlobalC::restart and rework the EXX restart mechanism (fix #8435) - #8436

Open
mohanchen wants to merge 11 commits into
deepmodeling:developfrom
mohanchen:2026-11-28-line1-removeGlobalC
Open

mohanchen wants to merge 11 commits into
deepmodeling:developfrom
mohanchen:2026-11-28-line1-removeGlobalC

Conversation

@mohanchen

Copy link
Copy Markdown
Collaborator

fix #8435

Summary

Remove GlobalC::restart — the last production member of the GlobalC namespace —
and replace the implicit restart singleton with explicit INPUT/OUTPUT:

  • out_mat_exx 1 [precision] writes the EXX Hamiltonian in real space as
    hrs{is}_exx.csr (rank-independent CSR, E_exx embedded in the header).
  • init_exx = file loads hrs{is}_exx.csr for the first SCF loop;
    init_chg = file (+ read_file_dir) loads the restart charge.
  • Delete the Restart class, namespace GlobalC { GlobalC::restart }, and the
    restart_save / restart_load INPUT parameters.

Closes # (remove GlobalC).

What changed

EXX restart output

  • New out_mat_exx (Boolean [Integer]): flag plus precision (default 16).
  • File names hrs1_exx.csr, hrs2_exx.csr, ... (1-based spin) with E_exx on the
    header line; this replaces the old HexxR_{is}.csr plus separate Eexx file.
  • Honors out_freq_ion and out_app_flag (0 = overwrite, 2 = per-step numbering).
  • Written at the first electronic step of every outer EXX step, matching the legacy
    restart cadence, so a valid restart snapshot exists while the SCF is running.

EXX restart input

  • New init_exx = file: loads the CSR Hexx(R) via Exx_NAO::need_load_hexx;
    multi-frame (append-mode) files are rejected with a clear error.
  • Charge restart uses the existing init_chg = file
    (*-CHARGE-DENSITY.restart, falling back to chg.cube).

Removals

  • restart_save, restart_load INPUT parameters and their Input_Item metadata.
  • Restart class, restart.cpp / restart.h, GlobalC::restart.
  • Dead charge-restart and k-space Hexx load paths (chg_init.cpp,
    ctrl_iter_lcao.cpp, op_exx_lcao.*).
  • Makefile.Objects and source_io/CMakeLists.txt synchronized.

Tests

  • tests/03_NAO_multik/scf_in_restart: migrated from restart_load to
    init_chg = file (+ autotest-CHARGE-DENSITY.restart input).
  • tests/08_RI/scf_hf_multik: now restarts from chg.cube + hrs1_exx.csr;
    result.ref regenerated.
  • tests/08_RI/scf_hse_spin2_gamma: compares hrs1_exx.csr / hrs2_exx.csr
    against reference files (CompareEXX1_pass, CompareEXX2_pass).

Migration

Old New
restart_save 1 out_mat_exx 1
restart_load 1 init_chg file + init_exx file + read_file_dir <dir>

Testing

  • abacus_max_para builds cleanly.
  • scf_hse_spin2_gamma: 6/6, including CompareEXX1_pass and CompareEXX2_pass.
  • scf_hf_multik: converges and matches the regenerated result.ref.
  • Round-trip A/B on Si2/HSE: the written E_exx is reproduced exactly when read back.

Notes

  • init_exx = file expects a single-frame file; use out_app_flag = 0 or 2 for
    restart files.
  • With out_freq_ion > 0, the final off-cadence ionic step no longer has the
    last_ion_step fallback, because that flag is not threaded into exx_iter_finish.
  • Governance exceptions (global dependency budget, docs sync) are documented in the
    commit messages.

abacus_fixer added 9 commits November 28, 2026 08:40
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.
@mohanchen mohanchen added EXX/lr-TDDFT/RPA/BSE/GW Related to beyond DFT methods Input&Output Suitable for coders without knowing too many DFT details Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests labels Nov 28, 2026
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.

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

EXX/lr-TDDFT/RPA/BSE/GW Related to beyond DFT methods Input&Output Suitable for coders without knowing too many DFT details Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove the GlobalC namespace from ABACUS

1 participant