Skip to content

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

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

fix(dpmodel): preserve nopbc batch semantics#6003
hcustc wants to merge 4 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.
    • Placeholder box data is now omitted from model inputs for non-periodic systems.
    • Periodic systems continue to retain their box data.
    • Non-periodic data without box information no longer receives an unintended box.
  • Tests

    • Added coverage for periodic and non-periodic batch normalization, including systems with missing or placeholder mesh and box metadata.

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 StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 329f1ea6-4ac3-4dd8-ac86-909ab3008a33

📥 Commits

Reviewing files that changed from the base of the PR and between 28b7d06 and 2d347c0.

📒 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 (2)
  • deepmd/dpmodel/utils/batch.py
  • source/tests/common/test_batch_nopbc.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.

Priority: ➖ Normal

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

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2d347

This change converts legacy non-periodic zero-box placeholders to a non-periodic model input while preserving periodic boxes. The stated regression coverage includes boundary cases and NPY data-system integration, with no current merge-blocking risk identified.

🚥 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 and concisely describes the main change: preserving non-periodic batch semantics in dpmodel.
Linked Issues check ✅ Passed The PR satisfies issue #6002. It converts non-periodic default_mesh encodings with sizes 0 and 1 to box=None, removes the metadata, preserves periodic boxes, avoids mutating inputs, and adds cover…
Out of Scope Changes check ✅ Passed The changes are limited to normalize_batch() and regression tests directly related to preserving non-periodic batch semantics. No unrelated code changes are present.
  • 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 77.68%. Comparing base (8cfd46e) to head (4399883).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6003      +/-   ##
==========================================
- Coverage   79.10%   77.68%   -1.42%     
==========================================
  Files        1105     1105              
  Lines      130981   130983       +2     
  Branches     4771     4765       -6     
==========================================
- Hits       103609   101758    -1851     
- Misses      25686    27546    +1860     
+ Partials     1686     1679       -7     

☔ 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
@njzjz
njzjz requested a review from wanghan-iapcm September 7, 2026 14:59
Merge upstream master at 28b7d06 so fresh PR checks include the corrected
training-argument fixture for EMA checkpoint retention. The nopbc changes
remain limited to batch normalization and its regression tests.

Validation: ruff format .; ruff check .; git diff --check; focused pytest
coverage for training arguments, nopbc batches, and charge states
(13 passed, 10 subtests passed).

Coding-Agent: Codex
Codex-Version: codex-cli 0.153.4
Model: gpt-6-astra
Reasoning-Effort: xhigh
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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