Skip to content

feat: validate LAMMPS template revision variables before task execution#366

Open
SchrodingersCattt wants to merge 3 commits into
deepmodeling:masterfrom
SchrodingersCattt:feat/lmp-variable-precheck
Open

feat: validate LAMMPS template revision variables before task execution#366
SchrodingersCattt wants to merge 3 commits into
deepmodeling:masterfrom
SchrodingersCattt:feat/lmp-variable-precheck

Conversation

@SchrodingersCattt

@SchrodingersCattt SchrodingersCattt commented Jul 20, 2026

Copy link
Copy Markdown

Problem

template.lammps may contain revision placeholders like V_PRESS that are not defined in the revisions config dict. Currently this is only discovered when LAMMPS actually runs on the remote cluster and fails — potentially wasting hours of GPU training time plus queue wait.

Solution

Add pre-check logic in LmpTemplateTaskGroup.make_task() that validates revision variable substitution before task submission (fail fast):

  1. Post-substitution residual check: After applying revise_by_keys(), scan output templates for remaining V_[A-Z][A-Z0-9_]* patterns. If found, raise ValueError with a clear message listing undefined variables and available revisions.

  2. Unused key warning: If a revision key is defined but never appears in the template, emit warnings.warn() to catch typos.

  3. Empty revisions with V_ in template*: If no revisions provided but template contains V_* variables, raise ValueError.

Design decisions

  • The V_ prefix is a strong convention from dpgen v1/v2 (100% of tests/examples use it). The check only scans for this pattern.
  • LAMMPS internal ${VARNAME} syntax is correctly ignored.
  • Fully backward compatible: only adds new validation, no change to substitution logic.

Tests

  • 5 new test cases in TestRevisionVariablePrecheck
  • Updated test_lmp_empty to expect ValueError

All 9 tests pass.

Summary by CodeRabbit

  • Bug Fixes
    • Added validation to detect unreplaced revision variables in generated templates.
    • Clear errors are now shown when required revision values are missing.
    • Unused revision entries generate warnings instead of failing.
    • Internal LAMMPS variables are correctly excluded from revision validation.

Add pre-check logic in LmpTemplateTaskGroup.make_task() that scans
substituted templates for unreplaced V_* revision placeholders.

This catches undefined revision variables at submit time (fail fast)
instead of waiting until LAMMPS execution on remote cluster fails,
which can waste hours of GPU training + queue time.

Changes:
- Add find_unreplaced_variables() to detect residual V_* patterns
- Add check_revisions_completeness() with two checks:
  1. Post-substitution residual check (raises ValueError)
  2. Unused revision key detection (emits warning for typos)
- Update test_lmp_empty to expect ValueError (previously would silently
  pass templates with unreplaced variables to LAMMPS)
- Add TestRevisionVariablePrecheck test class with 5 test cases

Closes: template variable typo wastes 75min train + queue time issue
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jul 20, 2026
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@SchrodingersCattt, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 30 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c6b16ef3-e8ae-481d-a4b4-19c0149266ca

📥 Commits

Reviewing files that changed from the base of the PR and between 87c626a and c2145a2.

📒 Files selected for processing (2)
  • dpgen2/exploration/task/lmp_template_task_group.py
  • tests/exploration/test_lmp_templ_task_group.py
📝 Walkthrough

Walkthrough

LAMMPS template task creation now detects unresolved V_* revision placeholders, raises errors for missing substitutions, and warns about unused revision keys. Tests cover missing, complete, unused, and internal LAMMPS variables.

Changes

Revision Placeholder Validation

Layer / File(s) Summary
Placeholder validation and diagnostics
dpgen2/exploration/task/lmp_template_task_group.py
Added V_* placeholder detection, completeness checks after substitution, errors for unresolved variables, and warnings for revision keys absent from the raw template.
Revision validation coverage
tests/exploration/test_lmp_templ_task_group.py
Updated empty-revision behavior tests and added coverage for missing, complete, unused, and internal LAMMPS variables.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: validating LAMMPS template revision variables before task execution.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
dpgen2/exploration/task/lmp_template_task_group.py (1)

314-320: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Consider using word boundaries for unused key detection.

Checking if key not in template_raw uses simple substring matching. If revisions defines V_NSTEPS, but the template only uses a longer variable like V_NSTEPS_1, the substring match will still evaluate to True, inadvertently suppressing the unused key warning for V_NSTEPS.

Since this is just a warning, it's not critical, but leveraging word boundaries ensures accurate matching.

💡 Proposed fix using regular expressions
     # Check 2: Unused revision keys (warning only)
     if template_raw and revision_keys:
         for key in revision_keys:
-            if key not in template_raw:
+            if not re.search(rf"(?<![A-Za-z0-9_]){re.escape(key)}(?![A-Za-z0-9_])", template_raw):
                 warnings.warn(
                     f"Revision key '{key}' is defined but does not appear in the "
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dpgen2/exploration/task/lmp_template_task_group.py` around lines 314 - 320,
Update the unused revision-key check in the loop over revision_keys to match
complete variable names rather than raw substrings in template_raw. Use a
word-boundary-aware regular-expression search so a key such as V_NSTEPS does not
match V_NSTEPS_1, while preserving the existing warning behavior for genuinely
absent keys.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dpgen2/exploration/task/lmp_template_task_group.py`:
- Around line 107-116: Update the check_revisions_completeness call in the
revisions validation block to validate every substituted template in conts, not
only conts[0]. Flatten or otherwise combine conts before passing it to the check
so PLUMED templates in conts[1] are checked whenever self.plm_set is enabled,
while preserving the existing revision keys and template_raw arguments.

---

Nitpick comments:
In `@dpgen2/exploration/task/lmp_template_task_group.py`:
- Around line 314-320: Update the unused revision-key check in the loop over
revision_keys to match complete variable names rather than raw substrings in
template_raw. Use a word-boundary-aware regular-expression search so a key such
as V_NSTEPS does not match V_NSTEPS_1, while preserving the existing warning
behavior for genuinely absent keys.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ea5e019e-b0fd-4dba-9673-28774b4ebd37

📥 Commits

Reviewing files that changed from the base of the PR and between b05af11 and 87c626a.

📒 Files selected for processing (2)
  • dpgen2/exploration/task/lmp_template_task_group.py
  • tests/exploration/test_lmp_templ_task_group.py

Comment thread dpgen2/exploration/task/lmp_template_task_group.py
Address CodeRabbit review: check_revisions_completeness was only called
with conts[0] (LAMMPS templates), missing conts[1] (PLUMED templates).

Now flatten all template variants before validation so V_* placeholders
in PLUMED templates are also caught.

Add test_plumed_template_undefined_variable_raises test case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant