Skip to content

Commit ac7ab7f

Browse files
committed
renamed make_task_spec to make_task_def
1 parent 1e81774 commit ac7ab7f

File tree

13 files changed

+59
-31
lines changed

13 files changed

+59
-31
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
"from fileformats.medimage import Nifti\n",
6565
"from pydra.engine.submitter import Submitter\n",
6666
"from pydra.tasks.mrtrix3.v3_0 import MrGrid\n",
67+
"import nest_asyncio\n",
68+
"\n",
69+
"# Allow running async code in Jupyter notebooks\n",
70+
"nest_asyncio.apply()\n",
6771
"\n",
6872
"# Make directory filled with nifti files\n",
6973
"test_dir = Path(tempfile.mkdtemp())\n",

new-docs/source/tutorial/canonical-form.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Canonical (dataclass) task form\n",
7+
"# Canonical task form\n",
88
"\n",
99
"Under the hood, all Python, shell and workflow task definitions generated by the\n",
1010
"`pydra.design.*.define` decorators/functions are translated to\n",

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
"from pathlib import Path\n",
3939
"from tempfile import mkdtemp\n",
4040
"import json\n",
41+
"import nest_asyncio\n",
42+
"\n",
43+
"# Allow running async code in Jupyter notebooks\n",
44+
"nest_asyncio.apply()\n",
4145
"\n",
4246
"JSON_CONTENTS = {'a': True, 'b': 'two', 'c': 3, 'd': [7, 0.55, 6]}\n",
4347
"\n",
@@ -57,9 +61,17 @@
5761
},
5862
{
5963
"cell_type": "code",
60-
"execution_count": 7,
64+
"execution_count": 2,
6165
"metadata": {},
62-
"outputs": [],
66+
"outputs": [
67+
{
68+
"name": "stderr",
69+
"output_type": "stream",
70+
"text": [
71+
"A newer version (0.25) of nipype/pydra is available. You are using 0.25.dev128+g1e817743.d20250104\n"
72+
]
73+
}
74+
],
6375
"source": [
6476
"# Import the task definition\n",
6577
"from pydra.tasks.common import LoadJson\n",
@@ -83,13 +95,13 @@
8395
},
8496
{
8597
"cell_type": "code",
86-
"execution_count": null,
98+
"execution_count": 3,
8799
"metadata": {},
88100
"outputs": [],
89101
"source": [
90102
"from pydra.engine.submitter import Submitter\n",
91103
"\n",
92-
"with Submitter(plugin='cf', n_procs=1) as submitter:\n",
104+
"with Submitter(plugin='serial', n_procs=1) as submitter:\n",
93105
" result = submitter(load_json)"
94106
]
95107
},
@@ -119,7 +131,7 @@
119131
},
120132
{
121133
"cell_type": "code",
122-
"execution_count": null,
134+
"execution_count": 4,
123135
"metadata": {},
124136
"outputs": [],
125137
"source": [
@@ -142,14 +154,26 @@
142154
},
143155
{
144156
"cell_type": "code",
145-
"execution_count": null,
157+
"execution_count": 5,
146158
"metadata": {},
147-
"outputs": [],
159+
"outputs": [
160+
{
161+
"ename": "AttributeError",
162+
"evalue": "'MrGrid' object has no attribute 'split'",
163+
"output_type": "error",
164+
"traceback": [
165+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
166+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
167+
"Cell \u001b[0;32mIn[5], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpydra\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtasks\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmrtrix3\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mv3_0\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m MrGrid\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m# Instantiate the task definition, \"splitting\" over all NIfTI files in the test directory\u001b[39;00m\n\u001b[0;32m----> 4\u001b[0m mrgrid \u001b[38;5;241m=\u001b[39m \u001b[43mMrGrid\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvoxel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m0.5\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m0.5\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m0.5\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msplit\u001b[49m(\u001b[38;5;28minput\u001b[39m\u001b[38;5;241m=\u001b[39mnifti_dir\u001b[38;5;241m.\u001b[39miterdir())\n\u001b[1;32m 6\u001b[0m \u001b[38;5;66;03m# Run the task to resample all NIfTI files\u001b[39;00m\n\u001b[1;32m 7\u001b[0m outputs \u001b[38;5;241m=\u001b[39m mrgrid()\n",
168+
"\u001b[0;31mAttributeError\u001b[0m: 'MrGrid' object has no attribute 'split'"
169+
]
170+
}
171+
],
148172
"source": [
149173
"from pydra.tasks.mrtrix3.v3_0 import MrGrid\n",
150174
"\n",
151175
"# Instantiate the task definition, \"splitting\" over all NIfTI files in the test directory\n",
152-
"mrgrid = MrGrid(voxel=0.5).split(input=nifti_dir.iterdir())\n",
176+
"mrgrid = MrGrid(voxel=(0.5,0.5,0.5)).split(input=nifti_dir.iterdir())\n",
153177
"\n",
154178
"# Run the task to resample all NIfTI files\n",
155179
"outputs = mrgrid()\n",

new-docs/source/tutorial/workflow.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@
414414
],
415415
"metadata": {
416416
"kernelspec": {
417-
"display_name": "Python 3 (ipykernel)",
417+
"display_name": "wf12",
418418
"language": "python",
419419
"name": "python3"
420420
},

pydra/design/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"Arg",
3535
"Out",
3636
"ensure_field_objects",
37-
"make_task_spec",
37+
"make_task_def",
3838
]
3939

4040

@@ -349,7 +349,7 @@ def get_fields(klass, field_type, auto_attribs, helps) -> dict[str, Field]:
349349
return inputs, outputs
350350

351351

352-
def make_task_spec(
352+
def make_task_def(
353353
spec_type: type["TaskDef"],
354354
out_type: type["TaskOutputs"],
355355
task_type: type["Task"],
@@ -724,6 +724,8 @@ def allowed_values_validator(_, attribute, value):
724724
allowed = attribute.metadata[PYDRA_ATTR_METADATA].allowed_values
725725
if value is attrs.NOTHING or is_lazy(value):
726726
pass
727+
elif value is None and is_optional(attribute.type):
728+
pass
727729
elif value not in allowed:
728730
raise ValueError(
729731
f"value of {attribute.name} has to be from {allowed}, but {value} provided"

pydra/design/boutiques.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from fileformats.generic import File
88
from pydra.engine.specs import ShellDef
99
from pydra.engine.task import BoshTask
10-
from .base import make_task_spec
10+
from .base import make_task_def
1111
from . import shell
1212

1313

@@ -113,7 +113,7 @@ def define(
113113
outputs = _prepare_output_spec(
114114
bosh_spec, input_keys, names_subset=output_spec_names
115115
)
116-
return make_task_spec(
116+
return make_task_def(
117117
spec_type=ShellDef,
118118
task_type=BoshTask,
119119
out_type=out,

pydra/design/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Arg,
77
Out,
88
ensure_field_objects,
9-
make_task_spec,
9+
make_task_def,
1010
parse_doc_string,
1111
extract_function_inputs_and_outputs,
1212
check_explicit_fields_are_none,
@@ -159,7 +159,7 @@ def make(wrapped: ty.Callable | type) -> PythonDef:
159159
name="function", type=ty.Callable, default=function
160160
)
161161

162-
interface = make_task_spec(
162+
interface = make_task_def(
163163
PythonDef,
164164
PythonOutputs,
165165
PythonTask,

pydra/design/shell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
check_explicit_fields_are_none,
2020
extract_fields_from_class,
2121
ensure_field_objects,
22-
make_task_spec,
22+
make_task_def,
2323
EMPTY,
2424
)
2525
from pydra.utils.typing import is_fileset_or_union, MultiInputObj
@@ -373,7 +373,7 @@ def make(
373373
if inpt.position is None:
374374
inpt.position = position_stack.pop(0)
375375

376-
interface = make_task_spec(
376+
interface = make_task_def(
377377
ShellDef,
378378
ShellOutputs,
379379
ShellTask,

pydra/design/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Arg,
77
Out,
88
ensure_field_objects,
9-
make_task_spec,
9+
make_task_def,
1010
parse_doc_string,
1111
extract_function_inputs_and_outputs,
1212
check_explicit_fields_are_none,
@@ -171,7 +171,7 @@ def make(wrapped: ty.Callable | type) -> TaskDef:
171171
for inpt_name in lazy:
172172
parsed_inputs[inpt_name].lazy = True
173173

174-
interface = make_task_spec(
174+
interface = make_task_def(
175175
WorkflowDef,
176176
WorkflowOutputs,
177177
WorkflowTask,

pydra/engine/submitter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ def __init__(self, plugin: ty.Union[str, ty.Type[Worker]] = "cf", **kwargs):
5050

5151
def __call__(self, runnable, cache_locations=None, rerun=False, environment=None):
5252
"""Submitter run function."""
53+
from pydra.engine.core import TaskDef
54+
5355
if cache_locations is not None:
5456
runnable.cache_locations = cache_locations
57+
if isinstance(runnable, TaskDef):
58+
runnable = runnable.Task(
59+
runnable,
60+
cache_locations=cache_locations,
61+
)
5562
self.loop.run_until_complete(
5663
self.submit_from_call(runnable, rerun, environment)
5764
)

0 commit comments

Comments
 (0)