-
Notifications
You must be signed in to change notification settings - Fork 612
test(lmp): avoid duplicate pb conversions in tests #5400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wanghan-iapcm
merged 11 commits into
deepmodeling:master
from
njzjz-bot:fix/lmp-tests-avoid-duplicate-pb-convert
Apr 24, 2026
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5d591e3
test(lmp): avoid duplicate pb conversions in tests
njzjz-bot 76fb1b9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5756071
test(lmp): fix pre-commit fallout in conversion cache changes
njzjz-bot 549eda6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 06769a1
test(lmp): defer conversions until runtime guards pass
njzjz-bot 58d2142
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9826b61
test(lmp): address remaining review nits on conversion guards
njzjz-bot c416849
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 76a5f25
test(lmp): add focused coverage for model conversion helper
njzjz-bot 869c096
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fd07220
test(lmp): make stale-lock PID test deterministic
njzjz-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # 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}") | ||
|
njzjz-bot marked this conversation as resolved.
Outdated
|
||
| time.sleep(_LOCK_POLL_SECONDS) | ||
|
njzjz-bot marked this conversation as resolved.
|
||
| continue | ||
| break | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| 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), | ||
| ] | ||
| ) | ||
|
njzjz-bot marked this conversation as resolved.
Outdated
coderabbitai[bot] marked this conversation as resolved.
|
||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.