Skip to content

Preserve model backend suffix in generated tasks - #120

Open
njzjz wants to merge 9 commits into
develfrom
preserve-model-backend-suffix
Open

Preserve model backend suffix in generated tasks#120
njzjz wants to merge 9 commits into
develfrom
preserve-model-backend-suffix

Conversation

@njzjz

@njzjz njzjz commented Jun 19, 2026

Copy link
Copy Markdown
Member

Summary

  • preserve the input model suffix when copying or linking DeepMD models into generated tasks, e.g. model.pth -> graph.pth
  • update HTI/GDI/TI/equi/MTI/water workflow submission paths to forward/link the actual generated model filename
  • add tests for suffix preservation and model filename lookup

Tests

  • PYTHONPATH=.. pytest -q test_lib_utils.py test_hti_make_task.py test_gdi_make_task.py test_equi_make_task.py test_ti_make_task.py test_hti_liq_make_task.py test_hti_liq_gen_lammps_input.py test_hti_water_gen_lammps_input.py test_ti_water_gen_lammps_input.py test_hti_gen_lammps_input.py
  • python -m ruff check --select I,F --ignore F841 dpti/lib/utils.py dpti/equi.py dpti/gdi.py dpti/hti.py dpti/hti_water.py dpti/hti_liq.py dpti/hti_ice.py dpti/ti.py dpti/mti.py dpti/relax.py dpti/old_equi.py tests/test_lib_utils.py tests/test_hti_make_task.py tests/test_gdi_make_task.py tests/test_ti_make_task.py tests/test_equi_make_task.py workflow/DpFreeEnergy.py workflow/DpFreeEnergyWater.py
  • python -m compileall -q dpti workflow tests/test_lib_utils.py tests/test_hti_make_task.py tests/test_gdi_make_task.py tests/test_ti_make_task.py tests/test_equi_make_task.py

Full pytest -q currently reports 116 passed, 1 error; the remaining error is an existing pytest collection issue in tests/test_hti_ff_spring.py:54, where a module-level test function has a self parameter.

Summary by CodeRabbit

Release Notes

  • New Features

    • Model/graph artifact filenames are now resolved dynamically from task/work settings, preserving the original backend extension, and are consistently used across setup, linking, LAMMPS generation, and job submission.
    • Phase-specific graph/model naming is supported for phase-based workflows.
  • Bug Fixes

    • Correctly stages and forwards the intended model artifact instead of always using graph.pb.
    • Improves robustness of model symlinking and command quoting.
  • Tests

    • Added/updated unit tests covering settings-based model resolution, phase-specific filenames, and improved symlink/link command behavior.

@njzjz
njzjz requested a review from Yi-FanLi June 19, 2026 16:53
@njzjz njzjz linked an issue Jun 19, 2026 that may be closed by this pull request
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 106 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (78091bd) to head (3fe3754).

Files with missing lines Patch % Lines
dpti/hti.py 0.00% 25 Missing ⚠️
dpti/mti.py 0.00% 14 Missing ⚠️
dpti/ti.py 0.00% 12 Missing ⚠️
dpti/equi.py 0.00% 11 Missing ⚠️
dpti/hti_liq.py 0.00% 10 Missing ⚠️
dpti/gdi.py 0.00% 9 Missing ⚠️
dpti/hti_water.py 0.00% 9 Missing ⚠️
dpti/lib/utils.py 0.00% 5 Missing ⚠️
dpti/hti_ice.py 0.00% 4 Missing ⚠️
dpti/relax.py 0.00% 4 Missing ⚠️
... and 1 more
Additional details and impacted files
@@          Coverage Diff          @@
##           devel    #120   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         25      25           
  Lines       6665    6729   +64     
=====================================
- Misses      6665    6729   +64     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9cf5da87-bc00-4eab-a405-dcd7613fbc39

📥 Commits

Reviewing files that changed from the base of the PR and between 48fc963 and 3fe3754.

📒 Files selected for processing (2)
  • dpti/mti.py
  • dpti/ti.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • dpti/mti.py

📝 Walkthrough

Walkthrough

Adds dynamic model filename resolution based on model suffixes and task settings. Resolved names propagate through task generation, refinement, runtime symlinking, LAMMPS input generation, and workflow file forwarding across simulation modules.

Changes

Dynamic model filename resolution

Layer / File(s) Summary
Model filename utility and validation
dpti/lib/utils.py, tests/test_lib_utils.py
Adds suffix-preserving model filename generation with default and prefix behavior, plus tests.
Resolved model staging during task generation
dpti/hti.py, dpti/hti_liq.py, dpti/hti_water.py, dpti/hti_ice.py, dpti/gdi.py, dpti/old_equi.py, dpti/relax.py, tests/test_gdi_make_task.py, tests/test_hti_make_task.py
Stages models under derived names, updates metadata and generated LAMMPS inputs, and supports phase-specific graph suffixes.
Runtime model selection and staging
dpti/equi.py, dpti/hti.py, dpti/mti.py, dpti/ti.py, tests/test_equi_make_task.py, tests/test_ti_make_task.py
Reads task settings to select model basenames, conditionally creates symlinks, safely quotes link commands, and forwards resolved model files.
Workflow model forwarding
workflow/DpFreeEnergy.py, workflow/DpFreeEnergyWater.py
Derives model filenames from settings JSON and applies them to NPT, NVT, HTI, and TI forwarding lists.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested reviewers: yi-fanli

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preserving model backend suffixes in generated tasks.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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: 3

🤖 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 `@dpti/hti.py`:
- Around line 1510-1515: The _graph_link_command function constructs a shell
command by directly interpolating graph_relpath and model_file into an ln -s
command without proper quoting, which creates a security and stability issue if
these paths contain spaces or shell metacharacters. Fix this by using shell
quoting (such as shlex.quote) to properly escape both the graph_relpath source
argument and the model_file destination argument in the return statement, and
add the -f flag to the ln -s command to make it idempotent. Apply the same fix
to the similar code mentioned in the comment at lines 1547-1550.

In `@dpti/mti.py`:
- Around line 339-343: The model_file variable is being interpolated directly
into shell ln -s commands without proper quoting, creating a security and
robustness issue. In the shell command fragments where link_model is assigned
(around lines 339 and 341, and also in the similar block at lines 374-380), wrap
both instances of the model_file variable with double quotes in the ln -s
commands to properly escape shell-sensitive characters. Additionally, add the -f
flag to the ln -s command to make the linking idempotent, so it will overwrite
existing links without error. Apply these same quoting and -f flag changes to
all occurrences of link_model assignments that use model_file.

In `@dpti/ti.py`:
- Around line 1081-1085: The model_file variable is directly interpolated into
the shell command string without proper quoting, creating a vulnerability to
command injection or path parsing issues if the filename contains special
characters or spaces. In the command string that includes the ln -s symlink
creation, wrap both occurrences of model_file with appropriate shell quotes
(single or double quotes) to properly escape the path. This applies to the
conditional command assignment where model_file is used twice in the symlink
command.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6ad7ce01-416a-4024-9b69-d9f051ce24f1

📥 Commits

Reviewing files that changed from the base of the PR and between 4a6fed5 and 94eaf11.

📒 Files selected for processing (18)
  • dpti/equi.py
  • dpti/gdi.py
  • dpti/hti.py
  • dpti/hti_ice.py
  • dpti/hti_liq.py
  • dpti/hti_water.py
  • dpti/lib/utils.py
  • dpti/mti.py
  • dpti/old_equi.py
  • dpti/relax.py
  • dpti/ti.py
  • tests/test_equi_make_task.py
  • tests/test_gdi_make_task.py
  • tests/test_hti_make_task.py
  • tests/test_lib_utils.py
  • tests/test_ti_make_task.py
  • workflow/DpFreeEnergy.py
  • workflow/DpFreeEnergyWater.py

Comment thread dpti/hti.py Outdated
Comment thread dpti/mti.py Outdated
Comment thread dpti/ti.py Outdated
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 3 file(s) based on 3 unresolved review comments.

Files modified:

  • dpti/hti.py
  • dpti/mti.py
  • dpti/ti.py

Commit: 25e9b37db69ee8fa0d99f224f2d5cf4c97b0cd71

The changes have been pushed to the preserve-model-backend-suffix branch.

Time taken: 5m 34s

Fixed 3 file(s) based on 3 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>

@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.

♻️ Duplicate comments (1)
dpti/ti.py (1)

1081-1084: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Shell quoting is still bypassable for crafted filenames.

At Line 1082, wrapping model_file in double quotes is not enough if the basename contains quotes; this can still break command parsing/injection safety. Please shell-escape both path operands before interpolation.

Suggested patch
 def run_task(task_name, machine_file):
+    import shlex
@@
-            command=(
-                f'ln -sf "../{model_file}" "{model_file}"; {mdata["command"]} -in in.lammps'
-                if model_file
-                else f"{mdata['command']} -in in.lammps"
-            ),
+            command=(
+                f"ln -sf {shlex.quote(f'../{model_file}')} {shlex.quote(model_file)}; {mdata['command']} -in in.lammps"
+                if model_file
+                else f"{mdata['command']} -in in.lammps"
+            ),
🤖 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 `@dpti/ti.py` around lines 1081 - 1084, The command construction at the `ln
-sf` statement does not properly shell-escape the model_file variable before
interpolation, which allows shell injection if the filename contains special
characters like quotes. Use a shell escaping function (such as shlex.quote() in
Python) to properly escape both the symlink source path (the quoted
"../{model_file}" part) and the symlink destination path (the quoted
"{model_file}" part) before interpolating them into the f-string command. This
ensures that any special characters in the filename cannot break out of the
quoted context or inject arbitrary commands.
🤖 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.

Duplicate comments:
In `@dpti/ti.py`:
- Around line 1081-1084: The command construction at the `ln -sf` statement does
not properly shell-escape the model_file variable before interpolation, which
allows shell injection if the filename contains special characters like quotes.
Use a shell escaping function (such as shlex.quote() in Python) to properly
escape both the symlink source path (the quoted "../{model_file}" part) and the
symlink destination path (the quoted "{model_file}" part) before interpolating
them into the f-string command. This ensures that any special characters in the
filename cannot break out of the quoted context or inject arbitrary commands.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 305627ba-f5f6-43e1-820f-717d3362e822

📥 Commits

Reviewing files that changed from the base of the PR and between 94eaf11 and 25e9b37.

📒 Files selected for processing (3)
  • dpti/hti.py
  • dpti/mti.py
  • dpti/ti.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • dpti/mti.py
  • dpti/hti.py

@njzjz

njzjz commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

pre-commit-ci Bot and others added 3 commits June 19, 2026 17:47
Resolve conflicts with template force-field support while preserving dynamic DeepMD model suffixes.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
Copilot AI review requested due to automatic review settings July 29, 2026 16:52

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
dpti/hti.py (1)

1069-1078: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve MEAM inputs during refinement.

Line 1072 assumes every model-less task has template_ff. Refining a MEAM HTI task instead raises KeyError. Branch explicitly on the resolved if_meam value, stage its library/potential into the refined task, and retain meam_model before calling _make_tasks.

🤖 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 `@dpti/hti.py` around lines 1069 - 1078, Update the model-less task handling
around the resolved if_meam value instead of assuming template_ff exists. For
MEAM tasks, stage the library and potential paths into to_jdata and preserve
meam_model before invoking _make_tasks; retain the existing
template_ff/template_ff_files handling for non-MEAM tasks.
🤖 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 `@dpti/mti.py`:
- Around line 354-360: Use shlex.quote() for both the relative source path and
destination argument when constructing dynamic model-link shell commands in
dpti/mti.py lines 354-360, covering the link_model branches near job_type
"mass_ti"; apply the same shell-safe quoting to ../{model_file} and {model_file}
in dpti/ti.py line 1127. Ensure both command arguments are quoted after
constructing their paths, rather than relying on double quotes.

---

Outside diff comments:
In `@dpti/hti.py`:
- Around line 1069-1078: Update the model-less task handling around the resolved
if_meam value instead of assuming template_ff exists. For MEAM tasks, stage the
library and potential paths into to_jdata and preserve meam_model before
invoking _make_tasks; retain the existing template_ff/template_ff_files handling
for non-MEAM tasks.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 45ffb952-4316-4b1a-bc03-5bd72d16d959

📥 Commits

Reviewing files that changed from the base of the PR and between 25e9b37 and 48fc963.

📒 Files selected for processing (11)
  • dpti/equi.py
  • dpti/gdi.py
  • dpti/hti.py
  • dpti/hti_ice.py
  • dpti/hti_water.py
  • dpti/lib/utils.py
  • dpti/mti.py
  • dpti/ti.py
  • tests/test_gdi_make_task.py
  • tests/test_hti_make_task.py
  • tests/test_lib_utils.py
🚧 Files skipped from review as they are similar to previous changes (5)
  • dpti/hti_ice.py
  • dpti/gdi.py
  • tests/test_lib_utils.py
  • dpti/hti_water.py
  • tests/test_hti_make_task.py

Comment thread dpti/mti.py Outdated
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 2 file(s) based on 1 unresolved review comment.

Files modified:

  • dpti/mti.py
  • dpti/ti.py

Commit: b7bbdc194160396375682c74bcf7bd8718d675cc

The changes have been pushed to the preserve-model-backend-suffix branch.

Time taken: 2m 33s

coderabbitai Bot and others added 2 commits July 30, 2026 03:23
Fixed 2 file(s) based on 1 unresolved review comment.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Support different backends in downstream workflows Support different backends for DeePMD-kit

4 participants