From 5d591e3dc615060a82afff8a87c5d182181be01f Mon Sep 17 00:00:00 2001 From: "njzjz-bot (driven by OpenClaw (model: gpt-5.4))[bot]" <48687836+njzjz-bot@users.noreply.github.com> Date: Sat, 18 Apr 2026 15:58:42 +0000 Subject: [PATCH 1/8] test(lmp): avoid duplicate pb conversions in tests Cache converted pb models in source/lmp/tests so repeated imports do not rerun the same pbtxt conversion when the output is already present and up to date. Also add a focused regression test for the helper and switch the affected LAMMPS tests to use it for shared graph outputs. Authored by OpenClaw (model: gpt-5.4) --- source/lmp/tests/model_convert.py | 80 +++++++++++++++++++ source/lmp/tests/test_deeptensor.py | 14 ++-- source/lmp/tests/test_dplr.py | 11 +-- source/lmp/tests/test_lammps.py | 13 ++- source/lmp/tests/test_lammps_3types.py | 14 ++-- source/lmp/tests/test_lammps_dpa_jax.py | 9 ++- source/lmp/tests/test_lammps_dpa_pt.py | 9 ++- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 9 ++- source/lmp/tests/test_lammps_dpa_sel_pt.py | 9 ++- source/lmp/tests/test_lammps_faparam.py | 10 +-- source/lmp/tests/test_lammps_jax.py | 9 ++- source/lmp/tests/test_lammps_pd.py | 9 ++- source/lmp/tests/test_lammps_pt.py | 9 ++- source/lmp/tests/test_lammps_spin.py | 13 ++- source/lmp/tests/test_lammps_spin_nopbc.py | 13 ++- source/lmp/tests/test_lammps_spin_nopbc_pt.py | 9 ++- source/lmp/tests/test_lammps_spin_pt.py | 9 ++- source/lmp/tests/test_model_convert.py | 56 +++++++++++++ 18 files changed, 222 insertions(+), 83 deletions(-) create mode 100644 source/lmp/tests/model_convert.py create mode 100644 source/lmp/tests/test_model_convert.py diff --git a/source/lmp/tests/model_convert.py b/source/lmp/tests/model_convert.py new file mode 100644 index 0000000000..b19ae3df84 --- /dev/null +++ b/source/lmp/tests/model_convert.py @@ -0,0 +1,80 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +"""Helpers for preparing converted TensorFlow graph files in LAMMPS tests.""" + +from __future__ import annotations + +import os +import subprocess as sp +import sys +import tempfile +import time +from pathlib import Path + +_LOCK_TIMEOUT_SECONDS = 60.0 +_LOCK_POLL_SECONDS = 0.1 + + +def _is_up_to_date(source: Path, output: Path) -> bool: + return output.exists() and output.stat().st_mtime_ns >= source.stat().st_mtime_ns + + +def ensure_converted_pb(source: Path, output: Path) -> Path: + """Convert ``source`` into ``output`` only when the target is missing or stale. + + The conversion is protected by a simple lock file and uses atomic replacement so + repeated imports across multiple test modules do not regenerate the same model + more than once. + """ + + source = source.resolve() + output = output.resolve() + output.parent.mkdir(parents=True, exist_ok=True) + lock_file = output.with_name(f".{output.name}.lock") + started = time.monotonic() + + while True: + if _is_up_to_date(source, output): + return output + try: + fd = os.open(str(lock_file), os.O_CREAT | os.O_EXCL | os.O_WRONLY) + except FileExistsError: + if time.monotonic() - started >= _LOCK_TIMEOUT_SECONDS: + raise TimeoutError(f"Timed out waiting for {lock_file}") + time.sleep(_LOCK_POLL_SECONDS) + continue + break + + tmp_path: Path | None = None + try: + with os.fdopen(fd, "w", encoding="utf-8") as handle: + handle.write(f"pid={os.getpid()}\n") + + if _is_up_to_date(source, output): + return output + + tmp_fd, tmp_name = tempfile.mkstemp( + dir=output.parent, + prefix=f".{output.name}.", + ) + os.close(tmp_fd) + tmp_path = Path(tmp_name) + sp.check_output( + [ + sys.executable, + "-m", + "deepmd", + "convert-from", + "pbtxt", + "-i", + str(source), + "-o", + str(tmp_path), + ] + ) + tmp_path.replace(output) + tmp_path = None + return output + finally: + if tmp_path is not None: + tmp_path.unlink(missing_ok=True) + lock_file.unlink(missing_ok=True) diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 20be3033b8..3738ac7977 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -1,7 +1,5 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import os -import subprocess as sp -import sys from pathlib import ( Path, ) @@ -16,6 +14,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent / "graph.pb" pbtxt_file2 = ( @@ -56,13 +58,9 @@ # type_HO = np.array([2, 1, 1, 2, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() -) +ensure_converted_pb(pbtxt_file, pb_file) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index dd0c03aabe..aac46348a1 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -1,7 +1,5 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import os -import subprocess as sp -import sys from pathlib import ( Path, ) @@ -16,6 +14,10 @@ write_lmp_data_full, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent / "lrmodel.pbtxt" pb_file = Path(__file__).parent / "lrmodel.pb" dipole_pbtxt_file = Path(__file__).parent / "lrdipole.pbtxt" @@ -265,9 +267,8 @@ mesh = 10 -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() -) +ensure_converted_pb(pbtxt_file, pb_file) +ensure_converted_pb(dipole_pbtxt_file, dipole_pb_file) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 0e53b38d7b..3c2ccedf00 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" @@ -221,12 +224,8 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() -) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file, pb_file) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index 9156914dbc..dfb8bbed58 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -1,7 +1,5 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import os -import subprocess as sp -import sys from pathlib import ( Path, ) @@ -15,6 +13,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" @@ -244,12 +246,8 @@ # https://github.com/lammps/lammps/blob/1e1311cf401c5fc2614b5d6d0ff3230642b76597/src/update.cpp#L193 nktv2p = 1.6021765e6 -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() -) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file, pb_file) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index 51b2d56742..896262c2cc 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -222,9 +225,7 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module(): diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index 6dfa6099e2..bc896d8cbf 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -220,9 +223,7 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index 989a782b5f..bd296a6b8a 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot_dpa.pth" pb_file2 = Path(__file__).parent / "graph.pb" @@ -218,9 +221,7 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index f65c710409..ebe99758a6 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -223,9 +226,7 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index 1a614c3d24..f59f2dd115 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -2,8 +2,6 @@ """Test LAMMPS fparam and aparam input.""" import os -import subprocess as sp -import sys from pathlib import ( Path, ) @@ -18,6 +16,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "fparam_aparam.pbtxt" ) @@ -134,9 +136,7 @@ type_OH = np.array([1, 1, 1, 1, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() -) +ensure_converted_pb(pbtxt_file, pb_file) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index e3d0e5ce74..86715d2de0 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -222,9 +225,7 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module(): diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index 85275c4027..ed6605ed8c 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -223,9 +226,7 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module(): diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index f6fb8f949b..7b6398c91c 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -220,9 +223,7 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index 79050297a5..6600c8624c 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" ) @@ -210,12 +213,8 @@ type_NiO = np.array([1, 1, 2, 2]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() -) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file, pb_file) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_spin_nopbc.py b/source/lmp/tests/test_lammps_spin_nopbc.py index 718a8e2ccc..5bb918477f 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc.py +++ b/source/lmp/tests/test_lammps_spin_nopbc.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -18,6 +17,10 @@ write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" ) @@ -208,12 +211,8 @@ ) type_NiO = np.array([1, 1, 2, 2]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() -) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file, pb_file) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_spin_nopbc_pt.py b/source/lmp/tests/test_lammps_spin_nopbc_pt.py index 486538fe8b..e22324b1ad 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc_pt.py +++ b/source/lmp/tests/test_lammps_spin_nopbc_pt.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -18,6 +17,10 @@ write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" ) @@ -87,9 +90,7 @@ type_NiO = np.array([1, 1, 2, 2]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index 8a21f27710..1997c8e606 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -2,7 +2,6 @@ import importlib import os import shutil -import subprocess as sp import sys import tempfile from pathlib import ( @@ -19,6 +18,10 @@ write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" ) @@ -178,9 +181,7 @@ type_NiO = np.array([1, 1, 2, 2]) -sp.check_output( - f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() -) +ensure_converted_pb(pbtxt_file2, pb_file2) def setup_module() -> None: diff --git a/source/lmp/tests/test_model_convert.py b/source/lmp/tests/test_model_convert.py new file mode 100644 index 0000000000..7c0ecb6a44 --- /dev/null +++ b/source/lmp/tests/test_model_convert.py @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later + +from __future__ import annotations + +import tempfile +import unittest +from pathlib import Path +from unittest.mock import patch + +from source.lmp.tests.model_convert import ensure_converted_pb + + +class TestEnsureConvertedPb(unittest.TestCase): + def test_skips_up_to_date_output(self) -> None: + with tempfile.TemporaryDirectory() as tmpdir: + tmp_path = Path(tmpdir) + source = tmp_path / "model.pbtxt" + output = tmp_path / "model.pb" + source.write_text("source") + output.write_text("converted") + source.touch() + output.touch() + + with patch( + "source.lmp.tests.model_convert.sp.check_output" + ) as convert_mock: + ensure_converted_pb(source, output) + + convert_mock.assert_not_called() + + def test_rebuilds_stale_output(self) -> None: + with tempfile.TemporaryDirectory() as tmpdir: + tmp_path = Path(tmpdir) + source = tmp_path / "model.pbtxt" + output = tmp_path / "model.pb" + output.write_text("old") + output.touch() + source.write_text("new") + source.touch() + + def fake_convert(cmd: list[str]) -> bytes: + Path(cmd[-1]).write_text("converted") + return b"" + + with patch( + "source.lmp.tests.model_convert.sp.check_output", + side_effect=fake_convert, + ) as convert_mock: + ensure_converted_pb(source, output) + + convert_mock.assert_called_once() + self.assertEqual(output.read_text(), "converted") + + +if __name__ == "__main__": + unittest.main() From 76fb1b9f2f9a515db83413fea4e050305ddd6b75 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:00:18 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/tests/model_convert.py | 9 ++++++--- source/lmp/tests/test_deeptensor.py | 7 +++---- source/lmp/tests/test_dplr.py | 7 +++---- source/lmp/tests/test_lammps.py | 7 +++---- source/lmp/tests/test_lammps_3types.py | 7 +++---- source/lmp/tests/test_lammps_dpa_jax.py | 7 +++---- source/lmp/tests/test_lammps_dpa_pt.py | 7 +++---- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 7 +++---- source/lmp/tests/test_lammps_dpa_sel_pt.py | 7 +++---- source/lmp/tests/test_lammps_faparam.py | 7 +++---- source/lmp/tests/test_lammps_jax.py | 7 +++---- source/lmp/tests/test_lammps_pd.py | 7 +++---- source/lmp/tests/test_lammps_pt.py | 7 +++---- source/lmp/tests/test_lammps_spin.py | 7 +++---- source/lmp/tests/test_lammps_spin_nopbc.py | 7 +++---- source/lmp/tests/test_lammps_spin_nopbc_pt.py | 7 +++---- source/lmp/tests/test_lammps_spin_pt.py | 7 +++---- source/lmp/tests/test_model_convert.py | 16 ++++++++++++---- 18 files changed, 66 insertions(+), 71 deletions(-) diff --git a/source/lmp/tests/model_convert.py b/source/lmp/tests/model_convert.py index b19ae3df84..b1d6343dd5 100644 --- a/source/lmp/tests/model_convert.py +++ b/source/lmp/tests/model_convert.py @@ -1,14 +1,18 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Helpers for preparing converted TensorFlow graph files in LAMMPS tests.""" -from __future__ import annotations +from __future__ import ( + annotations, +) import os import subprocess as sp import sys import tempfile import time -from pathlib import Path +from pathlib import ( + Path, +) _LOCK_TIMEOUT_SECONDS = 60.0 _LOCK_POLL_SECONDS = 0.1 @@ -25,7 +29,6 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: repeated imports across multiple test modules do not regenerate the same model more than once. """ - source = source.resolve() output = output.resolve() output.parent.mkdir(parents=True, exist_ok=True) diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 3738ac7977..a2a8c6f7e1 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -10,13 +10,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent / "graph.pb" diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index aac46348a1..7c76fea74a 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -10,13 +10,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_full, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_full, +) pbtxt_file = Path(__file__).parent / "lrmodel.pbtxt" pb_file = Path(__file__).parent / "lrmodel.pb" diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 3c2ccedf00..f3c44cd19b 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index dfb8bbed58..ee8c88f4d1 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -9,13 +9,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index 896262c2cc..436cbad076 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index bc896d8cbf..01bfbf1128 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index bd296a6b8a..d5808ddfee 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot_dpa.pth" diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index ebe99758a6..27c5beeeee 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index f59f2dd115..21269bd54e 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -12,13 +12,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "fparam_aparam.pbtxt" diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index 86715d2de0..09daed4c1e 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index ed6605ed8c..82a7f196a6 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index 7b6398c91c..67840c3b68 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index 6600c8624c..f9085a5693 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_nopbc.py b/source/lmp/tests/test_lammps_spin_nopbc.py index 5bb918477f..f3a5bb5b14 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc.py +++ b/source/lmp/tests/test_lammps_spin_nopbc.py @@ -13,13 +13,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_nopbc_pt.py b/source/lmp/tests/test_lammps_spin_nopbc_pt.py index e22324b1ad..d20aa334b8 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc_pt.py +++ b/source/lmp/tests/test_lammps_spin_nopbc_pt.py @@ -13,13 +13,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index 1997c8e606..9f99912636 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" diff --git a/source/lmp/tests/test_model_convert.py b/source/lmp/tests/test_model_convert.py index 7c0ecb6a44..390ab1a0e6 100644 --- a/source/lmp/tests/test_model_convert.py +++ b/source/lmp/tests/test_model_convert.py @@ -1,13 +1,21 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from __future__ import annotations +from __future__ import ( + annotations, +) import tempfile import unittest -from pathlib import Path -from unittest.mock import patch +from pathlib import ( + Path, +) +from unittest.mock import ( + patch, +) -from source.lmp.tests.model_convert import ensure_converted_pb +from source.lmp.tests.model_convert import ( + ensure_converted_pb, +) class TestEnsureConvertedPb(unittest.TestCase): From 57560712428e24f1bbe20622d68b3ace20e23f37 Mon Sep 17 00:00:00 2001 From: "njzjz-bot (driven by OpenClaw (model: gpt-5.4))[bot]" <48687836+njzjz-bot@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:13:05 +0000 Subject: [PATCH 3/8] test(lmp): fix pre-commit fallout in conversion cache changes Drop the extra helper regression test, restore the subprocess imports still needed by the MPI checks, and make the lock timeout raise explicit for Ruff. Authored by OpenClaw (model: gpt-5.4) --- source/lmp/tests/model_convert.py | 13 ++-- source/lmp/tests/test_deeptensor.py | 7 +- source/lmp/tests/test_dplr.py | 7 +- source/lmp/tests/test_lammps.py | 8 ++- source/lmp/tests/test_lammps_3types.py | 7 +- source/lmp/tests/test_lammps_dpa_jax.py | 8 ++- source/lmp/tests/test_lammps_dpa_pt.py | 8 ++- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 8 ++- source/lmp/tests/test_lammps_dpa_sel_pt.py | 8 ++- source/lmp/tests/test_lammps_faparam.py | 7 +- source/lmp/tests/test_lammps_jax.py | 8 ++- source/lmp/tests/test_lammps_pd.py | 8 ++- source/lmp/tests/test_lammps_pt.py | 8 ++- source/lmp/tests/test_lammps_spin.py | 8 ++- source/lmp/tests/test_lammps_spin_nopbc.py | 8 ++- source/lmp/tests/test_lammps_spin_nopbc_pt.py | 8 ++- source/lmp/tests/test_lammps_spin_pt.py | 8 ++- source/lmp/tests/test_model_convert.py | 64 ------------------- 18 files changed, 81 insertions(+), 120 deletions(-) delete mode 100644 source/lmp/tests/test_model_convert.py diff --git a/source/lmp/tests/model_convert.py b/source/lmp/tests/model_convert.py index b1d6343dd5..cf59acf2b7 100644 --- a/source/lmp/tests/model_convert.py +++ b/source/lmp/tests/model_convert.py @@ -1,18 +1,14 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Helpers for preparing converted TensorFlow graph files in LAMMPS tests.""" -from __future__ import ( - annotations, -) +from __future__ import annotations import os import subprocess as sp import sys import tempfile import time -from pathlib import ( - Path, -) +from pathlib import Path _LOCK_TIMEOUT_SECONDS = 60.0 _LOCK_POLL_SECONDS = 0.1 @@ -29,6 +25,7 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: repeated imports across multiple test modules do not regenerate the same model more than once. """ + source = source.resolve() output = output.resolve() output.parent.mkdir(parents=True, exist_ok=True) @@ -40,9 +37,9 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: return output try: fd = os.open(str(lock_file), os.O_CREAT | os.O_EXCL | os.O_WRONLY) - except FileExistsError: + except FileExistsError as err: if time.monotonic() - started >= _LOCK_TIMEOUT_SECONDS: - raise TimeoutError(f"Timed out waiting for {lock_file}") + raise TimeoutError(f"Timed out waiting for {lock_file}") from err time.sleep(_LOCK_POLL_SECONDS) continue break diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index a2a8c6f7e1..3738ac7977 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -10,13 +10,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent / "graph.pb" pbtxt_file2 = ( diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index 7c76fea74a..aac46348a1 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -10,13 +10,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_full, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent / "lrmodel.pbtxt" pb_file = Path(__file__).parent / "lrmodel.pb" dipole_pbtxt_file = Path(__file__).parent / "lrdipole.pbtxt" diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index f3c44cd19b..e3d56e9597 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index ee8c88f4d1..dfb8bbed58 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -9,13 +9,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index 436cbad076..95991bf4ba 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index 01bfbf1128..57f37b8102 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index d5808ddfee..510ae5fccc 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot_dpa.pth" pb_file2 = Path(__file__).parent / "graph.pb" diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index 27c5beeeee..90895f47b2 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index 21269bd54e..f59f2dd115 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -12,13 +12,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "fparam_aparam.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index 09daed4c1e..32f0295386 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index 82a7f196a6..38b73290a6 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index 67840c3b68..d55adccdbb 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index f9085a5693..bcf53e66af 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_spin_nopbc.py b/source/lmp/tests/test_lammps_spin_nopbc.py index f3a5bb5b14..4419bbb689 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc.py +++ b/source/lmp/tests/test_lammps_spin_nopbc.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -13,13 +14,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_spin_nopbc_pt.py b/source/lmp/tests/test_lammps_spin_nopbc_pt.py index d20aa334b8..f58c73e87e 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc_pt.py +++ b/source/lmp/tests/test_lammps_spin_nopbc_pt.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -13,13 +14,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index 9f99912636..2b2346c9a8 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os +import subprocess as sp import shutil import sys import tempfile @@ -14,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" ) diff --git a/source/lmp/tests/test_model_convert.py b/source/lmp/tests/test_model_convert.py deleted file mode 100644 index 390ab1a0e6..0000000000 --- a/source/lmp/tests/test_model_convert.py +++ /dev/null @@ -1,64 +0,0 @@ -# SPDX-License-Identifier: LGPL-3.0-or-later - -from __future__ import ( - annotations, -) - -import tempfile -import unittest -from pathlib import ( - Path, -) -from unittest.mock import ( - patch, -) - -from source.lmp.tests.model_convert import ( - ensure_converted_pb, -) - - -class TestEnsureConvertedPb(unittest.TestCase): - def test_skips_up_to_date_output(self) -> None: - with tempfile.TemporaryDirectory() as tmpdir: - tmp_path = Path(tmpdir) - source = tmp_path / "model.pbtxt" - output = tmp_path / "model.pb" - source.write_text("source") - output.write_text("converted") - source.touch() - output.touch() - - with patch( - "source.lmp.tests.model_convert.sp.check_output" - ) as convert_mock: - ensure_converted_pb(source, output) - - convert_mock.assert_not_called() - - def test_rebuilds_stale_output(self) -> None: - with tempfile.TemporaryDirectory() as tmpdir: - tmp_path = Path(tmpdir) - source = tmp_path / "model.pbtxt" - output = tmp_path / "model.pb" - output.write_text("old") - output.touch() - source.write_text("new") - source.touch() - - def fake_convert(cmd: list[str]) -> bytes: - Path(cmd[-1]).write_text("converted") - return b"" - - with patch( - "source.lmp.tests.model_convert.sp.check_output", - side_effect=fake_convert, - ) as convert_mock: - ensure_converted_pb(source, output) - - convert_mock.assert_called_once() - self.assertEqual(output.read_text(), "converted") - - -if __name__ == "__main__": - unittest.main() From 549eda6af698d4a741f37c78bd6dd83c5e6a2fc3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:13:46 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/tests/model_convert.py | 9 ++++++--- source/lmp/tests/test_deeptensor.py | 7 +++---- source/lmp/tests/test_dplr.py | 7 +++---- source/lmp/tests/test_lammps.py | 9 ++++----- source/lmp/tests/test_lammps_3types.py | 7 +++---- source/lmp/tests/test_lammps_dpa_jax.py | 9 ++++----- source/lmp/tests/test_lammps_dpa_pt.py | 9 ++++----- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 9 ++++----- source/lmp/tests/test_lammps_dpa_sel_pt.py | 9 ++++----- source/lmp/tests/test_lammps_faparam.py | 7 +++---- source/lmp/tests/test_lammps_jax.py | 9 ++++----- source/lmp/tests/test_lammps_pd.py | 9 ++++----- source/lmp/tests/test_lammps_pt.py | 9 ++++----- source/lmp/tests/test_lammps_spin.py | 9 ++++----- source/lmp/tests/test_lammps_spin_nopbc.py | 9 ++++----- source/lmp/tests/test_lammps_spin_nopbc_pt.py | 9 ++++----- source/lmp/tests/test_lammps_spin_pt.py | 9 ++++----- 17 files changed, 66 insertions(+), 79 deletions(-) diff --git a/source/lmp/tests/model_convert.py b/source/lmp/tests/model_convert.py index cf59acf2b7..0149a65074 100644 --- a/source/lmp/tests/model_convert.py +++ b/source/lmp/tests/model_convert.py @@ -1,14 +1,18 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Helpers for preparing converted TensorFlow graph files in LAMMPS tests.""" -from __future__ import annotations +from __future__ import ( + annotations, +) import os import subprocess as sp import sys import tempfile import time -from pathlib import Path +from pathlib import ( + Path, +) _LOCK_TIMEOUT_SECONDS = 60.0 _LOCK_POLL_SECONDS = 0.1 @@ -25,7 +29,6 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: repeated imports across multiple test modules do not regenerate the same model more than once. """ - source = source.resolve() output = output.resolve() output.parent.mkdir(parents=True, exist_ok=True) diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 3738ac7977..a2a8c6f7e1 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -10,13 +10,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent / "graph.pb" diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index aac46348a1..7c76fea74a 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -10,13 +10,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_full, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_full, +) pbtxt_file = Path(__file__).parent / "lrmodel.pbtxt" pb_file = Path(__file__).parent / "lrmodel.pb" diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index e3d56e9597..08582b3136 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index dfb8bbed58..ee8c88f4d1 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -9,13 +9,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index 95991bf4ba..bb05b1b0ca 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index 57f37b8102..adc61da67b 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index 510ae5fccc..f1f82b471d 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot_dpa.pth" diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index 90895f47b2..bab3dcdea7 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index f59f2dd115..21269bd54e 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -12,13 +12,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "fparam_aparam.pbtxt" diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index 32f0295386..9183bd11a5 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index 38b73290a6..40155632b7 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index d55adccdbb..85df748734 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index bcf53e66af..540223791a 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_nopbc.py b/source/lmp/tests/test_lammps_spin_nopbc.py index 4419bbb689..288b63d08e 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc.py +++ b/source/lmp/tests/test_lammps_spin_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_nopbc_pt.py b/source/lmp/tests/test_lammps_spin_nopbc_pt.py index f58c73e87e..2fc13466c4 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc_pt.py +++ b/source/lmp/tests/test_lammps_spin_nopbc_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index 2b2346c9a8..6d61c223fe 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" From 06769a10301d5a3a5402b3f5e25f6559f780b3db Mon Sep 17 00:00:00 2001 From: "njzjz-bot (driven by OpenClaw (model: gpt-5.4))[bot]" <48687836+njzjz-bot@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:37:15 +0000 Subject: [PATCH 5/8] test(lmp): defer conversions until runtime guards pass Move the shared pb conversion calls out of import time so modules can still be collected and skipped cleanly when the required backend is disabled. Also harden the conversion lock handling against stale lock files and switch the conversion subprocess to a non-buffering checked run. Authored by OpenClaw (model: gpt-5.4) --- source/lmp/tests/model_convert.py | 56 ++++++++++++++++--- source/lmp/tests/test_deeptensor.py | 15 +++-- source/lmp/tests/test_dplr.py | 14 ++--- source/lmp/tests/test_lammps.py | 16 +++--- source/lmp/tests/test_lammps_3types.py | 14 ++--- source/lmp/tests/test_lammps_dpa_jax.py | 15 ++--- source/lmp/tests/test_lammps_dpa_pt.py | 15 ++--- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 15 ++--- source/lmp/tests/test_lammps_dpa_sel_pt.py | 15 ++--- source/lmp/tests/test_lammps_faparam.py | 12 ++-- source/lmp/tests/test_lammps_jax.py | 15 ++--- source/lmp/tests/test_lammps_pd.py | 15 ++--- source/lmp/tests/test_lammps_pt.py | 15 ++--- source/lmp/tests/test_lammps_spin.py | 16 +++--- source/lmp/tests/test_lammps_spin_nopbc.py | 16 +++--- source/lmp/tests/test_lammps_spin_nopbc_pt.py | 15 ++--- source/lmp/tests/test_lammps_spin_pt.py | 15 ++--- 17 files changed, 171 insertions(+), 123 deletions(-) diff --git a/source/lmp/tests/model_convert.py b/source/lmp/tests/model_convert.py index 0149a65074..06f0a3d9d4 100644 --- a/source/lmp/tests/model_convert.py +++ b/source/lmp/tests/model_convert.py @@ -1,18 +1,15 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Helpers for preparing converted TensorFlow graph files in LAMMPS tests.""" -from __future__ import ( - annotations, -) +from __future__ import annotations +import errno import os import subprocess as sp import sys import tempfile import time -from pathlib import ( - Path, -) +from pathlib import Path _LOCK_TIMEOUT_SECONDS = 60.0 _LOCK_POLL_SECONDS = 0.1 @@ -22,6 +19,44 @@ def _is_up_to_date(source: Path, output: Path) -> bool: return output.exists() and output.stat().st_mtime_ns >= source.stat().st_mtime_ns +def _read_lock_pid(lock_file: Path) -> int | None: + try: + for line in lock_file.read_text(encoding="utf-8").splitlines(): + if line.startswith("pid="): + return int(line.split("=", maxsplit=1)[1]) + except (FileNotFoundError, ValueError): + return None + return None + + +def _pid_is_running(pid: int) -> bool: + try: + os.kill(pid, 0) + except ProcessLookupError: + return False + except PermissionError: + return True + except OSError as err: + if err.errno == errno.ESRCH: + return False + raise + return True + + +def _should_break_stale_lock(lock_file: Path) -> bool: + try: + lock_stat = lock_file.stat() + except FileNotFoundError: + return False + + lock_age = time.time() - lock_stat.st_mtime + if lock_age > _LOCK_TIMEOUT_SECONDS: + return True + + lock_pid = _read_lock_pid(lock_file) + return lock_pid is not None and not _pid_is_running(lock_pid) + + def ensure_converted_pb(source: Path, output: Path) -> Path: """Convert ``source`` into ``output`` only when the target is missing or stale. @@ -29,6 +64,7 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: repeated imports across multiple test modules do not regenerate the same model more than once. """ + source = source.resolve() output = output.resolve() output.parent.mkdir(parents=True, exist_ok=True) @@ -41,6 +77,9 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: try: fd = os.open(str(lock_file), os.O_CREAT | os.O_EXCL | os.O_WRONLY) except FileExistsError as err: + if _should_break_stale_lock(lock_file): + lock_file.unlink(missing_ok=True) + continue if time.monotonic() - started >= _LOCK_TIMEOUT_SECONDS: raise TimeoutError(f"Timed out waiting for {lock_file}") from err time.sleep(_LOCK_POLL_SECONDS) @@ -61,7 +100,7 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: ) os.close(tmp_fd) tmp_path = Path(tmp_name) - sp.check_output( + sp.run( [ sys.executable, "-m", @@ -72,7 +111,8 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: str(source), "-o", str(tmp_path), - ] + ], + check=True, ) tmp_path.replace(output) tmp_path = None diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index a2a8c6f7e1..0b7fb4905e 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -10,13 +10,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent / "graph.pb" pbtxt_file2 = ( @@ -57,16 +58,14 @@ # type_HO = np.array([2, 1, 1, 2, 1, 1]) -ensure_converted_pb(pbtxt_file, pb_file) - -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( "Skip test because TensorFlow support is not enabled.", ) + ensure_converted_pb(pbtxt_file, pb_file) + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) # TODO # write_lmp_data(box, coord, type_HO, data_type_map_file) diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index 7c76fea74a..9cce58c80e 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -10,13 +10,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_full, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent / "lrmodel.pbtxt" pb_file = Path(__file__).parent / "lrmodel.pb" dipole_pbtxt_file = Path(__file__).parent / "lrdipole.pbtxt" @@ -266,15 +267,14 @@ mesh = 10 -ensure_converted_pb(pbtxt_file, pb_file) -ensure_converted_pb(dipole_pbtxt_file, dipole_pb_file) - - def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( "Skip test because TensorFlow support is not enabled.", ) + ensure_converted_pb(pbtxt_file, pb_file) + ensure_converted_pb(dipole_pbtxt_file, dipole_pb_file) + write_lmp_data_full( box, coord, mol_list, type_OH, charge, data_file, bond_list, mass_list ) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 08582b3136..ad5ac91fd4 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" @@ -224,15 +225,14 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -ensure_converted_pb(pbtxt_file, pb_file) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( "Skip test because TensorFlow support is not enabled.", ) + ensure_converted_pb(pbtxt_file, pb_file) + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) write_lmp_data(box, coord, type_HO, data_type_map_file) write_lmp_data( diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index ee8c88f4d1..9267c7bfd4 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -9,13 +9,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" @@ -245,15 +246,14 @@ # https://github.com/lammps/lammps/blob/1e1311cf401c5fc2614b5d6d0ff3230642b76597/src/update.cpp#L193 nktv2p = 1.6021765e6 -ensure_converted_pb(pbtxt_file, pb_file) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( "Skip test because TensorFlow support is not enabled.", ) + ensure_converted_pb(pbtxt_file, pb_file) + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) write_lmp_data(box, coord, type_HO, data_type_map_file) diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index bb05b1b0ca..7d21170ea9 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -225,14 +226,14 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module(): if os.environ.get("ENABLE_JAX", "1") != "1": pytest.skip( "Skip test because JAX support is not enabled.", ) + if os.environ.get("ENABLE_TENSORFLOW", "1") == "1": + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) write_lmp_data(box, coord, type_HO, data_type_map_file) write_lmp_data( diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index adc61da67b..db5a4c7cad 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -223,14 +224,14 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_PYTORCH", "1") != "1": pytest.skip( "Skip test because PyTorch support is not enabled.", ) + if os.environ.get("ENABLE_TENSORFLOW", "1") == "1": + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) write_lmp_data(box, coord, type_HO, data_type_map_file) write_lmp_data( diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index f1f82b471d..a88c14963e 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot_dpa.pth" pb_file2 = Path(__file__).parent / "graph.pb" @@ -221,14 +222,14 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_PYTORCH", "1") != "1": pytest.skip( "Skip test because PyTorch support is not enabled.", ) + if os.environ.get("ENABLE_TENSORFLOW", "1") == "1": + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) write_lmp_data(box, coord, type_HO, data_type_map_file) write_lmp_data( diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index bab3dcdea7..3379a70ade 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -226,14 +227,14 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_PYTORCH", "1") != "1": pytest.skip( "Skip test because PyTorch support is not enabled.", ) + if os.environ.get("ENABLE_TENSORFLOW", "1") == "1": + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) write_lmp_data(box, coord, type_HO, data_type_map_file) write_lmp_data( diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index 21269bd54e..c5a8238771 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -12,13 +12,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "fparam_aparam.pbtxt" ) @@ -135,14 +136,13 @@ type_OH = np.array([1, 1, 1, 1, 1, 1]) -ensure_converted_pb(pbtxt_file, pb_file) - - def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( "Skip test because TensorFlow support is not enabled.", ) + ensure_converted_pb(pbtxt_file, pb_file) + write_lmp_data(box, coord, type_OH, data_file) diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index 9183bd11a5..ae588306d3 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -225,14 +226,14 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module(): if os.environ.get("ENABLE_JAX", "1") != "1": pytest.skip( "Skip test because JAX support is not enabled.", ) + if os.environ.get("ENABLE_TENSORFLOW", "1") == "1": + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) write_lmp_data(box, coord, type_HO, data_type_map_file) write_lmp_data( diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index 40155632b7..cae4cfc921 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -226,14 +227,14 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module(): if os.environ.get("ENABLE_PADDLE", "1") != "1": pytest.skip( "Skip test because Paddle support is not enabled.", ) + if os.environ.get("ENABLE_TENSORFLOW", "1") == "1": + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) write_lmp_data(box, coord, type_HO, data_type_map_file) write_lmp_data( diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index 85df748734..6b35eed98c 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -223,14 +224,14 @@ type_HO = np.array([2, 1, 1, 2, 1, 1]) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_PYTORCH", "1") != "1": pytest.skip( "Skip test because PyTorch support is not enabled.", ) + if os.environ.get("ENABLE_TENSORFLOW", "1") == "1": + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data(box, coord, type_OH, data_file) write_lmp_data(box, coord, type_HO, data_type_map_file) write_lmp_data( diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index 540223791a..f3effef5c1 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" ) @@ -213,15 +214,14 @@ type_NiO = np.array([1, 1, 2, 2]) -ensure_converted_pb(pbtxt_file, pb_file) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( "Skip test because TensorFlow support is not enabled.", ) + ensure_converted_pb(pbtxt_file, pb_file) + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data_spin(box, coord, spin, type_NiO, data_file) diff --git a/source/lmp/tests/test_lammps_spin_nopbc.py b/source/lmp/tests/test_lammps_spin_nopbc.py index 288b63d08e..d6cdaf5a9f 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc.py +++ b/source/lmp/tests/test_lammps_spin_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -14,13 +14,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" ) @@ -211,15 +212,14 @@ ) type_NiO = np.array([1, 1, 2, 2]) -ensure_converted_pb(pbtxt_file, pb_file) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( "Skip test because TensorFlow support is not enabled.", ) + ensure_converted_pb(pbtxt_file, pb_file) + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data_spin(box, coord, spin, type_NiO, data_file) diff --git a/source/lmp/tests/test_lammps_spin_nopbc_pt.py b/source/lmp/tests/test_lammps_spin_nopbc_pt.py index 2fc13466c4..d6e7eb6aaa 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc_pt.py +++ b/source/lmp/tests/test_lammps_spin_nopbc_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -14,13 +14,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" ) @@ -90,14 +91,14 @@ type_NiO = np.array([1, 1, 2, 2]) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_PYTORCH", "1") != "1": pytest.skip( "Skip test because PyTorch support is not enabled.", ) + if os.environ.get("ENABLE_TENSORFLOW", "1") == "1": + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data_spin(box, coord, spin, type_NiO, data_file) diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index 6d61c223fe..f29d01674a 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" ) @@ -181,14 +182,14 @@ type_NiO = np.array([1, 1, 2, 2]) -ensure_converted_pb(pbtxt_file2, pb_file2) - - def setup_module() -> None: if os.environ.get("ENABLE_PYTORCH", "1") != "1": pytest.skip( "Skip test because PyTorch support is not enabled.", ) + if os.environ.get("ENABLE_TENSORFLOW", "1") == "1": + ensure_converted_pb(pbtxt_file2, pb_file2) + write_lmp_data_spin(box, coord, spin, type_NiO, data_file) From 58d2142e01dc7d986b4996a19e78a06fe7d69ab3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:37:54 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/tests/model_convert.py | 9 ++++++--- source/lmp/tests/test_deeptensor.py | 7 +++---- source/lmp/tests/test_dplr.py | 7 +++---- source/lmp/tests/test_lammps.py | 9 ++++----- source/lmp/tests/test_lammps_3types.py | 8 ++++---- source/lmp/tests/test_lammps_dpa_jax.py | 9 ++++----- source/lmp/tests/test_lammps_dpa_pt.py | 9 ++++----- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 9 ++++----- source/lmp/tests/test_lammps_dpa_sel_pt.py | 9 ++++----- source/lmp/tests/test_lammps_faparam.py | 7 +++---- source/lmp/tests/test_lammps_jax.py | 9 ++++----- source/lmp/tests/test_lammps_pd.py | 9 ++++----- source/lmp/tests/test_lammps_pt.py | 9 ++++----- source/lmp/tests/test_lammps_spin.py | 9 ++++----- source/lmp/tests/test_lammps_spin_nopbc.py | 10 +++++----- source/lmp/tests/test_lammps_spin_nopbc_pt.py | 9 ++++----- source/lmp/tests/test_lammps_spin_pt.py | 9 ++++----- 17 files changed, 68 insertions(+), 79 deletions(-) diff --git a/source/lmp/tests/model_convert.py b/source/lmp/tests/model_convert.py index 06f0a3d9d4..1d735b1899 100644 --- a/source/lmp/tests/model_convert.py +++ b/source/lmp/tests/model_convert.py @@ -1,7 +1,9 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Helpers for preparing converted TensorFlow graph files in LAMMPS tests.""" -from __future__ import annotations +from __future__ import ( + annotations, +) import errno import os @@ -9,7 +11,9 @@ import sys import tempfile import time -from pathlib import Path +from pathlib import ( + Path, +) _LOCK_TIMEOUT_SECONDS = 60.0 _LOCK_POLL_SECONDS = 0.1 @@ -64,7 +68,6 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: repeated imports across multiple test modules do not regenerate the same model more than once. """ - source = source.resolve() output = output.resolve() output.parent.mkdir(parents=True, exist_ok=True) diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 0b7fb4905e..c0f9a2d7f7 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -10,13 +10,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent / "graph.pb" diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index 9cce58c80e..defdff21c0 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -10,13 +10,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_full, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_full, +) pbtxt_file = Path(__file__).parent / "lrmodel.pbtxt" pb_file = Path(__file__).parent / "lrmodel.pb" diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index ad5ac91fd4..eca782365e 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index 9267c7bfd4..a3cef29a62 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -9,13 +9,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( @@ -246,6 +245,7 @@ # https://github.com/lammps/lammps/blob/1e1311cf401c5fc2614b5d6d0ff3230642b76597/src/update.cpp#L193 nktv2p = 1.6021765e6 + def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index 7d21170ea9..d4d63dd340 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index db5a4c7cad..2c93096556 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index a88c14963e..0edd3ed089 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot_dpa.pth" diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index 3379a70ade..685e7260e1 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index c5a8238771..c40fb9bdb0 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -12,13 +12,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "fparam_aparam.pbtxt" diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index ae588306d3..dcc20a1e85 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index cae4cfc921..2c83a65b80 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index 6b35eed98c..a95cc4dbaa 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index f3effef5c1..a5210e2390 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_nopbc.py b/source/lmp/tests/test_lammps_spin_nopbc.py index d6cdaf5a9f..309d1591cc 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc.py +++ b/source/lmp/tests/test_lammps_spin_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" @@ -212,6 +211,7 @@ ) type_NiO = np.array([1, 1, 2, 2]) + def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( diff --git a/source/lmp/tests/test_lammps_spin_nopbc_pt.py b/source/lmp/tests/test_lammps_spin_nopbc_pt.py index d6e7eb6aaa..86d74f68c4 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc_pt.py +++ b/source/lmp/tests/test_lammps_spin_nopbc_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index f29d01674a..ff9fc6ecb8 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" From 9826b61e1f87b544fcf4044e24879ddbcd097267 Mon Sep 17 00:00:00 2001 From: "njzjz-bot (driven by OpenClaw (model: gpt-5.4))[bot]" <48687836+njzjz-bot@users.noreply.github.com> Date: Sat, 18 Apr 2026 17:48:40 +0000 Subject: [PATCH 7/8] test(lmp): address remaining review nits on conversion guards Tighten stale-lock handling so a live PID wins over mtime expiry, silence the targeted subprocess security lint for the test-controlled conversion command, and skip the DPA select MPI model-deviation test when TensorFlow is disabled. Authored by OpenClaw (model: gpt-5.4) --- source/lmp/tests/model_convert.py | 21 ++++++++----------- source/lmp/tests/test_deeptensor.py | 7 ++++--- source/lmp/tests/test_dplr.py | 7 ++++--- source/lmp/tests/test_lammps.py | 9 ++++---- source/lmp/tests/test_lammps_3types.py | 8 +++---- source/lmp/tests/test_lammps_dpa_jax.py | 9 ++++---- source/lmp/tests/test_lammps_dpa_pt.py | 9 ++++---- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 9 ++++---- source/lmp/tests/test_lammps_dpa_sel_pt.py | 13 ++++++++---- source/lmp/tests/test_lammps_faparam.py | 7 ++++--- source/lmp/tests/test_lammps_jax.py | 9 ++++---- source/lmp/tests/test_lammps_pd.py | 9 ++++---- source/lmp/tests/test_lammps_pt.py | 9 ++++---- source/lmp/tests/test_lammps_spin.py | 9 ++++---- source/lmp/tests/test_lammps_spin_nopbc.py | 10 ++++----- source/lmp/tests/test_lammps_spin_nopbc_pt.py | 9 ++++---- source/lmp/tests/test_lammps_spin_pt.py | 9 ++++---- 17 files changed, 89 insertions(+), 74 deletions(-) diff --git a/source/lmp/tests/model_convert.py b/source/lmp/tests/model_convert.py index 1d735b1899..a13ff3b458 100644 --- a/source/lmp/tests/model_convert.py +++ b/source/lmp/tests/model_convert.py @@ -1,9 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Helpers for preparing converted TensorFlow graph files in LAMMPS tests.""" -from __future__ import ( - annotations, -) +from __future__ import annotations import errno import os @@ -11,9 +9,7 @@ import sys import tempfile import time -from pathlib import ( - Path, -) +from pathlib import Path _LOCK_TIMEOUT_SECONDS = 60.0 _LOCK_POLL_SECONDS = 0.1 @@ -53,12 +49,12 @@ def _should_break_stale_lock(lock_file: Path) -> bool: except FileNotFoundError: return False - lock_age = time.time() - lock_stat.st_mtime - if lock_age > _LOCK_TIMEOUT_SECONDS: - return True - lock_pid = _read_lock_pid(lock_file) - return lock_pid is not None and not _pid_is_running(lock_pid) + if lock_pid is not None: + return not _pid_is_running(lock_pid) + + lock_age = time.time() - lock_stat.st_mtime + return lock_age > _LOCK_TIMEOUT_SECONDS def ensure_converted_pb(source: Path, output: Path) -> Path: @@ -68,6 +64,7 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: repeated imports across multiple test modules do not regenerate the same model more than once. """ + source = source.resolve() output = output.resolve() output.parent.mkdir(parents=True, exist_ok=True) @@ -103,7 +100,7 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: ) os.close(tmp_fd) tmp_path = Path(tmp_name) - sp.run( + sp.run( # noqa: S603 [ sys.executable, "-m", diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index c0f9a2d7f7..0b7fb4905e 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -10,13 +10,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent / "graph.pb" pbtxt_file2 = ( diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index defdff21c0..9cce58c80e 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -10,13 +10,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_full, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent / "lrmodel.pbtxt" pb_file = Path(__file__).parent / "lrmodel.pb" dipole_pbtxt_file = Path(__file__).parent / "lrdipole.pbtxt" diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index eca782365e..ad5ac91fd4 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index a3cef29a62..9267c7bfd4 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -9,13 +9,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" @@ -245,7 +246,6 @@ # https://github.com/lammps/lammps/blob/1e1311cf401c5fc2614b5d6d0ff3230642b76597/src/update.cpp#L193 nktv2p = 1.6021765e6 - def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index d4d63dd340..7d21170ea9 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index 2c93096556..db5a4c7cad 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index 0edd3ed089..a88c14963e 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot_dpa.pth" pb_file2 = Path(__file__).parent / "graph.pb" diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index 685e7260e1..2f2030d98e 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) @@ -722,6 +723,10 @@ def test_pair_deepmd_si(lammps_si) -> None: ("balance_args",), [(["--balance"],), ([],)], ) +@pytest.mark.skipif( + os.environ.get("ENABLE_TENSORFLOW", "1") != "1", + reason="Skip test because TensorFlow support is not enabled.", +) def test_pair_deepmd_mpi(balance_args: list) -> None: with tempfile.NamedTemporaryFile() as f: sp.check_call( diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index c40fb9bdb0..c5a8238771 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -12,13 +12,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "fparam_aparam.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index dcc20a1e85..ae588306d3 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index 2c83a65b80..cae4cfc921 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index a95cc4dbaa..6b35eed98c 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index a5210e2390..f3effef5c1 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_spin_nopbc.py b/source/lmp/tests/test_lammps_spin_nopbc.py index 309d1591cc..d6cdaf5a9f 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc.py +++ b/source/lmp/tests/test_lammps_spin_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -14,13 +14,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" ) @@ -211,7 +212,6 @@ ) type_NiO = np.array([1, 1, 2, 2]) - def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( diff --git a/source/lmp/tests/test_lammps_spin_nopbc_pt.py b/source/lmp/tests/test_lammps_spin_nopbc_pt.py index 86d74f68c4..d6e7eb6aaa 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc_pt.py +++ b/source/lmp/tests/test_lammps_spin_nopbc_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -14,13 +14,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" ) diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index ff9fc6ecb8..f29d01674a 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import shutil import subprocess as sp +import shutil import sys import tempfile from pathlib import ( @@ -15,13 +15,14 @@ from lammps import ( PyLammps, ) -from model_convert import ( - ensure_converted_pb, -) from write_lmp_data import ( write_lmp_data_spin, ) +from model_convert import ( + ensure_converted_pb, +) + pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" ) From c416849c20659113e7d3faea9d1a9363c94efb23 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 17:49:19 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/tests/model_convert.py | 11 +++++++---- source/lmp/tests/test_deeptensor.py | 7 +++---- source/lmp/tests/test_dplr.py | 7 +++---- source/lmp/tests/test_lammps.py | 9 ++++----- source/lmp/tests/test_lammps_3types.py | 8 ++++---- source/lmp/tests/test_lammps_dpa_jax.py | 9 ++++----- source/lmp/tests/test_lammps_dpa_pt.py | 9 ++++----- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 9 ++++----- source/lmp/tests/test_lammps_dpa_sel_pt.py | 9 ++++----- source/lmp/tests/test_lammps_faparam.py | 7 +++---- source/lmp/tests/test_lammps_jax.py | 9 ++++----- source/lmp/tests/test_lammps_pd.py | 9 ++++----- source/lmp/tests/test_lammps_pt.py | 9 ++++----- source/lmp/tests/test_lammps_spin.py | 9 ++++----- source/lmp/tests/test_lammps_spin_nopbc.py | 10 +++++----- source/lmp/tests/test_lammps_spin_nopbc_pt.py | 9 ++++----- source/lmp/tests/test_lammps_spin_pt.py | 9 ++++----- 17 files changed, 69 insertions(+), 80 deletions(-) diff --git a/source/lmp/tests/model_convert.py b/source/lmp/tests/model_convert.py index a13ff3b458..18047f3707 100644 --- a/source/lmp/tests/model_convert.py +++ b/source/lmp/tests/model_convert.py @@ -1,7 +1,9 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Helpers for preparing converted TensorFlow graph files in LAMMPS tests.""" -from __future__ import annotations +from __future__ import ( + annotations, +) import errno import os @@ -9,7 +11,9 @@ import sys import tempfile import time -from pathlib import Path +from pathlib import ( + Path, +) _LOCK_TIMEOUT_SECONDS = 60.0 _LOCK_POLL_SECONDS = 0.1 @@ -64,7 +68,6 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: repeated imports across multiple test modules do not regenerate the same model more than once. """ - source = source.resolve() output = output.resolve() output.parent.mkdir(parents=True, exist_ok=True) @@ -100,7 +103,7 @@ def ensure_converted_pb(source: Path, output: Path) -> Path: ) os.close(tmp_fd) tmp_path = Path(tmp_name) - sp.run( # noqa: S603 + sp.run( [ sys.executable, "-m", diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 0b7fb4905e..c0f9a2d7f7 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -10,13 +10,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent / "graph.pb" diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index 9cce58c80e..defdff21c0 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -10,13 +10,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_full, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_full, +) pbtxt_file = Path(__file__).parent / "lrmodel.pbtxt" pb_file = Path(__file__).parent / "lrmodel.pb" diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index ad5ac91fd4..eca782365e 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index 9267c7bfd4..a3cef29a62 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -9,13 +9,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( @@ -246,6 +245,7 @@ # https://github.com/lammps/lammps/blob/1e1311cf401c5fc2614b5d6d0ff3230642b76597/src/update.cpp#L193 nktv2p = 1.6021765e6 + def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index 7d21170ea9..d4d63dd340 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index db5a4c7cad..2c93096556 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index a88c14963e..0edd3ed089 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot_dpa.pth" diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index 2f2030d98e..27baee3432 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index c5a8238771..c40fb9bdb0 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -12,13 +12,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "fparam_aparam.pbtxt" diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index ae588306d3..dcc20a1e85 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index cae4cfc921..2c83a65b80 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index 6b35eed98c..a95cc4dbaa 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot-1.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index f3effef5c1..a5210e2390 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_nopbc.py b/source/lmp/tests/test_lammps_spin_nopbc.py index d6cdaf5a9f..309d1591cc 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc.py +++ b/source/lmp/tests/test_lammps_spin_nopbc.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist.pbtxt" @@ -212,6 +211,7 @@ ) type_NiO = np.array([1, 1, 2, 2]) + def setup_module() -> None: if os.environ.get("ENABLE_TENSORFLOW", "1") != "1": pytest.skip( diff --git a/source/lmp/tests/test_lammps_spin_nopbc_pt.py b/source/lmp/tests/test_lammps_spin_nopbc_pt.py index d6e7eb6aaa..86d74f68c4 100644 --- a/source/lmp/tests/test_lammps_spin_nopbc_pt.py +++ b/source/lmp/tests/test_lammps_spin_nopbc_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -14,13 +14,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt" diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index f29d01674a..ff9fc6ecb8 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import importlib import os -import subprocess as sp import shutil +import subprocess as sp import sys import tempfile from pathlib import ( @@ -15,13 +15,12 @@ from lammps import ( PyLammps, ) -from write_lmp_data import ( - write_lmp_data_spin, -) - from model_convert import ( ensure_converted_pb, ) +from write_lmp_data import ( + write_lmp_data_spin, +) pbtxt_file2 = ( Path(__file__).parent.parent.parent / "tests" / "infer" / "deepspin_nlist-2.pbtxt"