Repository navigation
feat(input): unify parameter value and dependency validation - #8192
Conversation
|
IIUC |
InputDomain already checks the allowed precision values and the LCAO restriction. Keep the CPU single-precision FFTW build check in the legacy callback.
@Growl1234 Thanks for the review! I've addressed your comments and also removed duplicate validation for precision and ks_solver, and simplified elax_method parsing to use the shared validator. Checks for required libraries and build options remain in place. |
ABACUS-PR-BOT
left a comment
There was a problem hiding this comment.
Static review of f87735bb84f44208f6b9075684f8edbab4e41517 against 3ab6d32e7f45e626e98fdcf0121c3d6aa3e6b2ba, independently cross-checked. One compatibility issue and three optional source/test clarifications are inline. Verification was limited to source review, static probes and git diff --check; no build, runtime/MPI or CI checks were run.
Non-blocking: please add the exact local validation commands, relevant build options and executable version, or link a revision-bound log. The Validation section lists successful SCF/MPI/CLI/C++11 checks but does not currently record how those local checks were run; the CI links can remain as separate evidence.
|
Recorded follow-ups (pre-existing, not introduced by this PR):
|
Thanks for the suggestion. I recovered the archived local validation records; the commands and relevant build options are below. The CPU builds used GCC 13.4, Release mode, At commit cmake --build /tmp/abacus-input-domain-build \
--target MODULE_IO_input_domain_reader MODULE_IO_read_item_serial \
MODULE_IO_read_input_serial abacus_pw_omp -j 12
ctest --test-dir /tmp/abacus-input-domain-build -V \
-R '^MODULE_IO_(input_domain_reader|read_item_serial|read_input_serial)$'
/tmp/abacus-input-domain-build/abacus_pw_omp --version
/tmp/abacus-input-domain-build/abacus_pw_omp -h ks_solver
/tmp/abacus-input-domain-build/abacus_pw_omp -h relax_methodA local CLI harness also passed 11 solver/relaxation cases, covering accepted configurations, incompatible solvers, retained build-capability checks, and missing/unknown/multiple relaxation values. Earlier verification during this PR included the following commands: # Core input validation: 5 targets / 70 tests passed.
ctest --test-dir /tmp/abacus-input-domain-build -V \
-R '^MODULE_IO_(input_domain(_reader)?|read_item_serial|read_input_serial|availability)$'
# Help formatting: 30 tests passed.
cmake --build /tmp/abacus-input-domain-mpi-build \
--target MODULE_IO_input_help_test -j 12
ctest --test-dir /tmp/abacus-input-domain-mpi-build -V \
-R '^MODULE_IO_input_help_test$'
# Documentation generator: 3 tests passed.
python3 -m unittest discover -s docs -p test_generate_input_main.py -v
# Standalone C++11 compilation passed.
g++ -std=c++11 -Isource \
-c source/source_io/module_parameter/input_domain.cpp \
-o /tmp/abacus-8192-domain-cxx11.o
# MPI executable and parameter-test build passed.
cmake --build /tmp/abacus-input-domain-mpi-build \
--target abacus_pw_para MODULE_IO_input_test_para -j 12Runtime checks used |
Related to #7719.
ABACUS can silently replace an explicitly supplied INPUT value during default/reset processing, hiding invalid values before the old checks run. This PR introduces a shared legal-value and dependency-validation stage that reports invalid user input clearly, explains the legal values or required combination, and links directly to the parameter's manual section. Omitted parameters keep their existing contextual defaults. Valid explicit
0,false, documented automatic/disabled options, and physical negative values retain their meanings.The implementation is a general mechanism used across the parameter registry. Registrations declare choices, numerical predicates and conditional requirements; common code performs the checks and formats diagnostics. There are no parameter-name branches or newly handwritten per-parameter validation callbacks. The earlier magnetic-mixing and
mem_saverfixes (#8185, #8186) are already in the merged base; this PR builds on those fixes.The shared validator replaces duplicate checks for
precision,ks_solverandrelax_method. Checks for required libraries and build options remain. GPU test preparation inserts a newline before appendingdevice gpu, keeping INPUT files valid even when they lack a trailing newline.Shared contracts and coverage
scf_thr_typeandsymmetryas well asnspinandgga_grad.sync_*registrations provide typed read-only access to values, including nested MD fields and vectors. Runtime checking does not format final values and parse them back.==,!=,<,<=,>,>=,in,contains,and,or). Registration-time validation rejects unknown references, incompatible operand types, nonfinite rule literals and unsupported vector/scalar comparisons.abacus -h, parameter YAML and the generated INPUT manual.basis_type,calculation,symmetry,ks_solver,device,precision,gint_precision,pcc_2d_axis,fft_mode,diag_subspace,mem_savernspin,gga_grad,nupdown,nbands,nelec,nb2d,bx,by,bz,mixing_beta,mixing_beta_mag,scf_thr,scf_thr_type,scf_os_thr,dfthalf_type,use_k_continuityrelax_method,force_thr,force_thr_ev,fixed_axes,fixed_ibrav,fixed_atoms,md_type,md_thermostat,md_pcouple,msst_qmassout_wfc_pw,out_wfc_lcao,out_librpa_verdeepks_bandgap,deepks_v_delta,deepks_out_freq_elec,deepks_out_base,bessel_descriptor_rcut,dfpt_max_iter,td_dt,lin_maxiter,lin_gmres_restartdip_cor_flag,efield_dir,vdw_method,vdw_d4_model,vdw_c6_unit,vdw_r0_unit,vdw_radius_unit,vdw_cn_thr_unit,vdw_cutoff_type,vdw_cutoff_width2,vdw_cutoff_width3,vdw_cn_thrsc_mag_switch,sc_thr,nsc,nsc_min,alpha_trial,sccut,sc_scf_thr,sc_lambda_strategy,rdmft_power_alpha,ecutexx,exx_batch_size,exx_ene_thr,method_stoecutwfc,ecutrhoPreparation and validation flow
Normal execution and
--check-inputcall the same preparation path. These two compact horizontal diagrams form one sequence. Green marks shared validation; red marks rejection.flowchart LR A[INPUT tokens] --> B{Explicit values<br/>valid?} B -->|No| E[Error + legal rule<br/>+ manual link] B -->|Yes| C[Read typed values<br/>retain supplied values] C --> D[Existing defaults<br/>and aliases] classDef check fill:#e8f5e9,stroke:#388e3c classDef error fill:#ffebee,stroke:#c62828 class B check class E errorFirst, invalid explicit values fail before default/reset code can hide them. Omitted parameters skip this explicit-input check. Typed snapshots preserve the supplied values while existing preparation computes defaults.
flowchart LR A[Defaults ready] --> B{Value and dependency<br/>rules pass?} B -->|No| E[Error + legal rule<br/>+ manual link] B -->|Yes| C[Context and remaining<br/>specialized checks] C --> D[Start calculation] classDef check fill:#e8f5e9,stroke:#388e3c classDef error fill:#ffebee,stroke:#c62828 class B check class E errorThe second phase checks declared requirements with explicit snapshots taking precedence over prepared defaults, so a legacy reset cannot erase a conflicting user request. It then validates effective domains and requirements. For example,
nspin=1, nupdown=1remains invalid: the previous code already rejected this combination, and the shared stage now reports it with the standardized requirement diagnostic and manual link. Independent errors are collected; the error is broadcast before parameter broadcasts so MPI ranks exit consistently.Applicability metadata and hard requirements keep distinct meanings. A disabled option such as
out_wfc_lcao=0is valid for PW; a nonzero value requires LCAO. The reviewedmem_saverrestriction remainscalculation in [scf, relax] => mem_saver==0, without adding a blanket basis restriction from its descriptive availability field.Examples and standardized diagnostics
scf_thr_type -11, 2scf_thr_type1for PW or2for LCAO; the resulting value is checked against the same choicesscf_thr_type 2for PWsymmetry 2-1, 0, 1nspin 3,nspin 2abc,nspin 2 4, barenspinnspin +2,nspin 02nspin 2withnoncolin truenspin==4mem_saver 1for SCFmem_saver==0; no silent resetmixing_beta nan,cal_force maybemixing_beta 0, explicit magnetic mixing0.2 / 0.71.6upper bound is inferred from a default formulascf_ene_thr -1,nbspline -1,mixing_angle -10md_pfirst -2, explicitmd_plast -1nspin 1withgga_grad 2Representative output:
scf_thr_typeuses an integer field andsymmetrycurrently uses a string field; the validator follows their actual typed bindings. Internal-1/-10initializers are not automatically added to public legal values. No nullable-field ornullinput conversion is introduced. Existing default representations and calculation semantics are retained.Compatibility and limits
Stricter parsing intentionally rejects numeric prefixes, extra scalar tokens, nonfinite reals and explicit internal placeholders that were previously accepted or reset. Legal empty strings/vectors, Boolean aliases, absolute paths, and existing trailing
//comments remain supported. An inactive internal marker outside its declared public domain is omitted when writing reusable INPUT; the in-memory value is unchanged and writer/reader round trips are tested.symmetryfollows its existing string binding and accepts the literal values-1,0, and1. Numeric-equivalent spellings such as+1,01, and-0are now rejected; ordinary integer parameters continue to accept complete integer spellings with a plus sign or leading zeros.The declarations use the documented option lists and existing guards. Recommendations and bounds in default formulas are not promoted to hard limits. Specialized grammars, vector cardinality involving structure, build capabilities and other context-sensitive checks retain their existing handlers. The generic engine can be reused by additional declarations; this PR does not infer constraints from arbitrary prose. Existing reset hooks are still present, so this PR does not claim every legal-to-legal overwrite in #7719 has been eliminated. The
gamma_onlyconvenience behavior remains available.Recorded follow-up constraints
Three existing runtime restrictions still need shared declarations and are recorded for discussion in later PRs. In a valid Si case,
--check-inputaccepts each input below, while full execution rejects it through the existing runtime guard:mixing_beta 1.1value>=00<=mixing_beta<=1efield_flag truewithefield_dir 80,1, or2fixed_axes wrongshape/volumedependency onrelax_method==cgNone,volume,shape,a,b,c,ab,ac,bc, orabcThese runtime guards remain in place. The shared declarations therefore do not yet describe every restriction enforced during execution. Automatic scalar parsing coverage is also limited to the ordinary readers noted above; custom scalar readers such as
nupdownandnxretain their existing parsing behavior.Validation
CI passed CPU/MPI tests (including all 58 IO test targets), CUDA tests, the build matrix, and both documentation builds (abacus-develop, abacus-rtd).