8000 Hash change guards by tclose · Pull Request #698 · nipype/pydra · GitHub
[go: up one dir, main page]

Skip to content

Hash change guards #698

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
merged 30 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3a72666
Implemented hash-change guards in TaskBase._run()
tclose Feb 24, 2024
b378f83
added hash guards to workflow execution (i.e. on workflow inputs)
tclose Feb 24, 2024
5aaf62f
reworked error message for blocked upstream tasks to specifiy which t…
tclose Feb 24, 2024
0397a18
touched up messages for hash change errors
tclose Feb 24, 2024
1d77f4b
replaced attrs.evolve with manual setattr of inputs within Task._run(…
tclose Feb 24, 2024
e2d009b
updated explicit hashes in unittests to match new values produced by …
tclose Feb 24, 2024
48d68f5
added a sleep to alter_x to make sure it runs after identity
tclose Feb 24, 2024
1a9eed0
fix up
tclose Feb 24, 2024 < 8000 /div>
d76bb3d
[skip ci] updates comment
tclose Feb 24, 2024
6e1f030
upped sleep
tclose Feb 24, 2024
6717d85
added random in to ensure that alter_x finishes after identity
tclose Feb 24, 2024
1cd9491
added more reruns to test_hash_changes_in_workflow_graph
tclose Feb 24, 2024
7d6849b
fixed bugs in graph hash error test
tclose Feb 24, 2024
df9ecc6
added logging to assist in tracking down hashing issues
tclose Feb 24, 2024
930dfc1
[skip ci] touched up error message
tclose Feb 24, 2024
6128951
added docstring to bytes_repr to retrigger checks
tclose Feb 24, 2024
4ba8da0
updated bytes_repr doc string
tclose Feb 24, 2024
15a775d
removed check for result None in TaskBase._run(). Shouldn't occur now…
tclose Feb 24, 2024
1263f5a
added test to hit unstable hash check branch
tclose Feb 24, 2024
b54166e
expanded hash graph error message to include final values/hashes of p…
tclose Feb 24, 2024
048c0a1
More touch ups to error messages
tclose Feb 24, 2024
c282d3e
Update pydra/engine/tests/test_submitter.py
tclose Feb 24, 2024
509afc7
Update pydra/engine/tests/test_submitter.py
tclose Feb 24, 2024
6e91065
reworked hash change detection error messages
tclose Feb 24, 2024
9896735
modified modified inputs so it returns the actual original inputs not…
tclose Feb 24, 2024
e660351
changed deepcopy to copy in checksum_states (not sure whether this is…
tclose Feb 24, 2024
8a5541c
changed test_hash_changes unittest so it works with python 3.8
tclose Feb 24, 2024
4e1d4a8
changed _graph_checksums to a dict instead of a list
tclose Feb 24, 2024
b94f185
Merge branch 'master' into hash-change-guards
tclose Mar 2, 2024
ff281aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added hash guards to workflow execution (i.e. on workflow inputs)
  • Loading branch information
tclose committed Feb 24, 2024
commit b378f83105aedbc45fd1cd47c3dd081d4b1dce49
9 changes: 9 additions & 0 deletions pydra/engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,15 @@ async def _run(self, submitter=None, rerun=False, **kwargs):
(self.cache_dir / f"{self.uid}_info.json").unlink()
os.chdir(cwd)
self.hooks.post_run(self, result)
# Check for any changes to the input hashes that have occurred during the execution
# of the task
hash_changes = self.inputs.hash_changes()
if hash_changes:
raise RuntimeError(
f"Hashes have changed for {hash_changes} input fields during the "
f"execution of {self} workflow. Please check all output files/directories are "
"typed with `pathlib.Path` instead of `fileformats` classes"
)
if result is None:
raise Exception("This should never happen, please open new issue")
return result
Expand Down
33 changes: 31 additions & 2 deletions pydra/engine/tests/test_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import re
import subprocess as sp
import time

import pytest

from fileformats.generic import Directory
from .utils import (
need_sge,
need_slurm,
Expand Down Expand Up @@ -612,3 +611,33 @@ def alter_input(x):
@mark.task
def to_tuple(x, y):
return (x, y)


# @pytest.mark.xfail(reason="Not sure")
def test_hash_changes(tmp_path):
task = output_dir_as_input(out_dir=tmp_path)
with pytest.raises(RuntimeError, match="Hashes have changed"):
task()


# @pytest.mark.xfail(reason="Not sure")
def test_hash_changes_workflow(tmp_path):
wf = Workflow(
name="test_hash_change", input_spec={"in_dir": Directory}, in_dir=tmp_path
)
wf.add(output_dir_as_output(out_dir=wf.lzin.in_dir, name="task"))
wf.set_output(("out_dir", wf.task.lzout.out))
with pytest.raises(RuntimeError, match="Hashes have changed.*workflow\."):
wf()


@mark.task
def output_dir_as_output(out_dir: Path) -> Directory:
(out_dir / "new-file.txt").touch()
return out_dir


@mark.task
def output_dir_as_input(out_dir: Directory) -> Directory:
(out_dir.fspath / "new-file.txt").touch()
return out_dir
14 changes: 0 additions & 14 deletions pydra/engine/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
import json
import glob as glob
from fileformats.generic import Directory
from ... import mark
from ..core import Workflow
from ..task import AuditFlag, ShellCommandTask
Expand Down Expand Up @@ -1583,16 +1582,3 @@ def testfunc(a: A):

result = testfunc(a=A(x=7))()
assert result.output.out == 7


@mark.task
def output_dir_as_input(out_dir: Directory) -> Directory:
(out_dir.fspath / "new-file.txt").touch()
return out_dir


# @pytest.mark.xfail(reason="Not sure")
def test_hash_changes(tmp_path):
task = output_dir_as_input(out_dir=tmp_path)
with pytest.raises(RuntimeError, match="Hashes have changed"):
task()
0