Skip to content

source_estate: print_etot takes its INPUT parameters explicitly, removing elecstate_print_test's access hack - #7991

Merged
mohanchen merged 2 commits into
deepmodeling:developfrom
Critsium-xy:refactor/elecstate-explicit-input
Sep 18, 2026
Merged

mohanchen merged 2 commits into
deepmodeling:developfrom
Critsium-xy:refactor/elecstate-explicit-input

Conversation

@Critsium-xy

Copy link
Copy Markdown
Collaborator

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& inp plus the derived two_fermi flag, and
elecstate_print.cpp is PARAM-free.

PARAM/GlobalV/GlobalC ledger: 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.cpp already holds an injected inp_ and already passes
*this->inp_ to ModuleIO::write_bands on the same code path, so the single call
site follows a pattern that is already in that file.

Why the whole Input_para rather than separate flags

print_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 the
aggregate the function is actually reporting: its job is to print the
INPUT-driven state. two_fermi is passed separately because it is derived and
lives in System_para, not Input_para.

Test side

The fixture 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.

I also checked the other headers the macro region covered (klist.h,
charge.h, efield.h, gatefield.h, xc_functional.h): the test touches no
private member of any of them. Its two XC_Functional::func_type /
ked_flag lines 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_test and elecstate_pw_test were 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:

Continues #7921 / #7949 / #7952 / #7953 / #7963 / #7964 / #7965 / #7966 / #7967 /
#7980 / #7981 / #7982 / #7983 / #7984 / #7987 / #7988 / #7989 / #7990.

🤖 Generated with Claude Code

Critsium-xy and others added 2 commits September 18, 2026 16:38
…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 mohanchen added Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels Sep 18, 2026
@mohanchen
mohanchen merged commit b1d6dfc into deepmodeling:develop Sep 18, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants