Skip to content

test(api): add universal DeepPot C API coverage#5538

Open
njzjz-bot wants to merge 4 commits into
deepmodeling:masterfrom
njzjz-bothub:fix/issue-3905
Open

test(api): add universal DeepPot C API coverage#5538
njzjz-bot wants to merge 4 commits into
deepmodeling:masterfrom
njzjz-bothub:fix/issue-3905

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Problem

Change

  • Add shared reference data for the common DeepPot water fixture.
  • Add parameterized C++ API tests for metadata and atomic inference across TensorFlow, PyTorch, PT-Expt, JAX, and Paddle when those backends/artifacts are available.
  • Add matching C API tests using DP_DeepPotCompute2 / DP_DeepPotComputef2 and link torch in the C test target so PT-Expt guards are detected consistently.

Verification

  • uvx pre-commit run --files source/api_c/tests/CMakeLists.txt source/api_c/tests/test_deeppot_universal.cc source/api_cc/tests/test_deeppot_universal.cc source/tests/infer/deeppot_universal_data.h
  • uvx pre-commit run --from-ref origin/master --to-ref HEAD
  • Local full CTest was not run because this workspace does not have a C++ backend dependency installed; the new tests skip unavailable backend artifacts and should be exercised by the existing C++ test job after generated models are prepared.

Refs #3905

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)

Summary by CodeRabbit

  • Tests
    • Added comprehensive universal model tests validating DeepPot functionality across multiple backends (TensorFlow, PyTorch, PTExpt, JAX, Paddle) for both C and C++ APIs.
    • Tests verify model loading, metadata retrieval, and inference operations with numerical validation across different data types.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 2aef2c9d-7391-4fd4-a928-503d8f8205c4

📥 Commits

Reviewing files that changed from the base of the PR and between 4d33e2a and 2068a86.

📒 Files selected for processing (2)
  • source/api_c/tests/test_deeppot_universal.cc
  • source/api_cc/tests/test_deeppot_universal.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/api_cc/tests/test_deeppot_universal.cc

📝 Walkthrough

Walkthrough

Adds a shared header (deeppot_universal_data.h) with reference data structures and accessors for universal DeepPot testing, then introduces two new parameterized GoogleTest suites — one for the C++ API (api_cc) and one for the C API (api_c) — that validate model loading, metadata, and numerical inference across TensorFlow, PyTorch, PTExpt, JAX, and Paddle backends. The C API build is updated to link against Torch libraries when PyTorch is enabled.

Changes

Universal DeepPot Test Infrastructure

Layer / File(s) Summary
Shared test reference data and accessors
source/tests/infer/deeppot_universal_data.h
Defines deepmd_test::DeepPotRef holding per-atom energies, virial coefficients, and metadata fields. Provides static accessors for coordinate/atom-type/box data, two pre-populated reference instances (tf_deeppot_ref, sea_deeppot_ref), and total_energy/total_virial aggregation helpers.
C++ API parameterized universal tests
source/api_cc/tests/test_deeppot_universal.cc
Defines Backend enum and ModelCase struct; adds compile-time backend-enablement checks, artifact-existence helpers, and a model_cases() catalog. Implements UniversalDeepPotTest fixture with optional pbtxt→pb conversion and teardown cleanup. Adds templated check_compute<ValueType> and Metadata/ComputeDouble/ComputeFloat parameterized tests using deepmd::DeepPot.
C API parameterized universal tests and build wiring
source/api_c/tests/CMakeLists.txt, source/api_c/tests/test_deeppot_universal.cc
Links runUnitTests_c against ${TORCH_LIBRARIES} under ENABLE_PYTORCH for inductor header visibility. Adds a parallel C API test suite with check_compute_double/check_compute_float helpers calling DP_DeepPotCompute2/DP_DeepPotComputef2, and Metadata/ComputeDouble/ComputeFloat parameterized tests instantiated over model_cases().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • njzjz
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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 accurately describes the main change: adding universal DeepPot C API coverage across multiple backends, which is the primary focus of the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
source/api_cc/tests/test_deeppot_universal.cc (1)

17-99: ⚡ Quick win

