Skip to content

fix(system): copy first append and support absolute paths#1015

Open
njzjz-bot wants to merge 2 commits into
deepmodeling:masterfrom
njzjz-bot:fix/issue-986
Open

fix(system): copy first append and support absolute paths#1015
njzjz-bot wants to merge 2 commits into
deepmodeling:masterfrom
njzjz-bot:fix/issue-986

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #986.

Deep-copy the first appended system and build absolute-safe recursive glob patterns in MultiSystems.from_dir.

Tests: cd tests && python -m unittest test_multisystems.TestMultiSystemsFromDir test_system_append

Why existing tests missed it: There was no first-append ownership test and no absolute-directory from_dir case.

Coding agent: Codex
Codex version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning effort: xhigh

Summary by CodeRabbit

  • Bug Fixes

    • Fixed directory-based system discovery for absolute paths.
    • Prevented unintended data sharing when appending systems, improving data isolation.
  • Tests

    • Added coverage confirming absolute and relative directory paths return equivalent systems and frame counts.

Deep-copy data when appending into an empty system and build MultiSystems.from_dir glob patterns without a forced relative prefix. Regression tests cover source ownership and equivalent relative/absolute directory searches.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. dpdata labels Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

System.append now avoids shared data during initial copying. MultiSystems.from_dir correctly searches absolute directories, with tests comparing absolute and relative directory inputs.

Changes

System data isolation

Layer / File(s) Summary
Deep-copy append initialization
dpdata/system.py
System.append deep-copies system.data when initializing a destination without existing atom counts.

Absolute directory search

Layer / File(s) Summary
Directory search path and validation
dpdata/system.py, tests/test_multisystems.py
MultiSystems.from_dir removes the ./ prefix from recursive glob construction, and tests equivalent results for relative and absolute directories.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: njzjz

🚥 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 summarizes the two main changes: first-append copying and absolute-path support.
Linked Issues check ✅ Passed The PR fixes #986 by removing the './' prefix for recursive globbing and adds coverage for absolute vs. relative directories.
Out of Scope Changes check ✅ Passed The added deep-copy behavior and tests align with the PR objectives and do not appear unrelated to the requested fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

🤖 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 `@tests/test_multisystems.py`:
- Around line 54-64: Strengthen
test_absolute_directory_matches_relative_directory in TestMultiSystemsFromDir to
compare the matched systems themselves, not just collection and aggregate frame
counts. Assert equivalent system names and per-system frame counts, or reuse the
repository’s existing system-comparison helper, while preserving the
relative-versus-absolute directory setup.
🪄 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: 24696385-2be8-420e-aabb-8f15318c1c0d

📥 Commits

Reviewing files that changed from the base of the PR and between 0416b54 and ebab942.

📒 Files selected for processing (2)
  • dpdata/system.py
  • tests/test_multisystems.py

Comment on lines +54 to +64
class TestMultiSystemsFromDir(unittest.TestCase):
def test_absolute_directory_matches_relative_directory(self):
relative = dpdata.MultiSystems.from_dir(
"poscars", "OUTCAR.h2o.md", fmt="vasp/outcar"
)
absolute = dpdata.MultiSystems.from_dir(
os.path.abspath("poscars"), "OUTCAR.h2o.md", fmt="vasp/outcar"
)
self.assertEqual(len(relative), 1)
self.assertEqual(len(absolute), len(relative))
self.assertEqual(absolute.get_nframes(), relative.get_nframes())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert equivalence of the matched systems, not only aggregate counts.

These assertions would pass if the absolute-path search returned a different set of systems with the same length and total frame count. Compare system names and each system’s frame count (or use the repository’s existing system-comparison helper) to fully cover the stated relative/absolute equivalence requirement.

🤖 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 `@tests/test_multisystems.py` around lines 54 - 64, Strengthen
test_absolute_directory_matches_relative_directory in TestMultiSystemsFromDir to
compare the matched systems themselves, not just collection and aggregate frame
counts. Assert equivalent system names and per-system frame counts, or reuse the
repository’s existing system-comparison helper, while preserving the
relative-versus-absolute directory setup.

@codspeed-hq

codspeed-hq Bot commented Jul 16, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 13.33%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 1 untouched benchmark

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_import 12.6 ms 11.1 ms +13.33%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing njzjz-bot:fix/issue-986 (e9bd912) with master (713ef68)

Open in CodSpeed

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.01%. Comparing base (713ef68) to head (e9bd912).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1015      +/-   ##
==========================================
+ Coverage   86.95%   87.01%   +0.06%     
==========================================
  Files          90       90              
  Lines        8330     8330              
==========================================
+ Hits         7243     7248       +5     
+ Misses       1087     1082       -5     

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

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving: both fixes are correct and CI is green.

  • The first-append deepcopy(system.data) completes the "do not modify the appended system" invariant from #483, which deep-copied in every branch except this one (the shallow dict.copy() left arrays/lists aliased).
  • The from_dir change to os.path.join(dir_name, "**", file_name) matches the form originally suggested in #63 and fixes absolute directory paths (the ./ prefix turned them into no-match relative patterns) without regressing relative paths.

Note: the append deepcopy here is exactly the fix that #1014's currently-failing test_first_append_does_not_alias_source needs. These two PRs are complementary — this one has the fix, #1014 has the test — so they should be sequenced/merged together.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dpdata lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code scan] MultiSystems.from_dir silently returns empty results for absolute directories

2 participants