Repository navigation
refactor(lr): slim ESolver_LR by moving LR state and logic into module_lrrefactor(lr): slim ESolver_LR by moving LR state and logic into module_lr (fix #8438) - #8439
Open
mohanchen wants to merge 27 commits into
Conversation
added 25 commits
November 28, 2026 14:27
Extract set_dimension/reset_dim_spin2 from ESolver_LR into LR::resolve_dim and LR::apply_spin_pol so the solver only assembles inputs and copies the resolved dimensions back. Rename the members to set_dim/reset_dim_spin and register lr_dim.cpp in both build systems.
Add LR::set_band_layout, make_amp_layout, set_x_init, read_wfc_*, build_z_win and read_gs_chg so esolver_lr_orb.cpp only forwards member state. Wavefunction/charge reading, amplitude distributions and the Z-vector window no longer depend on the solver class.
…ring into module_lr Add LR::GsPot, LR::make_gs_dm and LR::make_lr_exx so the force path and the ks-lr initialization only forward member state. lr_dm is a separate translation unit so the cal_edm unit test keeps its slim link set.
Add LR::RelaxTarget so the relaxation state (followed root, multiplet group, previous amplitudes) lives in module_lr and the solver only forwards energies and amplitudes. Remove the duplicated target members from ESolver_LR.
Merge esolver_lr_cfg/orb/grad/rlx.cpp into esolver_lr_lcao_tddft.cpp so a single translation unit holds the remaining solver-side code. Drop the freed source files from both build systems.
Merge esolver_lr_init.cpp into the main implementation and rename the pair so the solver lives in one header and one translation unit. Update the BSE subclass and the factory includes, and keep the EXX/JSON conditional includes intact. ESolver_LR and its BSE-visible members are unchanged.
The governance checker counts comment text as a global dependency, which made the refactor look like a net +1. Describe the field instead.
Add LR::build_mpl and LR::eval_jt_force, which own the polarization identity, the basis diagnostics and the Jahn-Teller search. The solver keeps only the Z-vector callback and the target-state bookkeeping, and the dead MultipletLVC::average_force goes away.
The member had no definition and no caller; the GintInfo hand-off both paths use is ModuleGint::Gint::set_gint_info.
cal_edm, Parallel_Reduce, <numeric> and state_track are now pulled in only where they are actually used.
Drop the share_exx_lri specialisations (call LR::make_lr_exx directly), the unused GsPot::pot accessor and MplLvc::dim.
…o module_lr Add LR::setup_x, LR::read_gs_wfc and LR::pad_group; drop the set_parallel_orbitals_band wrapper in favour of LR::set_band_layout.
Add LR::GsForceCtx, LR::solve_zeq, LR::force_xz and LR::force_xz_os; the solver now only fills the context and keeps the timers.
Introduce LR::Amp, LR::PotSet, LR::RelaxRun and LR::Core in module_lr so the amplitudes, Z window, potentials and relaxation state stop being members of ESolver_LR. All accesses go through lr_.<group>.<field>; the functions still live in the esolver for now.
LR::Core now owns LR::Dim and LR::GsState; Core::read_wfc and Core::fill_z absorb the former read_ks_wfc/fill_z_window_ bodies. Drop the unused pad_X_to_z_ wrapper.
Add LR::Refs, the borrowed geometry handles the force path needs, and bind them once from the esolver. The per-state/Z-window context builders, the force/gradient entry points, the ground-state density matrix, and the excited-state relaxation (target setup, root following, average/JT force) now live in module_lr. The esolver keeps only the thin virtual overrides.
The LR runtime logs are the same streams as GlobalV::ofs_running and GlobalV::ofs_warning, but using the members keeps the global dependency budget from growing.
Resolve conflicts from forcing the LR esolver refactor onto the newer upstream tree, and port the semantic changes of deepmodeling#8329 (LR force output, spin selection, virtual-window response, XC kernels) into the new module_lr layout: - window response: force_xz / force_xz_os build the WindowResponse from the X-window virtual count and pass its density to the Z-vector solve and its terms to the force evaluation; solve_zeq takes window_density - fill_z: real-Gamma virtual-window diagnosis matches deepmodeling#8329 - spin selection: nspin==1 labels the single channel with lr_target_spin, and lr_target_spin=triplet no longer aborts on nspin=1 - output: electron-hole densities are labelled singlet/triplet or up/down - runner: cache the ground-state force for single-point excited states - cal_force: print the cached ground-state force - BSE: keep the refactored lr_.dim / lr_.amp members with upstream's explicit types
The Z window widens the virtual space for the CPSCF (Z-vector) solve, but
the virtual-window response must be built for the virtuals the caller
actually solved for, i.e. the X window. Passing the widened count made
the response too large and shifted the triplet forces by ~0.1%:
lr_tddft_lda_triplet_window_gamma
before: 88.7758685201 after: 88.7747473201 (reference)
force_xz / force_xz_os now take the active virtual count explicitly;
Core passes dim.nvirt and state_forces passes StateCtx::nvirt.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix #8438
Summary
Makes
ESolver_LRa thin adapter and moves the linear-response TDDFT state andalgorithms into
source_lcao/module_lr. No behaviour change: same inputs, sameoutputs, same numerical results.
The LR esolver used to be seven files (~2550 lines) under
source/source_esolver/.It is now a single
esolver_lr.{h,cpp}(~760 lines); the algorithms live next to therest of the LR module.
Design
LR::Core<T>(newlr_core.{h,cpp}) owns the LR solver state:Dim,Amp,GsState,ZWin,PotSet,RelaxRun, and the borrowedRefs.LR::Refs<T>is a set of plain pointers/handles to objects the esolver alreadyowns (
ucell,kv,gd,orb_cutoff,rho/rhod,vloc,sfac,tcb,inp,log streams,
pgrid, in/out dirs,xc_kernel, rank,pv_all, and under__EXXa pointer to the
shared_ptr<Exx_LRI<T>>plushybrid_alpha). The esolver bindsthem once;
module_lrnever includes an esolver header.LR::KsBands<T>(POD) carries the per-ionic-step ground-state bands(psi/eig/wg + layout) into
Core::refresh_gs.LR::DimSrccarries the few esolver/global quantities dimension resolution needs,so
lr_dimno longer reads them implicitly.What moved into
module_lrlr_dim).lr_gs).(
potentials/lr_gs_pot,init_helpers).lr_amp,lr_mpl).Core::solve).gradients (
Core::output).lr_sforce,lr_zeq,lr_dm,gradient_*).(
lr_relax,lr_mpl).What the esolver keeps
Only orchestration and adaptation, because it is inherently esolver-typed:
ESolver_FP::before_all_runners(PW grids, structure factor,kv.set,atom_arrange, symmetry, pseudopotential/nonlocal data).ESolverinterface adapters:cal_energy,cal_force,cal_stress.init_pot/read_ks_wfc/read_ks_chg, kept as one-line delegations becauseBSE overrides or calls them.
Notes
Refsbinding is hoisted ahead ofrefresh_from_ks_/init_pot, since thepotentials now read
Refs.Parallel_Orbitalsmembers (paraMat_,paraMat_all_) were removed; the standalone path now uses the realgs.para_mat/gs.para_mat_alllayouts (previously wrong under MPI).ks-lrinitialisation before the embeddedground-state SCF is kept and still pairs with
Relax_Driver's step-0 skip.esolver_lr.cpp.Verification
cmake --build build -j 56(CPU; including theesolvertarget with BSEand all LR unit-test targets).
tests/08_RI/lr_tddft_lda_gamma->CompareLRForce_pass 0,totalforceref 115.0726395253,excitationenergyref1 0.587347tests/08_RI/lr_relax_lda_ch4->CompareStateTracking_pass 0tools/03_code_analysis/agent_governance_check.py: 0 errors, global-dependencynet delta <= 0.
Diff shape
source/source_esolver/esolver_lr.{h,cpp}: the whole LR esolver in one place.source/source_lcao/module_lr/:lr_core,lr_dim,lr_gs,lr_amp,lr_mpl,lr_relax,lr_dm,lr_zeq,lr_sforce,potentials/lr_gs_pot,init_helpers.esolver_lr_init.cpp,esolver_lr_cfg.cpp,esolver_lr_grad.cpp,esolver_lr_lcao_tddft.{h,cpp},esolver_lr_orb.cpp,esolver_lr_rlx.cpp.## SummaryMakes
ESolver_LRa thin adapter and moves the linear-response TDDFT state andalgorithms into
source_lcao/module_lr. No behaviour change: same inputs, sameoutputs, same numerical results.
The LR esolver used to be seven files (~2550 lines) under
source/source_esolver/.It is now a single
esolver_lr.{h,cpp}(~760 lines); the algorithms live next to therest of the LR module.
Design
LR::Core<T>(newlr_core.{h,cpp}) owns the LR solver state:Dim,Amp,GsState,ZWin,PotSet,RelaxRun, and the borrowedRefs.LR::Refs<T>is a set of plain pointers/handles to objects the esolver alreadyowns (
ucell,kv,gd,orb_cutoff,rho/rhod,vloc,sfac,tcb,inp,log streams,
pgrid, in/out dirs,xc_kernel, rank,pv_all, and under__EXXa pointer to the
shared_ptr<Exx_LRI<T>>plushybrid_alpha). The esolver bindsthem once;
module_lrnever includes an esolver header.LR::KsBands<T>(POD) carries the per-ionic-step ground-state bands(psi/eig/wg + layout) into
Core::refresh_gs.LR::DimSrccarries the few esolver/global quantities dimension resolution needs,so
lr_dimno longer reads them implicitly.What moved into
module_lrlr_dim).lr_gs).(
potentials/lr_gs_pot,init_helpers).lr_amp,lr_mpl).Core::solve).gradients (
Core::output).lr_sforce,lr_zeq,lr_dm,gradient_*).(
lr_relax,lr_mpl).What the esolver keeps
Only orchestration and adaptation, because it is inherently esolver-typed:
ESolver_FP::before_all_runners(PW grids, structure factor,kv.set,atom_arrange, symmetry, pseudopotential/nonlocal data).ESolverinterface adapters:cal_energy,cal_force,cal_stress.init_pot/read_ks_wfc/read_ks_chg, kept as one-line delegations becauseBSE overrides or calls them.
Notes
Refsbinding is hoisted ahead ofrefresh_from_ks_/init_pot, since thepotentials now read
Refs.Parallel_Orbitalsmembers (paraMat_,paraMat_all_) were removed; the standalone path now uses the realgs.para_mat/gs.para_mat_alllayouts (previously wrong under MPI).ks-lrinitialisation before the embeddedground-state SCF is kept and still pairs with
Relax_Driver's step-0 skip.esolver_lr.cpp.Verification
cmake --build build -j 56(CPU; including theesolvertarget with BSEand all LR unit-test targets).
tests/08_RI/lr_tddft_lda_gamma->CompareLRForce_pass 0,totalforceref 115.0726395253,excitationenergyref1 0.587347tests/08_RI/lr_relax_lda_ch4->CompareStateTracking_pass 0tools/03_code_analysis/agent_governance_check.py: 0 errors, global-dependencynet delta <= 0.
Diff shape
source/source_esolver/esolver_lr.{h,cpp}: the whole LR esolver in one place.source/source_lcao/module_lr/:lr_core,lr_dim,lr_gs,lr_amp,lr_mpl,lr_relax,lr_dm,lr_zeq,lr_sforce,potentials/lr_gs_pot,init_helpers.esolver_lr_init.cpp,esolver_lr_cfg.cpp,esolver_lr_grad.cpp,esolver_lr_lcao_tddft.{h,cpp},esolver_lr_orb.cpp,esolver_lr_rlx.cpp.