Consider extracting shared test infrastructure to a common header. The Backend enum, ModelCase struct, path_exists, backend_enabled, backend_name, and model_cases functions are duplicated verbatim across both test files. Factoring these into a shared header (e.g., deeppot_universal_test_common.h) would eliminate ~80 lines of duplication and ensure backend configuration and tolerance values remain synchronized.

  • source/api_cc/tests/test_deeppot_universal.cc#L17-L99: Move the duplicated definitions to a shared header and include it.
  • source/api_c/tests/test_deeppot_universal.cc#L17-L99: Include the shared header instead of duplicating the definitions.
🤖 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 `@source/api_cc/tests/test_deeppot_universal.cc` around lines 17 - 99, The
Backend enum, ModelCase struct, and utility functions (path_exists,
backend_enabled, backend_name, model_cases) are duplicated across two test
files. Create a new shared header file named deeppot_universal_test_common.h in
the source/api_cc/tests directory and move all these duplicated definitions into
it, then update source/api_cc/tests/test_deeppot_universal.cc to include this
shared header instead of defining these symbols locally, and update
source/api_c/tests/test_deeppot_universal.cc to also include the shared header
and remove its own duplicate definitions of these symbols.
🤖 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.

Nitpick comments:
In `@source/api_cc/tests/test_deeppot_universal.cc`:
- Around line 17-99: The Backend enum, ModelCase struct, and utility functions
(path_exists, backend_enabled, backend_name, model_cases) are duplicated across
two test files. Create a new shared header file named
deeppot_universal_test_common.h in the source/api_cc/tests directory and move
all these duplicated definitions into it, then update
source/api_cc/tests/test_deeppot_universal.cc to include this shared header
instead of defining these symbols locally, and update
source/api_c/tests/test_deeppot_universal.cc to also include the shared header
and remove its own duplicate definitions of these symbols.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6d6a0011-cb3c-4d21-821c-3b52011a4b67

📥 Commits

Reviewing files that changed from the base of the PR and between 16df629 and 215fff0.

📒 Files selected for processing (4)
  • source/api_c/tests/CMakeLists.txt
  • source/api_c/tests/test_deeppot_universal.cc
  • source/api_cc/tests/test_deeppot_universal.cc
  • source/tests/infer/deeppot_universal_data.h

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.16667% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.23%. Comparing base (16df629) to head (2068a86).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
source/api_cc/tests/test_deeppot_universal.cc 85.00% 12 Missing and 3 partials ⚠️
source/api_c/tests/test_deeppot_universal.cc 90.51% 8 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5538      +/-   ##
==========================================
+ Coverage   82.21%   82.23%   +0.01%     
==========================================
  Files         892      895       +3     
  Lines      101506   101770     +264     
  Branches     4242     4264      +22     
==========================================
+ Hits        83456    83690     +234     
- Misses      16749    16770      +21     
- Partials     1301     1310       +9     

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

Add focused parameterized C and C++ API smoke tests that exercise DeepPot metadata and atomic inference over the shared TensorFlow, PyTorch, PT-Expt, JAX, and Paddle fixture matrix when those backends and generated artifacts are available.

Link torch into the C API test target so PT-Expt guards are detected consistently with the C++ API tests.

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (2)
source/api_c/tests/test_deeppot_universal.cc (1)

119-119: ⚡ Quick win

Add error handling for pbtxt-to-pb conversion.

The conversion call does not check for errors. If DP_ConvertPbtxtToPb fails silently, the subsequent model loading on line 122 will fail with an error message that does not indicate the root cause was a conversion failure, making debugging more difficult.

🛡️ Suggested approach to add error checking

Check the signature of DP_ConvertPbtxtToPb to determine its error-reporting mechanism (return value, error string, or exception), then add appropriate error handling. For example, if it returns an error string:

 if (param.convert_pbtxt) {
   converted_model = "deeppot_c_universal_" + param.name + ".pb";
-  DP_ConvertPbtxtToPb(param.model_path.c_str(), converted_model.c_str());
+  const char* conv_error = DP_ConvertPbtxtToPb(param.model_path.c_str(), converted_model.c_str());
+  if (conv_error && strlen(conv_error) > 0) {
+    std::string error_msg(conv_error);
+    DP_DeleteChar(conv_error);
+    GTEST_SKIP() << "Conversion failed: " << error_msg;
+  }
   model_path = converted_model;
 }
🤖 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 `@source/api_c/tests/test_deeppot_universal.cc` at line 119, The
DP_ConvertPbtxtToPb function call on line 119 lacks error handling, which means
if the conversion fails, the subsequent model loading error will mask the root
cause. Check the signature and return type of DP_ConvertPbtxtToPb to determine
its error-reporting mechanism (return value, error string output parameter, or
exception), then add appropriate error checking and handling immediately after
the conversion call that either logs the error details and returns early or
throws an exception with a clear message indicating the pbtxt-to-pb conversion
failed.
source/api_cc/tests/test_deeppot_universal.cc (1)

119-119: ⚡ Quick win

Add error handling for pbtxt-to-pb conversion.

The conversion call does not check for errors. If deepmd::convert_pbtxt_to_pb fails (either by throwing an exception or silently), the subsequent dp.init() call on line 122 may fail with an error message that does not clearly indicate the root cause was a conversion failure.

🛡️ Suggested approach to add error checking

Wrap the conversion in a try-catch block or verify its error-reporting mechanism:

 if (param.convert_pbtxt) {
   converted_model = "deeppot_universal_" + param.name + ".pb";
-  deepmd::convert_pbtxt_to_pb(param.model_path, converted_model);
+  try {
+    deepmd::convert_pbtxt_to_pb(param.model_path, converted_model);
+  } catch (const std::exception& e) {
+    GTEST_SKIP() << "Conversion failed: " << e.what();
+  }
   model_path = converted_model;
 }
🤖 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 `@source/api_cc/tests/test_deeppot_universal.cc` at line 119, The
deepmd::convert_pbtxt_to_pb function call does not have error handling, which
means if the conversion fails (either by throwing an exception or returning an
error state), the subsequent dp.init() call will fail with an unclear error
message that does not indicate the conversion was the root cause. Add error
handling around the deepmd::convert_pbtxt_to_pb call by either wrapping it in a
try-catch block to catch exceptions or checking its return value/error state if
it provides one, and ensure that any conversion failure is logged or handled
appropriately before attempting the dp.init() call.
🤖 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.

Nitpick comments:
In `@source/api_c/tests/test_deeppot_universal.cc`:
- Line 119: The DP_ConvertPbtxtToPb function call on line 119 lacks error
handling, which means if the conversion fails, the subsequent model loading
error will mask the root cause. Check the signature and return type of
DP_ConvertPbtxtToPb to determine its error-reporting mechanism (return value,
error string output parameter, or exception), then add appropriate error
checking and handling immediately after the conversion call that either logs the
error details and returns early or throws an exception with a clear message
indicating the pbtxt-to-pb conversion failed.

In `@source/api_cc/tests/test_deeppot_universal.cc`:
- Line 119: The deepmd::convert_pbtxt_to_pb function call does not have error
handling, which means if the conversion fails (either by throwing an exception
or returning an error state), the subsequent dp.init() call will fail with an
unclear error message that does not indicate the conversion was the root cause.
Add error handling around the deepmd::convert_pbtxt_to_pb call by either
wrapping it in a try-catch block to catch exceptions or checking its return
value/error state if it provides one, and ensure that any conversion failure is
logged or handled appropriately before attempting the dp.init() call.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cc176e68-293c-42ff-897d-53e8e9bd3679

📥 Commits

Reviewing files that changed from the base of the PR and between 215fff0 and cac3931.

📒 Files selected for processing (4)
  • source/api_c/tests/CMakeLists.txt
  • source/api_c/tests/test_deeppot_universal.cc
  • source/api_cc/tests/test_deeppot_universal.cc
  • source/tests/infer/deeppot_universal_data.h
🚧 Files skipped from review as they are similar to previous changes (2)
  • source/api_c/tests/CMakeLists.txt
  • source/tests/infer/deeppot_universal_data.h

PyTorch C API backends return the same type map with a trailing separator, so normalize whitespace before checking metadata in the universal DeepPot coverage.

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
Build PyTorch type maps without a trailing separator so the C and C++ APIs
return the same metadata string as the TensorFlow, JAX, and Paddle backends.

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
Compare universal test type maps as tokens so this coverage PR does not carry
the PyTorch trailing-separator fix, which is split into a dedicated PR.

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
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.

1 participant