Skip to content

fix(lammps): validate dplr and spin options#5842

Open
njzjz-bot wants to merge 2 commits into
deepmodeling:masterfrom
njzjz-bot:fix/lammps-dplr-spin-option-parsing-5645
Open

fix(lammps): validate dplr and spin options#5842
njzjz-bot wants to merge 2 commits into
deepmodeling:masterfrom
njzjz-bot:fix/lammps-dplr-spin-option-parsing-5645

Conversation

@njzjz-bot

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

Copy link
Copy Markdown
Contributor

Summary

  • validate fix dplr model and electric-field values before reading them
  • report odd type_associate lists through a normal LAMMPS input error instead of an assertion
  • validate relative, relative_v, virtual_len, and spin_norm values in both pair parsers and parse numeric values strictly
  • add subprocess-isolated regressions for truncated options and keywords supplied where values are required

Why existing tests missed the bugs

  • DPLR tests supplied a model path, all three efield components, and paired type_associate entries, so they never reached the off-by-one reads or assertion path.
  • DeepMD and DeepSpin model-deviation tests always supplied values after relative and relative_v, so the parsers never read beyond the final argument.
  • No parser tests exercised virtual_len or spin_norm with missing values or a following keyword, leaving their unchecked loops uncovered.
  • The new negative tests run LAMMPS in subprocesses because the old out-of-bounds behavior could abort or segfault instead of raising a catchable input error.

Validation

  • cmake --build source/build --target deepmd_lmp -j2
  • pytest source/lmp/tests/test_lammps_option_parsers.py -q (18 passed)
  • representative existing DPLR, DeepMD relative-virial, and DeepSpin tests (4 passed)
  • ruff format .
  • ruff check .

Fixes #5645

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation for DeePMD and DeepSpin simulation options, preventing incomplete or ambiguous values from causing parser failures.
    • Added clearer error messages for invalid model, electric-field, spin, and association settings.
    • Invalid numeric inputs are now rejected consistently.
    • Enforced the requirement for an even number of associated atom types.
  • Tests

    • Added regression coverage for malformed and incomplete option lists.
    • Verified that valid DeepSpin configurations continue to work correctly.

Reject truncated or keyword-valued DPLR and model-deviation options before reading them. Replace the type_associate assertion with a normal LAMMPS input error and use strict numeric conversion for spin parser values.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@dosubot dosubot Bot added the bug label Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 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

Run ID: b463a456-0801-44ce-a1f7-bdfe3ac7957b

📥 Commits

Reviewing files that changed from the base of the PR and between 6c3b985 and 5f65a39.

📒 Files selected for processing (4)
  • source/lmp/fix_dplr.cpp
  • source/lmp/pair_deepmd.cpp
  • source/lmp/pair_deepspin.cpp
  • source/lmp/tests/test_lammps_option_parsers.py

📝 Walkthrough

Walkthrough

LAMMPS DeePMD, DeepSpin, and DPLR option parsing now validates required values, rejects keyword tokens in value positions, uses numeric conversion utilities, and includes subprocess-based regression tests.

Changes

LAMMPS parser hardening

Layer / File(s) Summary
DPLR option validation
source/lmp/fix_dplr.cpp
model and efield validate required values and keyword boundaries, while type_associate reports odd argument counts through a runtime error.
DeePMD and DeepSpin option validation
source/lmp/pair_deepmd.cpp, source/lmp/pair_deepspin.cpp
Relative, virtual-length, and spin-normalization values use utils::numeric; missing, truncated, and keyword-valued options are rejected.
Malformed option regression tests
source/lmp/tests/test_lammps_option_parsers.py
Isolated LAMMPS subprocess tests verify diagnostic failures for malformed options and successful parsing of complete DeepSpin values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: Python, C++, LAMMPS

Suggested reviewers: yi-fanli

🚥 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 concisely describes the main change: hardening LAMMPS DPLR and spin option validation.
Linked Issues check ✅ Passed The PR addresses the reported parser OOB reads, adds keyword/bounds checks, replaces the assert, and includes regression tests.
Out of Scope Changes check ✅ Passed The changes stay within LAMMPS parser hardening and regression coverage; no unrelated functionality appears added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.97436% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.32%. Comparing base (6c3b985) to head (5f65a39).

Files with missing lines Patch % Lines
source/lmp/pair_deepmd.cpp 37.50% 8 Missing and 2 partials ⚠️
source/lmp/pair_deepspin.cpp 75.00% 0 Missing and 4 partials ⚠️
source/lmp/fix_dplr.cpp 71.42% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5842      +/-   ##
==========================================
- Coverage   78.58%   78.32%   -0.26%     
==========================================
  Files        1050     1050              
  Lines      120637   120664      +27     
  Branches     4356     4369      +13     
==========================================
- Hits        94801    94510     -291     
- Misses      24278    24579     +301     
- Partials     1558     1575      +17     

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

@njzjz

njzjz commented Jul 18, 2026

Copy link
Copy Markdown
Member

Possible reviewers based on changed lines, exact file history, and exact-file review history:

  • @wanghan-iapcm — 12 commits on changed files; 16 reviews on exact changed files (source/lmp/fix_dplr.cpp, source/lmp/pair_deepmd.cpp, source/lmp/pair_deepspin.cpp).
  • @OutisLi — 24 reviews on exact changed files (source/lmp/pair_deepmd.cpp, source/lmp/pair_deepspin.cpp).

No review request was made automatically.

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

@njzjz
njzjz requested review from OutisLi and wanghan-iapcm and removed request for OutisLi and wanghan-iapcm July 18, 2026 07:19
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.

[Code scan] Harden LAMMPS DPLR and spin option argument parsing

2 participants