Skip to content

Conversation

@OutisLi
Copy link

@OutisLi OutisLi commented Aug 25, 2025

fix issue #305

Now we can add input_extra_files for lmp-md and lmp-template in json configurations. The docs were updated too.

Summary by CodeRabbit

  • New Features

    • You can now attach extra input files to LAMMPS-based tasks (including NPT), which will be bundled and sent with each task.
    • Configuration helpers now accept an input_extra_files option for NPT, LAMMPS template, and customized LAMMPS template task groups.
  • Documentation

    • Clarified the description for trajectory frequency in NPT task configuration to better reflect its behavior.

@coderabbitai
Copy link

coderabbitai bot commented Aug 25, 2025

📝 Walkthrough

Walkthrough

Adds optional support for attaching extra input files to LMP and NPT task groups. Extends set_lmp and set_md signatures to accept input_extra_files, stores basenames and contents, and appends them to tasks during creation. Updates config argument builders to expose input_extra_files and fixes a trj_freq doc string.

Changes

Cohort / File(s) Summary of Changes
LMP task group: extra input files
dpgen2/exploration/task/lmp_template_task_group.py
Extends LmpTemplateTaskGroup.set_lmp with input_extra_files: Optional[List[str]]. Stores basenames and file contents; during _make_lmp_task, appends each extra file via task.add_file(name, content).
NPT task group: extra input files
dpgen2/exploration/task/npt_task_group.py
Extends NPTTaskGroup.set_md with input_extra_files: Optional[List[str]]. Saves basenames and contents; in _make_lmp_task, adds them to the task via task.add_file. Imports Path and introduces internal attributes to hold names/contents.
Config argument builders
dpgen2/exploration/task/make_task_group_from_config.py
Adds input_extra_files argument (list, default []) to npt_task_group_args, lmp_template_task_group_args, customized_lmp_template_task_group_args, with local doc_input_extra_files. Updates trj_freq doc from doc_nsteps to doc_traj_freq.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User/Config
  participant CFG as TaskGroup Args Builder
  participant TG as TaskGroup (LMP/NPT)
  participant TK as ExplorationTask

  U->>CFG: Provide input_extra_files (optional)
  CFG->>TG: set_* (… , input_extra_files)
  alt extras provided
    TG->>TG: Read files (basename + contents)
  else no extras
    TG->>TG: Initialize empty lists
  end
  TG->>TK: Create task with standard inputs
  loop for each extra file
    TG->>TK: add_file(name, content)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • wanghan-iapcm
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

51-52: Add concise doc and type expectation for input_extra_files

Briefly document acceptable values (paths to readable text files) and note that only basenames are kept. This helps config users avoid unexpected overrides.


42-56: Avoid mutable default for revisions

Using a mutable default dict is a latent footgun. Prefer None and coalesce.

Apply this diff:

 def set_lmp(
     self,
     numb_models: int,
     lmp_template_fname: str,
     plm_template_fname: Optional[str] = None,
-    revisions: dict = {},
+    revisions: Optional[dict] = None,
     traj_freq: int = 10,
     extra_pair_style_args: str = "",
     pimd_bead: Optional[str] = None,
     input_extra_files: Optional[List[str]] = None,
 ) -> None:
-    self.lmp_template = Path(lmp_template_fname).read_text().split("\n")
-    self.revisions = revisions
+    self.lmp_template = Path(lmp_template_fname).read_text().split("\n")
+    self.revisions = revisions or {}

147-152: Add a defensive assertion before zipping filenames and contents

Guards against future changes that might desynchronize the two lists.

Apply this diff:

