Skip to content

Refactor: structured INPUT parameter availability (Phase 1) - #7783

Open
Stardust0831 wants to merge 2 commits into
deepmodeling:developfrom
Stardust0831:upstream-ready
Open

Refactor: structured INPUT parameter availability (Phase 1)#7783
Stardust0831 wants to merge 2 commits into
deepmodeling:developfrom
Stardust0831:upstream-ready

Conversation

@Stardust0831

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

Ref #7719 — normalize INPUT availability into a machine-readable form and align it with parameter validation.

Unit Tests and/or Case Tests for my changes

  • Commands run:
    • python3 tools/03_code_analysis/test_availability_parser.py — 17 tests, all pass (incl. precedence for and/or/parentheses, contains semantics, and a validation that every non-empty availability in docs/parameters.yaml parses as Expression).
    • New C++ parser unit test source/source_io/test_serial/availability_test.cpp wired into the test build (BUILD_TESTING=ON); covers leaf/in-set/contains/and-or nesting/round-trip/empty/string-end edge inputs.
    • Remote CPU build + abacus --generate-parameters-yaml — COMPLETED; regenerated docs/parameters.yaml and input-main.md (generated output byte-consistent with the checked-in docs).
  • Result summary: docs/parameters.yaml has 526 params / 216 non-empty availability, all concrete boolean Expression (0 Label / 0 Unstructured).
  • Checks not run, with reason: full runtime/MPI test suite not run — this change is metadata-only (availability strings + help export); no numerical or code-path behavior change.

What's changed?

Make the Input_Item availability field a single-source, machine-evaluable boolean condition so the INPUT docs, validation and tooling can consume and evaluate it instead of re-parsing free text or bare tags.

  • C++ data model: new dependency-free module source/source_io/module_parameter/availability.{h,cpp} (wired into CMake) with AvailabilityCondition / AvailabilityExpr and parse_availability() (operators ==/!=/>/>=/</<=/in/contains, combinators and/or/,, (...) grouping). Input_Item keeps the canonical availability string plus availability_expr (parsed tree) and a set_availability() helper keeping both in sync (single source of truth).
  • Migration: all 217 non-empty availability registrations rewritten to canonical boolean syntax. Former bare "label"-style tags (OFDFT, Numerical atomic orbital basis, ...) are now concrete conditions over existing parameters (esolver_type==ofdft, basis_type==lcao, calculation==gen_bessel, dft_plus_u==1, ...). Vector parameters use contains (e.g. td_ttype contains 2) to preserve containment semantics.
  • Export: --generate-parameters-yaml now emits the canonical availability string (empty string = always available) and nothing else, keeping the YAML lean; the structured parse tree stays in C++ for a future validation/error layer.
  • Docs: regenerated docs/parameters.yaml and input-main.md.

Manual fidelity: rewrites preserve the manual's original meaning. Where the manual states a gate the code does not enforce via an INPUT boolean, it is called out in Governance Notes.

Governance Notes

  • INPUT/docs changes: docs/parameters.yaml and docs/advanced/input_files/input-main.md regenerated from the new binary (per AGENTS.md). Full old→new mapping was reviewed locally.
  • Core module impact: source/source_io/module_parameter/input_item.h gains an availability_expr member and the new availability module; metadata-only, no runtime/numerical behavior change.
  • Exceptions requested:
    • Header dependency review: input_item.h includes availability.h because Input_Item holds AvailabilityExpr by value (a forward declaration is not possible); availability.h includes <string>/<vector> for its members (std::string, std::vector). Required includes, not reducible to forward declarations.
  • Manual-vs-code discrepancies documented (not acting on them in this PR):
    • mixing_dmr: manual >= 0.0 (always true) kept as mixing_restart>=0; esolver checks > 0 — likely loose manual wording.
    • mixing_tau: "Only relevant for meta-GGA" is a note decided at runtime (XC_Functional::get_ked_flag), not an INPUT gate; availability empty, note kept in description.
    • fixed_ibrav: encoded as relax_method in [cg 2] and latname != none (both manual clauses; the latter also enforced by check_value).

The Input_Item availability field mixes prose and ad-hoc conditions as free
text, which cannot be consumed programmatically for tree-structured docs,
validation or agent tooling.

Add a small dependency-free parser (tools/03_code_analysis/availability_parser.py)
that normalises the historical spellings (==, =, 'is set to', 'contains')
onto a canonical form and classifies each value as an Expression, a bare
Label, or Unstructured prose waiting for review.

- availability_parser.py: parse_availability() -> Availability
- test_availability_parser.py: unit tests
- generate_input_main.py: add --check-availability to report the
  Expression/Label/Unstructured distribution without changing the generated
  markdown.

On the current docs/parameters.yaml this classifies 217 non-empty values as
82 Expression / 84 Label / 51 Unstructured.
Make the Input_Item availability field a concrete, machine-readable boolean
condition (single source of truth) so the INPUT docs, validation and tooling
can consume the actual condition instead of free text or bare tags.

- Add AvailabilityKind/AvailabilityCondition/AvailabilityExpr and
  parse_availability() in a new module (availability.{h,cpp}, wired into CMake).
- Input_Item now carries availability_kind + availability_expr and a
  set_availability() helper that keeps the canonical string and the structured
  form in sync (single source of truth).
- Rewrite all 217 non-empty availability registrations to canonical boolean
  syntax; the exported YAML classifies them as 216 Expression / 0 Unstructured.
- Export the structured fields from --generate-parameters-yaml (input_help.cpp).
- Consume the structured fields in generate_input_main.py; extend
  availability_parser.py to the canonical grammar and cover it with tests.
- Regenerate docs/parameters.yaml and input-main.md.

Former bare "label"-style tags (e.g. "OFDFT", "Numerical atomic orbital basis")
are now expressed as concrete conditions (esolver_type==ofdft, basis_type==lcao,
...) so they can be evaluated by validation/error tooling. mixing_tau has no hard
gate, so its availability is empty (always available); its meta-GGA relevance is
kept in the description.
@Stardust0831 Stardust0831 added the Refactor Refactor ABACUS codes label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant