source_estate: print_etot takes its INPUT parameters explicitly, removing elecstate_print_test's access hack - #7991
Merged
mohanchen merged 2 commits intoSep 18, 2026
Conversation
…ving elecstate_print_test's access hack All fourteen of elecstate_print.cpp's global reads were inside one function, print_etot(), and it has exactly one production call site. print_etot() now takes `const Input_para& inp` and the derived `two_fermi` flag, inserted before the existing defaulted arguments so no new default argument is introduced. elecstate_print.cpp is now PARAM-free. esolver_ks.cpp already holds an injected inp_ and already passes *this->inp_ to ModuleIO::write_bands on the same path, so the one call site follows a pattern that is already there. The test owns an Input_para and a two_fermi bool instead of writing the private half of PARAM. Its PARAM.sys.log_file write was dead -- no source compiled by MODULE_ESTATE_elecstate_print reads it -- and is dropped. Passing the whole Input_para rather than thirteen separate flags is deliberate: print_etot's job is to report the INPUT-driven state, and thirteen parameters would be worse than the aggregate it is actually printing. No production logic changed. No assertion or expected value changed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
mohanchen
approved these changes
Sep 18, 2026
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.
What this does
All fourteen of
elecstate_print.cpp's global reads were inside one function,print_etot(), and it has exactly one production call site.print_etot()now takes
const Input_para& inpplus the derivedtwo_fermiflag, andelecstate_print.cppisPARAM-free.PARAM/GlobalV/GlobalCledger: added 1, removed 58, net_delta = −57.Zero blockers.
The two new parameters are inserted before the existing defaulted arguments,
so no new default argument is introduced (governance blocks that).
esolver_ks.cppalready holds an injectedinp_and already passes*this->inp_toModuleIO::write_bandson the same code path, so the single callsite follows a pattern that is already in that file.
Why the whole
Input_pararather than separate flagsprint_etot()reads thirteen distinct INPUT keys —basis_type,out_freq_elec,scf_nmax,vdw_method,dft_plus_u,imp_sol,efield_flag,gate_flag,deepks_scf,ml_exx,out_level,nspin,esolver_type,ks_solver. Thirteen parameters would be worse than theaggregate the function is actually reporting: its job is to print the
INPUT-driven state.
two_fermiis passed separately because it is derived andlives in
System_para, notInput_para.Test side
The fixture owns an
Input_paraand atwo_fermibool instead of writing theprivate half of
PARAM. ItsPARAM.sys.log_filewrite was dead — no sourcecompiled by
MODULE_ESTATE_elecstate_printreads it — and is dropped.I also checked the other headers the macro region covered (
klist.h,charge.h,efield.h,gatefield.h,xc_functional.h): the test touches noprivate member of any of them. Its two
XC_Functional::func_type/ked_flaglines are out-of-line definitions, which need no access.Verification
Remote Linux box,
cmake -B build -G Ninja -DBUILD_TESTING=ON -DENABLE_LCAO=ON -DENABLE_MPI=ON -DENABLE_OPENMP=ON: configure and build exit 0,3354/3354 targets, zero errors.
agent_governance_check.py: zero blockers,no access-hack ratchet finding (1 removed, 0 added).
No production logic changed. No assertion or expected value changed. No INPUT
parameter or user-facing behaviour changed, so no documentation update is
required.
The two sibling files are not in this PR
elecstate_energy_testandelecstate_pw_testwere scoped alongside this one,and measuring them showed they are not the same problem, so they are left for
separate PRs rather than bundled in half-done:
elecstate_energy_test(1 macro) — 7 of its 12 written keys are dead(
basis_type,esolver_type,lspinorb,nelec,nlocal,nupdown,two_fermihave no reader inMODULE_ESTATE_elecstate_energy). The live onesneed
nspininjected intocal_delta_eband(8 call sites) andcal_delta_escf(2), andimp_sol/sc_mag_switch/dft_plus_u/nspininto
cal_energies(9) — 19 call sites across 12 files, and two of them(
chgmixing.cpp,rdmft.cpp) have no injectedinp_to draw on. Mechanicalbut wide.
elecstate_pw_test(2 macros) — the hard one. Of its 25 global reads, threeare in
~ElecStatePW(), and a destructor cannot take parameters.device,precision,double_gridanduse_uspptherefore have to become member statecaptured at construction — the same move this campaign used for
Charge::nelecin source_estate: decouple Charge from PARAM, plus two setters on XC_Functional — removes charge_test's two access hacks (touches module_xc) #7990, but across six methods of a template class. That is a design change,
not a signature change. It also needs the
XC_Functional::set_func_type()addedin source_estate: decouple Charge from PARAM, plus two setters on XC_Functional — removes charge_test's two access hacks (touches module_xc) #7990, so it should land after that.
Continues #7921 / #7949 / #7952 / #7953 / #7963 / #7964 / #7965 / #7966 / #7967 /
#7980 / #7981 / #7982 / #7983 / #7984 / #7987 / #7988 / #7989 / #7990.
🤖 Generated with Claude Code