Skip to content

Commit e7926ec

Browse files
authored
Merge pull request #847 from nipype/lazy-val-setting-bugfix
Set provided non-lazy input vals when constructing workflows, if they are not set in the cached workflow
2 parents 59bd130 + 47cf3b0 commit e7926ec

File tree

8 files changed

+29
-18
lines changed

8 files changed

+29
-18
lines changed

docs/source/explanation/conditional-lazy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Lazy fields
1313

1414
Pydra workflows are constructed by the assignment of "lazy field" placeholders from
1515
the outputs of upstream nodes to the inputs of downstream nodes. These placeholders,
16-
which are instances of the :class:`pydra.engine.specs.LazyField` class, are replaced
16+
which are instances of the :class:`pydra.engine.lazy.LazyField` class, are replaced
1717
by the actual values they represent when the workflow is run.
1818

1919

docs/source/reference/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ Workflows
2525
:undoc-members:
2626
:show-inheritance:
2727

28-
Specification classes
29-
---------------------
28+
Engine classes
29+
--------------
3030

31-
.. automodule:: pydra.engine.specs
31+
.. automodule:: pydra.engine
3232
:members:
3333
:undoc-members:
3434
:show-inheritance:

docs/source/tutorial/1-getting-started.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
"metadata": {},
152152
"outputs": [],
153153
"source": [
154-
"from pydra.tasks.mrtrix3.v3_0 import MrGrid\n",
154+
"from pydra.tasks.mrtrix3.v3_1 import MrGrid\n",
155155
"\n",
156156
"# Instantiate the task, \"splitting\" over all NIfTI files in the test directory\n",
157157
"# by splitting the \"input\" input field over all files in the directory\n",
@@ -236,7 +236,7 @@
236236
"metadata": {},
237237
"outputs": [],
238238
"source": [
239-
"from pydra.tasks.mrtrix3.v3_0 import MrGrid\n",
239+
"from pydra.tasks.mrtrix3.v3_1 import MrGrid\n",
240240
"\n",
241241
"if (\n",
242242
" __name__ == \"__main__\"\n",

docs/source/tutorial/2-advanced-execution.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
"from pprint import pprint\n",
192192
"from fileformats.medimage import Nifti1\n",
193193
"from pydra.engine.submitter import Submitter\n",
194-
"from pydra.tasks.mrtrix3.v3_0 import MrGrid\n",
194+
"from pydra.tasks.mrtrix3.v3_1 import MrGrid\n",
195195
"\n",
196196
"# Make a temporary directory\n",
197197
"test_dir = Path(tempfile.mkdtemp())\n",
@@ -323,7 +323,7 @@
323323
"outputs": [],
324324
"source": [
325325
"import tempfile\n",
326-
"from pydra.tasks.mrtrix3.v3_0 import MrGrid\n",
326+
"from pydra.tasks.mrtrix3.v3_1 import MrGrid\n",
327327
"from pydra.environments import docker\n",
328328
"\n",
329329
"test_dir = tempfile.mkdtemp()\n",

docs/source/tutorial/6-workflow.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,10 @@
481481
"from pathlib import Path\n",
482482
"import numpy as np\n",
483483
"from fileformats.medimage import Nifti1\n",
484-
"import fileformats.medimage_mrtrix3 as mrtrix3\n",
484+
"import fileformats.vendor.mrtrix3.medimage as mrtrix3\n",
485485
"from pydra.environments import docker\n",
486486
"from pydra.compose import workflow, python\n",
487-
"from pydra.tasks.mrtrix3.v3_0 import MrConvert, MrThreshold\n",
487+
"from pydra.tasks.mrtrix3.v3_1 import MrConvert, MrThreshold\n",
488488
"\n",
489489
"MRTRIX2NUMPY_DTYPES = {\n",
490490
" \"Int8\": np.dtype(\"i1\"),\n",

pydra/compose/tests/test_workflow_fields.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ def MyTestShellWorkflow(
266266

267267
# check to see that the cache is used if we provide a concrete value for one of the
268268
# lazy fields
269+
wf2.name = "tagged"
269270
workflow_spec.input_video = video.Mp4.mock("input.mp4")
270271
wf3 = Workflow.construct(workflow_spec)
271-
assert wf3 is wf2
272+
assert wf3.name == "tagged"
272273
assert list(workflow_cache) == [key_set]
273274
assert len(workflow_cache[key_set]) == 2
274275

pydra/engine/workflow.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import inspect
33
import typing as ty
4-
from copy import copy
4+
from copy import copy, deepcopy
55
from collections import defaultdict
66
from typing import Self
77
import attrs
@@ -115,7 +115,12 @@ def construct(
115115
}
116116
subset_hash = hash_function(subset_vals, cache=hash_cache)
117117
if subset_hash in key_set_cache:
118-
return key_set_cache[subset_hash]
118+
wf = deepcopy(key_set_cache[subset_hash])
119+
for key in non_lazy_keys - key_set:
120+
# Set any additional non-lazy inputs that were not in the
121+
# cached workflow.
122+
setattr(wf.inputs, key, non_lazy_vals[key])
123+
return wf
119124

120125
# Initialise the outputs of the workflow
121126
outputs = task.Outputs(

pyproject.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ readme = "README.rst"
99
requires-python = ">=3.11"
1010
dependencies = [
1111
"attrs >=24.2.0",
12+
"click >=8.2.0",
1213
"cloudpickle >=3.0.0",
1314
"etelemetry >=0.3.1",
1415
"filelock >=3.0.0",
@@ -39,9 +40,11 @@ dynamic = ["version"]
3940
[project.optional-dependencies]
4041
dev = ["black", "pre-commit", "pydra[test]", "matplotlib"]
4142
doc = [
42-
"fileformats-extras >= v0.15.0a6",
43+
"fileformats-extras[application,image] >= v0.15.0a6",
4344
"fileformats-medimage >= v0.10.0a2",
4445
"fileformats-medimage-extras >= v0.10.0a2",
46+
"fileformats-vendor-mrtrix3 >=3.1.0a5",
47+
"fileformats-vendor-mrtrix3-extras >=3.1.0a5",
4548
"furo>=2022.2.14.1",
4649
"ipython",
4750
"ipykernel",
@@ -57,7 +60,7 @@ doc = [
5760
"packaging",
5861
"pandas",
5962
"pandoc",
60-
"pydra-tasks-mrtrix3 >=3.1.0a1",
63+
"pydra-tasks-mrtrix3 >=3.1.0a5",
6164
"scipy",
6265
"sphinx",
6366
"sphinx-argparse",
@@ -75,17 +78,19 @@ test = [
7578
"pytest-rerunfailures >=15.0",
7679
"pytest-timeout >=2.3",
7780
"pympler >=1.1",
78-
"fileformats-extras >=0.15.0a7",
81+
"fileformats-extras[application,image] >=0.15.0a7",
7982
"numpy >=1.26",
8083
"pyld >=2.0",
8184
"psutil >=5.9.0",
8285
"python-dateutil >=2.8.2",
8386
"tornado >=6.1",
8487
]
8588
tutorial = [
86-
"fileformats-extras >= v0.15.0a6",
89+
"fileformats-extras[application,image] >= v0.15.0a6",
8790
"fileformats-medimage >= v0.10.0a2",
8891
"fileformats-medimage-extras >= v0.10.0a2",
92+
"fileformats-vendor-mrtrix3 >=3.1.0a5",
93+
"fileformats-vendor-mrtrix3-extras >=3.1.0a5",
8994
"jupyter",
9095
"jupyter_contrib_nbextensions",
9196
"jupytext",
@@ -100,7 +105,7 @@ tutorial = [
100105
"openneuro-py",
101106
"pandas",
102107
"psutil",
103-
"pydra-tasks-mrtrix3 >=3.1.0a1",
108+
"pydra-tasks-mrtrix3 >=3.1.0a5",
104109
"scipy",
105110
"sh",
106111
]

0 commit comments

Comments
 (0)