Skip to content

fix(dpmodel): preserve nopbc batch semantics - #6003

Open
hcustc wants to merge 3 commits into
deepmodeling:masterfrom
hcustc:fix/pt-expt-nopbc-box
Open

fix(dpmodel): preserve nopbc batch semantics#6003
hcustc wants to merge 3 commits into
deepmodeling:masterfrom
hcustc:fix/pt-expt-nopbc-box

Conversation

@hcustc

@hcustc hcustc commented Aug 26, 2026

Copy link
Copy Markdown

Summary

  • translate the legacy non-periodic default_mesh encodings (sizes 0 and 1) to the canonical model input box=None
  • preserve periodic boxes for both standard-type and mixed-type batches
  • add regression coverage for the batch boundary and a real temporary nopbc NPY system

Root cause

DeepmdDataSystem represents a valid non-periodic system with an empty or single-element default_mesh and an all-zero box placeholder. normalize_batch() dropped the mesh metadata but retained the placeholder, so downstream code treated the non-None box as periodic and attempted to invert a singular cell.

The fix performs the semantic conversion before the metadata is discarded, without mutating the input batch.

Fixes #6002.

Testing

  • .venv/bin/python -m pytest source/tests/common/test_batch_nopbc.py source/tests/common/test_batch_charge_state.py -q (10 passed, 10 subtests passed)
  • .venv/bin/ruff check .
  • .venv/bin/ruff format --check .
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of non-periodic systems during batch normalization.
    • Non-periodic data now correctly omits placeholder box information.
    • Periodic systems continue to retain their box data.
    • Model inputs now correctly receive no box for valid non-periodic systems.
  • Tests

    • Added coverage for legacy mesh metadata and non-periodic data system behavior.

Convert non-periodic default_mesh encodings to box=None before normalize_batch drops the legacy metadata. This prevents pt_expt neighbor construction from treating zero box placeholders as periodic cells.\n\nAdd regression coverage for standard and mixed-type mesh encodings, periodic box preservation, and a real nopbc NPY data system.
Copilot AI lite review requested due to automatic review settings August 26, 2026 11:18
@dosubot dosubot Bot added the bug label Aug 26, 2026
@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 9855518d-6803-47db-88dd-c900b31aa152

📥 Commits

Reviewing files that changed from the base of the PR and between 1dcebad and 4399883.

📒 Files selected for processing (2)
  • deepmd/dpmodel/utils/batch.py
  • source/tests/common/test_batch_nopbc.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepmd/dpmodel/utils/batch.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

normalize_batch now converts non-periodic default_mesh encodings to a None model input box. Tests cover periodic preservation, missing metadata, absent boxes, and nopbc NPY integration.

Changes

Non-periodic batch normalization

Layer / File(s) Summary
Normalize non-periodic batch boxes
deepmd/dpmodel/utils/batch.py
normalize_batch detects non-periodic default_mesh values and sets an existing box to None before removing the metadata.
Validate normalization and data-system integration
source/tests/common/test_batch_nopbc.py
Tests cover non-periodic and periodic boxes, missing default_mesh, batches without box, and nopbc NPY data-system inputs.

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

Merge Risk: ⚪ Minimal · up to 43998

This change converts legacy non-periodic batch placeholders to the canonical non-periodic representation while preserving periodic batches. No actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. 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 summarizes the primary change: preserving non-periodic batch semantics in dpmodel.
Linked Issues check ✅ Passed The implementation translates non-periodic default_mesh encodings to box=None before metadata removal. The tests cover non-periodic and periodic batches, missing metadata, and a temporary nopbc system…
Out of Scope Changes check ✅ Passed The code and test changes directly support the linked issue. No unrelated changes are identified.
Full details: Linked Issues check

Explanation

The implementation translates non-periodic default_mesh encodings to box=None before metadata removal. The tests cover non-periodic and periodic batches, missing metadata, and a temporary nopbc system, satisfying issue #6002.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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

Pull request overview

This PR fixes loss of non-periodic (nopbc) semantics during DeepmdDataSystem batch normalization in deepmd.dpmodel.utils.batch.normalize_batch(). It translates the legacy default_mesh encoding for non-periodic systems (mesh sizes 0/1) into the canonical model input form (box=None), preventing downstream periodic-only code paths from attempting to invert the all-zero placeholder cell.

Changes:

  • Convert non-periodic default_mesh encodings (size 0 or 1) to box=None during normalize_batch() (before default_mesh is dropped).
  • Preserve periodic boxes unchanged for both standard-type and mixed-type batches.
  • Add regression tests covering (a) the mesh-size boundary behavior and (b) a real temporary nopbc NPY system with a zero-box placeholder.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
deepmd/dpmodel/utils/batch.py Implements non-periodic semantic conversion (default_mesh size 0/1 ⇒ box=None) while keeping periodic boxes intact.
source/tests/common/test_batch_nopbc.py Adds regression coverage for legacy mesh encodings and an end-to-end nopbc system batch ensuring inputs["box"] is None.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread deepmd/dpmodel/utils/batch.py Outdated
Describe the default_mesh conversion in terms of the canonical model input rather than implying that normalize_batch inspects box values.

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

Reviewed the non-periodic batch-normalization path and its coverage. The legacy mesh-size 0/1 encodings are translated before metadata is dropped, periodic encodings remain intact, and the input batch is not mutated. I found no blocking issues.

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

@njzjz
njzjz requested a review from wanghan-iapcm August 29, 2026 17:21
@codecov

codecov Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.84%. Comparing base (8cfd46e) to head (1dcebad).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6003      +/-   ##
==========================================
- Coverage   79.10%   78.84%   -0.26%     
==========================================
  Files        1105     1105              
  Lines      130981   130985       +4     
  Branches     4771     4771              
==========================================
- Hits       103609   103272     -337     
- Misses      25686    26029     +343     
+ Partials     1686     1684       -2     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The diagnosis is right and the fix is correct. The layer is right too, which is worth recording: doing this at the producer instead — if not self.pbc: b_data["box"] = None in DeepmdDataSystem.get_batch_standard/get_batch_mixed — would break TensorFlow and JAX training on nopbc systems, since get_batch() is shared with backends that require box to be an array. normalize_batch is the first point downstream of that contract.

Two notes, neither blocking.

Comment thread deepmd/dpmodel/utils/batch.py Outdated
Comment thread source/tests/common/test_batch_nopbc.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] pt_expt drops nopbc metadata but retains the zero box placeholder in normalize_batch

5 participants