Skip to content

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

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

test(api): add universal DeepPot C API coverage#5538
njzjz-bot wants to merge 1 commit 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 parameterized “universal” DeepPot verification for multiple backends (TensorFlow, PyTorch, PTExpt, JAX, Paddle), including model-load validation, metadata checks, and compute accuracy (energy/forces/virial and atomic variants) for both float and double where supported.
    • Supports optional artifact conversion for TensorFlow pbtxt inputs and gracefully skips cases when a backend or artifact isn’t available.
  • Chores
    • Updated C unit test build to link against Torch libraries when PyTorch support is enabled.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a shared test reference data header (deeppot_universal_data.h) with static per-backend reference values, then introduces two new parameterized GoogleTest suites — one for the C++ API and one for the C API — that validate DeepPot model loading, metadata, and numerical compute outputs across TensorFlow, PyTorch, PTExpt, JAX, and Paddle backends. The C test build is also updated to link against Torch libraries when PyTorch support is enabled.

Changes

Universal Multi-Backend DeepPot Tests

Layer / File(s) Summary
Shared test reference data
source/tests/infer/deeppot_universal_data.h
Introduces deepmd_test::DeepPotRef struct with atomic energy, virial, and metadata fields; static accessors for coordinates, atom types, and box; two backend-specific reference instances (tf_deeppot_ref, sea_deeppot_ref); and total_energy/total_virial aggregation helpers.
C++ API universal tests
source/api_cc/tests/test_deeppot_universal.cc
Adds Backend enum, ModelCase struct with tolerances and reference pointer, compile-time backend enablement/existence helpers, model_cases() catalog, UniversalDeepPotTest fixture with optional pbtxt→pb conversion and teardown cleanup, and Metadata/ComputeDouble/ComputeFloat parameterized tests using deepmd::DeepPot.
C API universal tests and build wiring
source/api_c/tests/test_deeppot_universal.cc, source/api_c/tests/CMakeLists.txt
Adds a parallel C API test suite (UniversalDeepPotCTest) with check_compute_double/check_compute_float helpers invoking DP_DeepPotCompute2/DP_DeepPotComputef2, parameterized Metadata/ComputeDouble/ComputeFloat tests, and links runUnitTests_c against ${TORCH_LIBRARIES} so Torch inductor headers are visible at compile time.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

new feature

Suggested reviewers

  • iProzd
  • 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 'test(api): add universal DeepPot C API coverage' accurately captures the main change: adding universal cross-backend test coverage for the DeepPot C API. It is specific, clear, and directly reflects the primary objective.
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 72.22222% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.59%. Comparing base (16df629) to head (cac3931).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
source/api_c/tests/test_deeppot_universal.cc 66.34% 31 Missing and 4 partials ⚠️
source/api_cc/tests/test_deeppot_universal.cc 71.59% 17 Missing and 8 partials ⚠️

❗ There is a different number of reports uploaded between BASE (16df629) and HEAD (cac3931). Click for more details.

HEAD has 30 uploads less than BASE
Flag BASE (16df629) HEAD (cac3931)
56 26
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #5538       +/-   ##
===========================================
- Coverage   82.21%   70.59%   -11.63%     
===========================================
  Files         892      871       -21     
  Lines      101506    96269     -5237     
  Branches     4242     3554      -688     
===========================================
- Hits        83456    67961    -15495     
- Misses      16749    27590    +10841     
+ Partials     1301      718      -583     

☔ 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

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