diff --git a/deepmd/tf2/infer/deep_eval.py b/deepmd/tf2/infer/deep_eval.py index af5037e2e6..518af01485 100644 --- a/deepmd/tf2/infer/deep_eval.py +++ b/deepmd/tf2/infer/deep_eval.py @@ -213,6 +213,15 @@ def __init__( ) -> None: if not model_file.endswith(".savedmodeltf"): raise ValueError("TF2 backend only supports .savedmodeltf files") + if neighbor_list is not None: + # SavedModel lower calls accept extended tensors, but this wrapper + # does not yet connect the existing adapter and output fold-back + # helpers to an ASE Python neighbor-list object. + raise NotImplementedError( + "TF2 SavedModel inference does not support a custom ASE " + "neighbor_list; omit neighbor_list to use the SavedModel's " + "built-in neighbor-list builder" + ) self.output_def = output_def self.model_path = model_file self.dp = TF2SavedModelWrapper(model_file) diff --git a/source/tests/tf2/test_deep_eval.py b/source/tests/tf2/test_deep_eval.py new file mode 100644 index 0000000000..601f75723b --- /dev/null +++ b/source/tests/tf2/test_deep_eval.py @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +"""Tests for the TensorFlow 2 SavedModel inference adapter.""" + +import os + +import pytest + +if os.environ.get("DP_TEST_TF2_ONLY") != "1": + pytest.skip( + "TF2 tests require DP_TEST_TF2_ONLY=1", + allow_module_level=True, + ) + +from deepmd.dpmodel.output_def import ( + FittingOutputDef, + ModelOutputDef, +) +from deepmd.tf2.infer.deep_eval import ( + DeepEval, +) + + +def test_custom_neighbor_list_is_rejected_before_model_loading() -> None: + """A custom ASE neighbor list must not be accepted as a silent no-op.""" + output_def = ModelOutputDef(FittingOutputDef([])) + + with pytest.raises(NotImplementedError, match="custom ASE neighbor_list"): + DeepEval( + "sentinel.savedmodeltf", + output_def, + neighbor_list=object(), + )