forked from mdekauwe/CABLE_benchmarking
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Log status of fluxsite and comparison runs #291
Merged
SeanBryan51
merged 2 commits into
main
from
180-log-run-summary-of-tasks-to-standard-output
Jul 10, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains 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 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 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 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 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,51 @@ | ||
from pathlib import Path | ||
|
||
from benchcab.internal import STATE_PREFIX | ||
|
||
|
||
class StateAttributeError(Exception): | ||
"""Exception class for signalling state attribute errors.""" | ||
|
||
|
||
class State: | ||
"""Stores state which persists on the file system.""" | ||
|
||
def __init__(self, state_dir: Path) -> None: | ||
"""Instantiate a State object. | ||
|
||
Parameters | ||
---------- | ||
state_dir: Path | ||
Path to the directory in which state is stored. If the specified | ||
directory does not exist, create the directory. | ||
|
||
""" | ||
self.state_dir = state_dir | ||
self.state_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
def reset(self): | ||
"""Clear all state attributes.""" | ||
for path in self.state_dir.glob(f"{STATE_PREFIX}*"): | ||
path.unlink() | ||
|
||
def set(self, attr: str): | ||
"""Set state attribute.""" | ||
(self.state_dir / (STATE_PREFIX + attr)).touch() | ||
|
||
def is_set(self, attr: str): | ||
"""Return True if the state attribute has been set, False otherwise.""" | ||
return (self.state_dir / (STATE_PREFIX + attr)).exists() | ||
|
||
def get(self) -> str: | ||
"""Get the state of the most recent state attribute.""" | ||
attrs = list(self.state_dir.glob(f"{STATE_PREFIX}*")) | ||
|
||
def get_mtime(path: Path): | ||
return path.stat().st_mtime | ||
|
||
attrs.sort(key=get_mtime) | ||
try: | ||
return attrs.pop().name.removeprefix(STATE_PREFIX) | ||
except IndexError as exc: | ||
msg = "No attributes have been set." | ||
raise StateAttributeError(msg) from exc |
This file contains 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 | ||
---|---|---|---|---|
|
@@ -24,6 +24,9 @@ def clean_submission_files(): | |||
if internal.RUN_DIR.exists(): | ||||
shutil.rmtree(internal.RUN_DIR) | ||||
|
||||
if internal.STATE_DIR.exists(): | ||||
shutil.rmtree(internal.STATE_DIR) | ||||
bschroeter marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems my previous comment about cleanup wasn't clear. I was talking about updating this test: benchcab/tests/test_workdir.py Line 136 in fc625c0
To check that the STATE_DIR is removed. |
||||
for pbs_job_file in Path.cwd().glob(f"{internal.QSUB_FNAME}*"): | ||||
pbs_job_file.unlink() | ||||
|
||||
|
This file contains 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 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 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,39 @@ | ||
import time | ||
from pathlib import Path | ||
|
||
import pytest | ||
from benchcab.utils.state import State, StateAttributeError | ||
|
||
|
||
@pytest.fixture() | ||
def state(): | ||
"""Return a State object.""" | ||
return State(state_dir=Path("my_state")) | ||
|
||
|
||
def test_state_is_set(state): | ||
"""Success case: test state is set.""" | ||
state.set("foo") | ||
assert state.is_set("foo") | ||
|
||
|
||
def test_state_reset(state): | ||
"""Success case: test state is reset.""" | ||
state.set("foo") | ||
state.reset() | ||
assert not state.is_set("foo") | ||
|
||
|
||
def test_state_get(state): | ||
"""Success case: test get() returns the most recent state attribute.""" | ||
state.set("foo") | ||
# This is done so that time stamps can be resolved between state attributes | ||
time.sleep(0.01) | ||
state.set("bar") | ||
assert state.get() == "bar" | ||
|
||
|
||
def test_state_get_raises_exception(state): | ||
"""Failure case: test get() raises an exception when no attributes are set.""" | ||
with pytest.raises(StateAttributeError): | ||
state.get() |
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to users if there was a warning level log entry if there were any failed tasks? And some indication either of which tasks failed or how to find out which failed. This is valid for the bitwise comparison as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked that failure cases always output to the PBS log file. Here is the PBS log of a benchcab run with a task that fails due to a malformed namelist file: