Skip to content

refactor(input): replace fixed-value resets with shared requirements - #8495

Open
Stardust0831 wants to merge 14 commits into
deepmodeling:developfrom
Stardust0831:feat/input-choice-requirements
Open

Stardust0831 wants to merge 14 commits into
deepmodeling:developfrom
Stardust0831:feat/input-choice-requirements

Conversation

@Stardust0831

@Stardust0831 Stardust0831 commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

This PR reorganizes existing fixed-value INPUT resets into shared requirements. For example, calculation=md uses cal_force=true when omitted; an explicit cal_force=false now reports a conflict instead of being overwritten.

Linked Issue

Background: #7719

What's changed?

Register requirements on the parameter that directly controls them, using either an option list or a condition:

item.add_choice_requirement({"md", "relax", "cell-relax"}, "cal_force==true");
item.add_requirement("of_wt_rho0!=0", "of_hold_rho0==true");
  • Conditional defaults: when a rule applies, fixed scalar equalities (==, including those joined by and) supply the required values for omitted parameters, replacing their ordinary defaults. Sets, ranges, and or requirements only validate.
  • Explicit input takes precedence: is_explicit distinguishes user input, including 0 and false, from generated defaults. The migrated rules preserve explicit values and reject conflicts through the existing diagnostics and manual links.
  • Local ownership, shared handling: register each rule with its direct controlling parameter. For example, the restart requirement belongs to md_restart, with calculation==md as its scope.
  • One source for behavior and documentation: the same registrations generate the manual tables. Each option appears once; only options with identical complete requirements are grouped.

This replaces 16 complete reset callbacks and fixed assignments in three mixed callbacks. Other reset policies remain outside this migration. Existing Autotest inputs omit 41 conflicting declarations across 35 cases; requirements supply the same values as the former resets, with reference results unchanged.

Parameter Option or condition Requirements
calculation md, relax cal_force==true
calculation cell-relax cal_force==true and cal_stress==true
calculation get_wf cal_force==false and init_chg==atomic and chg_extrap==atomic and out_proj_band==false and bx==1 and by==1 and bz==1 and basis_type!=pw
calculation get_pchg cal_force==false and init_chg==atomic and chg_extrap==atomic and out_proj_band==false and basis_type!=pw
calculation get_s cal_force==false
calculation nscf scf_nmax==1
esolver_type tddft exx_separate_loop==false
esolver_type esolver_type in [lj, dp] and calculation==md cal_stress==true
symmetry -1, 0 exx_symmetry_realspace==false
basis_type pw, lcao_in_pw bx==1 and by==1 and bz==1
dft_functional hf, pbe0 rdmft_power_alpha==1
dft_functional muller rdmft_power_alpha==0.5
md_type md_type in [msst, npt] and calculation==md cal_stress==true
md_tfirst md_tfirst<0 and calculation==md init_vel==true
md_restart md_restart==true and calculation==md init_vel==true
md_pmode iso md_pcouple==xyz
of_kinetic of_kinetic!=wt of_read_kernel==false
of_wt_rho0 of_wt_rho0!=0 of_hold_rho0==true
of_full_pw false of_full_pw_dim==0
deepks_out_unittest true deepks_out_labels==1 and deepks_scf==true
bse_mem_save true bse_continue==0 and bse_ri_hartree==true
qo_switch true out_wfc_lcao==1
exx_singularity_correction exx_singularity_correction==limits and basis_type==pw exx_gamma_extra==false

For get_wf and get_pchg, basis_type!=pw is an existing requirement retained alongside the migrated rules. The unchanged gen_bessel requirement is omitted here.

Unit Tests and/or Case Tests for my changes

After merging current develop (67d6746c4), at fda234a00:

  • 121 tests in five serial suites, 22 four-rank MPI cases, 30 help tests, and six documentation-generator tests passed.
  • Generated the full keyword reference (629 parameters / 37 categories); representative requirement tables and links passed MyST checks.
  • C++11 syntax, whitespace, and PR governance checks passed. Two whole-file CMake formatting checks retain baseline failures; details below.
  • Fixture follow-up (618031a96): 31 complete INPUT files passed four-rank reader checks, and the 185-read requirement regression passed. Four fixtures need unavailable local FFTW-single/DeePKS features and await CI.
  • No full executable or numerical calculation was run locally.
Execution order and remaining reset policies

Rules run in registration order, immediately after the controlling parameter's remaining reset callback. This supplies scf_nmax before the output-frequency default consumes it, and resolves symmetry, basis aliases, and EXX automatic options before selecting their requirements. Each controller selects its rules from one snapshot; there is no dependency sorting or repeated solving. New rules validate effective values after normalization. Existing validation-only domain.add_requirement rules still check both original requests and effective values.

Existing trigger scopes are retained: for example, the RDMFT-alpha rule still follows the functional even if rdmft is false, and isotropic pressure coupling still follows md_pmode without an extra MD-only gate. Previously overwritten explicit conflicts in those scopes now fail.

Remaining reset callbacks retain their existing behavior and are not covered by this explicit-value guarantee. They include contextual/formula defaults, automatic markers, aliases, internal-state calculations, vector elements/lengths, OFDFT presets, symmetry overrides, and the method-plus-format init_wfc. DFT+U's vector-triggered disabling, PW gamma-only conversion with KPT generation, and the unused historical md_prec_level reset are also retained.

Two successful shared INPUT fixtures now explicitly satisfy the migrated constraints (md_pcouple=xyz, of_hold_rho0=1); separate tests cover the formerly overwritten conflicts.

Verification details and exact commands

Fixture verification at 618031a96: the initial upstream CPU/GPU failures were explicit scf_nmax conflicts in five NSCF cases and bx/by/bz conflicts in get_wf_spin2. All six errors reproduced with the original INPUT files and disappeared after omitting those fields. The same audit covered enabled later test groups, including MD velocity and TDDFT force declarations. Omitting cal_force=0 preserves the existing Autotest force-collection selection; changing it to 1 would add a reference quantity.

The four-rank fixture sweep initially accepted 27/35 files. Four SNAP inputs then passed with their existing model paths available in the scratch layout, giving 31 accepted files with four shutdown markers each. Two single-precision TDDFT and two DeePKS inputs stop at unavailable local build features; their numerical checks await CI. No reference, collector, C++ source, or workflow was changed in this follow-up.

python3 /tmp/abacus-pr8495-verify-fixtures.py
python3 /tmp/abacus-pr8495-verify-snap.py
OMP_NUM_THREADS=1 LD_LIBRARY_PATH=/tmp/npt8425-cpu/lib build-req/source/source_io/test_serial/MODULE_IO_read_item_serial --gtest_filter=InputTest.FixedRequirementsPreserveExplicitValuesInEitherOrder
python3 tools/03_code_analysis/agent_governance_check.py --staged --format text
git diff --cached --check

The local fixture harness invokes /tmp/npt8425-cpu/bin/mpiexec -n 4 build-req-mpi/source/source_io/unittests/MODULE_IO_input_error_mpi <absolute-INPUT-path> in isolated scratch directories with OMP_NUM_THREADS=1. These are input-reader checks, not full numerical reruns.

The serial suites include 37 context/target rows exercised through 185 reads: omitted values, explicit matching/conflicting values, both keyword orders, unchanged conflicting values, and explicit provenance. Full-reader regressions cover scf_nmax → out_freq_elec, the Wannier basis alias, explicit chg_extrap=default, resolved symmetry, EXX correction selection, inactive requirements, and existing noncollinear conflicts.

MPI cases check collective error exit and broadcasting of defaults for force, conditional stress, pressure coupling, and fixed OFDFT density. Six existing positive DFT+U cases are excluded because they require GENELPA and this build disables ELPA.

Documentation tests cover overlapping option groups, full-set grouping independent of registration order, duplicate removal, and preservation of compound conditions and nested alternatives. MyST parsed representative option, numerical-condition, and nested-alternative tables with their expected rows and valid links.

Reused GCC Debug builds with LCAO, OpenMP, Libxc, and JSON disabled; the MPI build uses MPICH and disables ELPA. Reader-level DeePKS tests exercise parsing/defaults without invoking the unavailable numerical backend. No full main executable, numerical integration, GPU/LCAO/ELPA-enabled calculation, or full Sphinx/PDF build was run; main-program abacus --version, -h, and --check-input therefore remain unverified.

The following build and test commands passed:

LIBRARY_PATH=/tmp/npt8425-cpu/lib /tmp/dpa4c-ipi-kokkos-cmake/unpacked/cmake/data/bin/cmake --build build-req --target MODULE_IO_availability MODULE_IO_input_domain MODULE_IO_read_input_serial MODULE_IO_input_domain_reader MODULE_IO_read_item_serial abacus_input_yaml -j 4
OMP_NUM_THREADS=1 LD_LIBRARY_PATH=/tmp/npt8425-cpu/lib /tmp/dpa4c-ipi-kokkos-cmake/unpacked/cmake/data/bin/ctest --test-dir build-req -V -R '^MODULE_IO_(availability|input_domain|read_input_serial|read_item_serial|input_domain_reader)$'
LIBRARY_PATH=/tmp/npt8425-cpu/lib LD_LIBRARY_PATH=/tmp/npt8425-cpu/lib PATH=/tmp/npt8425-cpu/bin:$PATH /tmp/dpa4c-ipi-kokkos-cmake/unpacked/cmake/data/bin/cmake --build build-req-mpi --target MODULE_IO_input_error_mpi MODULE_IO_input_help_test -j 4
OMP_NUM_THREADS=1 LD_LIBRARY_PATH=/tmp/npt8425-cpu/lib PATH=/tmp/npt8425-cpu/bin:$PATH /tmp/dpa4c-ipi-kokkos-cmake/unpacked/cmake/data/bin/ctest --test-dir build-req-mpi -V -R '^MODULE_IO_(input_error_mpi_.*|input_help_test)$' -E 'mpi_dftu_(default|fll|amf|mixed0|mixed05|mixed1)$'

Documentation and source checks passed:

/tmp/abacus-input-default-stages-docenv-20261201/bin/python -m unittest discover -s docs -p test_generate_input_main.py -v
LD_LIBRARY_PATH=/tmp/npt8425-cpu/lib build-req/source/source_io/abacus_input_yaml > /tmp/abacus-req-owner-parameters.yaml
/tmp/abacus-input-default-stages-docenv-20261201/bin/python docs/generate_input_main.py /tmp/abacus-req-owner-parameters.yaml --output /tmp/abacus-req-table-input-main.md
/tmp/abacus-input-default-stages-docenv-20261201/bin/python /tmp/abacus-check-req-table-render.py
g++ -std=c++11 -Isource -fsyntax-only source/source_io/module_parameter/input_domain.cpp
python3 tools/03_code_analysis/agent_governance_check.py --base upstream/develop --head HEAD --format text --event-path /tmp/abacus-choice-pr-event.json
git diff --check upstream/develop HEAD

Formatting-scope audit passed:

PYTHONPATH=/tmp/pr8444-format-tools python3 /tmp/abacus-fixed-check-cmake-format-scope.py

Whole-file formatting check retains baseline failures in the two files noted below:

PYTHONPATH=/tmp/pr8444-format-tools python3 -m cmakelang.format --check source/source_io/module_parameter/test/CMakeLists.txt source/source_io/unittests/CMakeLists.txt source/source_io/unittests/test_read_input.cmake
Development checklist and governance notes

Reminder

  • Read AGENTS.md, agent governance, and CMake guidelines.
  • Link the background issue and describe INPUT behavior and metadata changes.
  • Add focused tests and list commands, results, and limitations.
  • Explain core-module impact and governance findings.

Governance Notes

  • Core module impact is limited to INPUT preparation and requirement metadata; numerical solver code is unchanged.
  • The modified legacy domain test is moved to unittests/test_input_domain.cpp with its existing CMake target updated; it has no Makefile or pyabacus source-list entry.
  • Whole-file cmake-format --check still fails on source/source_io/unittests/CMakeLists.txt and source/source_io/unittests/test_read_input.cmake. Comparing exact formatter edits at the original base (6273e2568) and current version confirms that all remaining discrepancies already exist at the base. Those files are unchanged between that base and current upstream. The module-parameter CMake file passes. Unrelated formatting is excluded; no formatter configuration or CI rule is changed.
  • No governance exception requested.

@Stardust0831
Stardust0831 marked this pull request as draft December 3, 2026 00:17
@Stardust0831
Stardust0831 marked this pull request as ready for review December 3, 2026 00:21
@mohanchen mohanchen added Refactor Refactor ABACUS codes Input&Output Suitable for coders without knowing too many DFT details labels Dec 3, 2026
@Stardust0831 Stardust0831 reopened this Dec 3, 2026
@Stardust0831
Stardust0831 force-pushed the feat/input-choice-requirements branch 2 times, most recently from d0ac9bf to 9470bf5 Compare December 4, 2026 10:33

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

Input&Output Suitable for coders without knowing too many DFT details Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants