Skip to content

Add workflow module ordering validation - #1651

Open
amjjbonvin wants to merge 7 commits into
mainfrom
workflow-rules
Open

Add workflow module ordering validation#1651
amjjbonvin wants to merge 7 commits into
mainfrom
workflow-rules

Conversation

@amjjbonvin

@amjjbonvin amjjbonvin commented Aug 4, 2026

Copy link
Copy Markdown
Member

Before submitting, read the contributing guidelines and the AI policy.

What does this PR do and why?

HADDOCK3 validates that each workflow module and its parameters are valid, but it does not check whether the sequence of modules makes sense. Some modules only work when another ran before them, some must not be chained to themselves, and a workflow must start by building topologies. Until now, such mistakes only surfaced at run time (or produced meaningless results).

This PR adds a data-driven workflow ordering check. Constraints are declared in src/haddock/gear/workflow_rules.yaml and enforced by src/haddock/gear/workflow_ordering.py, so new rules can be added without touching the validation logic. Four rule types are supported:

  • disallowed_sequences — a module may not directly follow another (e.g. clustrmsd → clustrmsd, clustfcc → clustfcc, seletop → seletop, seletopclusts → seletopclusts).
  • required_preceding — a module must be immediately preceded by one of a set (topocg after topoaa; clustrmsd after rmsdmatrix/ilrmsdmatrix).
  • required_prior — a module must appear somewhere earlier (cgtoaa requires topoaa).
  • required_first — the first module must be one of a set (topoaa).

The check is wired into setup_run() and raises a single ConfigurationError listing all violations (with step numbers and allowed alternatives). It is skipped for --extend-run, whose config only describes the appended modules, so the full order is not known there.

The plot-finetune-clustfcc.cfg example was adjusted so its clustfcc steps are no longer directly consecutive, matching the clustfcc → clustfcc rule.

How was this tested?

  • New unit tests in tests/test_gear_workflow_ordering.py (100% coverage of workflow_ordering.py) covering each rule type, multi-violation reporting, empty workflows, and custom rules files.
  • Ran the check against all 110 real example workflows: only the two docking-extend-run-*.cfg configs "fail" standalone, and those are exclusively run with --extend-run (where the check is skipped by design).
  • ruff format --check and ruff check pass on changed files; pytest tests/test_gear_workflow_ordering.py tests/test_gear_prepare_run.py → 93 passed.

AI assistance

Drafted with Claude Code and reviewed manually. Claude wrote the validation logic, YAML rules, tests, and docs; verified the behaviour by running the full test suite and cross-checking the rules against every example workflow in the repo. This is config/ordering validation only — no scoring, energy, restraint, or CNS/topology logic is involved.

Checklist

  • Tests cover the new and/or changed code
  • Documentation updated if needed (also in the haddock3 user-manual) — code docs updated (architecture.md, docstrings); user-manual update still to do
  • CHANGELOG.md updated for user-facing changes

Related issues

Related to #1530.

Notes for reviewers

  • Rules live in gear/workflow_rules.yaml — reviewers should sanity-check the rule set for scientific correctness (e.g. whether any other module pairs should be disallowed/required).
  • The user-manual (separate repo) is not yet updated.

amjjbonvin and others added 4 commits August 4, 2026 20:04
Validate the sequence of modules in a workflow config against ordering
rules declared as data in gear/workflow_rules.yaml:

- disallowed_sequences: a module may not directly follow another
- required_preceding: a module must be immediately preceded by one of a set
- required_prior: a module must be preceded anywhere earlier by one of a set
- required_first: the first module must be one of a set

gear/workflow_ordering.py reads the rules and checks the ordered module
list, collecting all violations into a single ConfigurationError. The check
is wired into setup_run() and skipped for --extend-run configs (which only
describe the appended modules). Adjusted the finetune-clustfcc example so
its clustfcc steps are no longer directly consecutive.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Format workflow_ordering.py and the setup_run() hook with ruff format
- List gear/workflow_ordering.py in the architecture gear table
- Note the ordering validation step in the setup_run() docstring

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@amjjbonvin amjjbonvin self-assigned this Aug 4, 2026
@amjjbonvin amjjbonvin added feature Adding something new to the codebase workflow All the general parts of HADDOCK3 not related to any module in particular python Pull requests that update python code AI Changes authored or assisted by AI labels Aug 4, 2026
@AnnaKravchenko

Copy link
Copy Markdown
Contributor

At a glance this goes agains the fine tuning of the clustfcc parameters from the user manual here, bottom of the page

@amjjbonvin

Copy link
Copy Markdown
Member Author

At a glance this goes agains the fine tuning of the clustfcc parameters from the user manual here, bottom of the page

Indeed - this example was updated (but not the manual). This is intended to avoid similar problems as with clustrmsd.

But as said in the PR, the list of rules need to be checked.

Comment thread src/haddock/gear/workflow_rules.yaml Outdated
Comment thread src/haddock/gear/workflow_rules.yaml
amjjbonvin and others added 2 commits August 6, 2026 09:51
Co-authored-by: Victor Reys <132575181+VGPReys@users.noreply.github.com>
@amjjbonvin
amjjbonvin requested a review from VGPReys August 6, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Changes authored or assisted by AI feature Adding something new to the codebase python Pull requests that update python code workflow All the general parts of HADDOCK3 not related to any module in particular

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants