Skip to content

Commit 8afc2e5

Browse files
authored
Merge pull request #849 from nipype/lzin-passthrough
added test for lzin passthrough in workflows
2 parents e7926ec + 927e958 commit 8afc2e5

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

pydra/compose/tests/test_workflow_run.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import typing as ty
77
import attr
88
from pathlib import Path
9+
from fileformats.generic import File
910
from pydra.engine.tests.utils import (
1011
Add2,
1112
Add2Wait,
@@ -4606,3 +4607,18 @@ def Worky(x: int, y: ty.List[int]):
46064607
outputs = Worky(x=10, y=[1, 2, 3, 4])(cache_root=tmp_path)
46074608
assert outputs.sum == 100
46084609
assert outputs.products == [10, 20, 30, 40]
4610+
4611+
4612+
def test_wf_lzin_passthrough(tmp_path: Path) -> None:
4613+
@workflow.define
4614+
def IdentityWorkflow(x: int) -> int:
4615+
return x
4616+
4617+
@workflow.define
4618+
def OuterWorkflow(x: int) -> int:
4619+
ident = workflow.add(IdentityWorkflow(x=x))
4620+
add2 = workflow.add(Add2(x=ident.out))
4621+
return add2.out
4622+
4623+
wf = OuterWorkflow(x=1)
4624+
assert wf(cache_root=tmp_path).out == 3

pydra/compose/workflow.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
extract_fields_from_class,
1313
)
1414
from pydra.utils.general import attrs_values
15-
from pydra.utils.typing import StateArray
15+
from pydra.utils.typing import StateArray, is_lazy
1616

1717
if ty.TYPE_CHECKING:
1818
from pydra.engine.workflow import Workflow
@@ -334,7 +334,10 @@ def _from_job(cls, job: "Job[WorkflowTask]") -> ty.Self:
334334
values = {}
335335
lazy_field: LazyOutField
336336
for name, lazy_field in attrs_values(workflow.outputs).items():
337-
val_out = lazy_field._get_value(workflow=workflow, graph=exec_graph)
337+
if is_lazy(lazy_field):
338+
val_out = lazy_field._get_value(workflow=workflow, graph=exec_graph)
339+
else:
340+
val_out = lazy_field # handle non-lazy inputs that are passed through
338341
if isinstance(val_out, StateArray):
339342
val_out = list(val_out) # implicitly combine state arrays
340343
values[name] = val_out

pydra/engine/workflow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def construct(
187187
)
188188
for outpt, outpt_lf in zip(output_fields, output_lazy_fields):
189189
# Automatically combine any uncombined state arrays into a single lists
190-
outpt_lf._type = State.combine_state_arrays(outpt_lf._type)
190+
if isinstance(outpt_lf, LazyOutField):
191+
outpt_lf._type = State.combine_state_arrays(outpt_lf._type)
191192
setattr(outputs, outpt.name, outpt_lf)
192193
else:
193194
if unset_outputs := [

0 commit comments

Comments
 (0)