Skip to content

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

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

fix(dpmodel): preserve nopbc batch semantics#6003
hcustc wants to merge 2 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: Pro Plus

Run ID: c4562284-0912-4da9-9574-38bd580e6e6c

📥 Commits

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

📒 Files selected for processing (1)
  • deepmd/dpmodel/utils/batch.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 detects non-periodic default_mesh encodings and converts zero box placeholders to None. Tests cover periodic preservation, metadata removal, 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 the existing box to None. Periodic boxes remain unchanged.
Validate normalization and data-system integration
source/tests/common/test_batch_nopbc.py
Tests verify normalization behavior and confirm that nopbc NPY systems provide no box to model inputs.

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

Merge Risk: ⚪ Minimal · up to 1dceb

The change narrowly converts legacy non-periodic batch metadata to the canonical representation while preserving periodic behavior, with regression coverage and checks reported as passing; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 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 identifies the primary change: preserving non-periodic batch semantics in dpmodel.
Linked Issues check ✅ Passed The implementation satisfies issue #6002 by converting legacy non-periodic default_mesh encodings to box=None, preserving periodic boxes, avoiding input mutation, and adding regression coverage fo…
Out of Scope Changes check ✅ Passed The changes are limited to normalize_batch() and related regression tests. They directly support issue #6002 and the stated pull request objectives.
Full details: Linked Issues check

Explanation

The implementation satisfies issue #6002 by converting legacy non-periodic default_mesh encodings to box=None, preserving periodic boxes, avoiding input mutation, and adding regression coverage for standard, mixed-type, and temporary NPY systems.

  • 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

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

4 participants