-        # Add extra files to the task
-        for file_name, file_content in zip(
+        # Add extra files to the task
+        assert len(self.input_extra_files) == len(self.input_extra_file_contents), \
+            "Mismatched extra file names and contents"
+        for file_name, file_content in zip(
             self.input_extra_files, self.input_extra_file_contents
         ):
             task.add_file(file_name, file_content)

58-66: DRY: Factor out “load-and-validate extra files” into a utility

The same logic appears here and in NPTTaskGroup. Consider a shared helper (e.g., dpgen2/exploration/task/utils.py: load_extra_files(paths, reserved)) to centralize validation and encoding behavior.

If you want, I can draft a small utils module and the two call sites.

Also applies to: 147-152

dpgen2/exploration/task/npt_task_group.py (3)

56-57: Document the new parameter and align semantics with config defaults

Add a short note in the set_md docstring about input_extra_files (list of file paths; basenames kept). Given make_task_group_from_config supplies default [] (not None), ensure current logic handles both None and [] consistently. It does, but documenting avoids confusion.

Would you like me to add a one-liner docstring update here?


152-157: Add a defensive assertion before zipping filenames and contents

Small safety net against future changes that could desync the lists.

Apply this diff:

-        # Add extra files to the task
-        for file_name, file_content in zip(
+        # Add extra files to the task
+        assert len(self.input_extra_files) == len(self.input_extra_file_contents), \
+            "Mismatched extra file names and contents"
+        for file_name, file_content in zip(
             self.input_extra_files, self.input_extra_file_contents
         ):
             task.add_file(file_name, file_content)

79-87: DRY with LmpTemplateTaskGroup

This logic duplicates the LMP-template path. A shared helper would improve consistency and testability.

I can factor a reusable helper and update both call sites in a follow-up commit.

Also applies to: 152-157

dpgen2/exploration/task/make_task_group_from_config.py (2)

51-53: Docs + config plumbing for input_extra_files look good; consider early validation

Plumbing and docs are clear. Optionally, validate that each entry is a string path and exists to fail fast at config time.

Example (outside these ranges, in make_lmp_task_group_from_config before set_md/set_lmp):

# add near the start of make_lmp_task_group_from_config
from pathlib import Path  # at file top

# ...
files = config.get("input_extra_files") or []
if not all(isinstance(p, str) for p in files):
    raise TypeError("input_extra_files must be a list of str paths")
missing = [p for p in files if not Path(p).is_file()]
if missing:
    raise FileNotFoundError(f"input_extra_files not found: {missing}")

Also applies to: 122-128


139-141: LMP-template docs and args: mirror the NPT behavior

Looks consistent with the NPT variant. Consider explicitly mentioning that only basenames are used and collisions with core inputs are disallowed (once checks are added at the call site).

If you add the collision checks suggested in the task groups, I can update these doc strings in the same PR for full alignment.

Also applies to: 190-196

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between edbaa44 and e7ce996.

📒 Files selected for processing (3)
  • dpgen2/exploration/task/lmp_template_task_group.py (2 hunks)
  • dpgen2/exploration/task/make_task_group_from_config.py (5 hunks)
  • dpgen2/exploration/task/npt_task_group.py (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
dpgen2/exploration/task/npt_task_group.py (1)
dpgen2/exploration/task/task.py (1)
  • add_file (30-46)
dpgen2/exploration/task/lmp_template_task_group.py (1)
dpgen2/exploration/task/task.py (1)
  • add_file (30-46)
🔇 Additional comments (2)
dpgen2/exploration/task/npt_task_group.py (1)

3-5: LGTM: Path import

Necessary for reading extra files; no concerns.

dpgen2/exploration/task/make_task_group_from_config.py (1)

76-77: Good fix: trj_freq now references the right doc string

This resolves the previous doc_nsteps mismatch.

@wanghan-iapcm wanghan-iapcm requested a review from zjgemi August 25, 2025 13:29
@codecov
Copy link

codecov bot commented Aug 25, 2025

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.23%. Comparing base (edbaa44) to head (e7ce996).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
dpgen2/exploration/task/lmp_template_task_group.py 85.71% 1 Missing ⚠️
dpgen2/exploration/task/npt_task_group.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
+ Coverage   84.22%   84.23%   +0.01%     
==========================================
  Files         104      104              
  Lines        6112     6129      +17     
==========================================
+ Hits         5148     5163      +15     
- Misses        964      966       +2     

☔ View full report in Codecov by Sentry.
📢 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.

@wanghan-iapcm wanghan-iapcm merged commit eb779cb into deepmodeling:master Aug 29, 2025
9 checks passed
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.

3 participants