Skip to content

Commit

Permalink
renamed make_task_spec to make_task_def
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Jan 4, 2025
1 parent 1e81774 commit ac7ab7f
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 31 deletions.
4 changes: 4 additions & 0 deletions new-docs/source/tutorial/advanced-execution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
"from fileformats.medimage import Nifti\n",
"from pydra.engine.submitter import Submitter\n",
"from pydra.tasks.mrtrix3.v3_0 import MrGrid\n",
"import nest_asyncio\n",
"\n",
"# Allow running async code in Jupyter notebooks\n",
"nest_asyncio.apply()\n",
"\n",
"# Make directory filled with nifti files\n",
"test_dir = Path(tempfile.mkdtemp())\n",
Expand Down
2 changes: 1 addition & 1 deletion new-docs/source/tutorial/canonical-form.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Canonical (dataclass) task form\n",
"# Canonical task form\n",
"\n",
"Under the hood, all Python, shell and workflow task definitions generated by the\n",
"`pydra.design.*.define` decorators/functions are translated to\n",
Expand Down
40 changes: 32 additions & 8 deletions new-docs/source/tutorial/getting-started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"from pathlib import Path\n",
"from tempfile import mkdtemp\n",
"import json\n",
"import nest_asyncio\n",
"\n",
"# Allow running async code in Jupyter notebooks\n",
"nest_asyncio.apply()\n",
"\n",
"JSON_CONTENTS = {'a': True, 'b': 'two', 'c': 3, 'd': [7, 0.55, 6]}\n",
"\n",
Expand All @@ -57,9 +61,17 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"A newer version (0.25) of nipype/pydra is available. You are using 0.25.dev128+g1e817743.d20250104\n"
]
}
],
"source": [
"# Import the task definition\n",
"from pydra.tasks.common import LoadJson\n",
Expand All @@ -83,13 +95,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from pydra.engine.submitter import Submitter\n",
"\n",
"with Submitter(plugin='cf', n_procs=1) as submitter:\n",
"with Submitter(plugin='serial', n_procs=1) as submitter:\n",
" result = submitter(load_json)"
]
},
Expand Down Expand Up @@ -119,7 +131,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -142,14 +154,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "AttributeError",
"evalue": "'MrGrid' object has no attribute 'split'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"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",
"\u001b[0;31mAttributeError\u001b[0m: 'MrGrid' object has no attribute 'split'"
]
}
],
"source": [
"from pydra.tasks.mrtrix3.v3_0 import MrGrid\n",
"\n",
"# Instantiate the task definition, \"splitting\" over all NIfTI files in the test directory\n",
"mrgrid = MrGrid(voxel=0.5).split(input=nifti_dir.iterdir())\n",
"mrgrid = MrGrid(voxel=(0.5,0.5,0.5)).split(input=nifti_dir.iterdir())\n",
"\n",
"# Run the task to resample all NIfTI files\n",
"outputs = mrgrid()\n",
Expand Down
2 changes: 1 addition & 1 deletion new-docs/source/tutorial/workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "wf12",
"language": "python",
"name": "python3"
},
Expand Down
6 changes: 4 additions & 2 deletions pydra/design/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"Arg",
"Out",
"ensure_field_objects",
"make_task_spec",
"make_task_def",
]


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


def make_task_spec(
def make_task_def(
spec_type: type["TaskDef"],
out_type: type["TaskOutputs"],
task_type: type["Task"],
Expand Down Expand Up @@ -724,6 +724,8 @@ def allowed_values_validator(_, attribute, value):
allowed = attribute.metadata[PYDRA_ATTR_METADATA].allowed_values
if value is attrs.NOTHING or is_lazy(value):
pass
elif value is None and is_optional(attribute.type):
pass
elif value not in allowed:
raise ValueError(
f"value of {attribute.name} has to be from {allowed}, but {value} provided"
Expand Down
4 changes: 2 additions & 2 deletions pydra/design/boutiques.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fileformats.generic import File
from pydra.engine.specs import ShellDef
from pydra.engine.task import BoshTask
from .base import make_task_spec
from .base import make_task_def
from . import shell


Expand Down Expand Up @@ -113,7 +113,7 @@ def define(
outputs = _prepare_output_spec(
bosh_spec, input_keys, names_subset=output_spec_names
)
return make_task_spec(
return make_task_def(
spec_type=ShellDef,
task_type=BoshTask,
out_type=out,
Expand Down
4 changes: 2 additions & 2 deletions pydra/design/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Arg,
Out,
ensure_field_objects,
make_task_spec,
make_task_def,
parse_doc_string,
extract_function_inputs_and_outputs,
check_explicit_fields_are_none,
Expand Down Expand Up @@ -159,7 +159,7 @@ def make(wrapped: ty.Callable | type) -> PythonDef:
name="function", type=ty.Callable, default=function
)

interface = make_task_spec(
interface = make_task_def(
PythonDef,
PythonOutputs,
PythonTask,
Expand Down
4 changes: 2 additions & 2 deletions pydra/design/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
check_explicit_fields_are_none,
extract_fields_from_class,
ensure_field_objects,
make_task_spec,
make_task_def,
EMPTY,
)
from pydra.utils.typing import is_fileset_or_union, MultiInputObj
Expand Down Expand Up @@ -373,7 +373,7 @@ def make(
if inpt.position is None:
inpt.position = position_stack.pop(0)

interface = make_task_spec(
interface = make_task_def(
ShellDef,
ShellOutputs,
ShellTask,
Expand Down
4 changes: 2 additions & 2 deletions pydra/design/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Arg,
Out,
ensure_field_objects,
make_task_spec,
make_task_def,
parse_doc_string,
extract_function_inputs_and_outputs,
check_explicit_fields_are_none,
Expand Down Expand Up @@ -171,7 +171,7 @@ def make(wrapped: ty.Callable | type) -> TaskDef:
for inpt_name in lazy:
parsed_inputs[inpt_name].lazy = True

interface = make_task_spec(
interface = make_task_def(
WorkflowDef,
WorkflowOutputs,
WorkflowTask,
Expand Down
7 changes: 7 additions & 0 deletions pydra/engine/submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ def __init__(self, plugin: ty.Union[str, ty.Type[Worker]] = "cf", **kwargs):

def __call__(self, runnable, cache_locations=None, rerun=False, environment=None):
"""Submitter run function."""
from pydra.engine.core import TaskDef

if cache_locations is not None:
runnable.cache_locations = cache_locations
if isinstance(runnable, TaskDef):
runnable = runnable.Task(
runnable,
cache_locations=cache_locations,
)
self.loop.run_until_complete(
self.submit_from_call(runnable, rerun, environment)
)
Expand Down
10 changes: 0 additions & 10 deletions pydra/engine/tests/test_dockertask.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def test_docker_inputspec_1(tmp_path):
shell.arg(
name="file",
type=File,
mandatory=True,
position=1,
argstr="",
help="input file",
Expand Down Expand Up @@ -258,7 +257,6 @@ def test_docker_inputspec_2a_except(plugin, tmp_path):
shell.arg(
name="file2",
type=File,
mandatory=True,
position=2,
argstr="",
help="input file 2",
Expand Down Expand Up @@ -304,7 +302,6 @@ def test_docker_inputspec_2a(plugin, tmp_path):
shell.arg(
name="file2",
type=File,
mandatory=True,
position=2,
argstr="",
help="input file 2",
Expand Down Expand Up @@ -335,7 +332,6 @@ def test_docker_inputspec_3(plugin, tmp_path):
shell.arg(
name="file",
type=File,
mandatory=True,
position=1,
argstr="",
help="input file",
Expand Down Expand Up @@ -372,7 +368,6 @@ def test_docker_cmd_inputspec_copyfile_1(plugin, tmp_path):
shell.arg(
name="orig_file",
type=File,
mandatory=True,
position=1,
argstr="",
help="orig file",
Expand Down Expand Up @@ -423,7 +418,6 @@ def test_docker_inputspec_state_1(plugin, tmp_path):
shell.arg(
name="file",
type=File,
mandatory=True,
position=1,
argstr="",
help="input file",
Expand Down Expand Up @@ -460,7 +454,6 @@ def test_docker_inputspec_state_1b(plugin, tmp_path):
shell.arg(
name="file",
type=File,
mandatory=True,
position=1,
argstr="",
help="input file",
Expand Down Expand Up @@ -490,7 +483,6 @@ def test_docker_wf_inputspec_1(plugin, tmp_path):
shell.arg(
name="file",
type=File,
mandatory=True,
position=1,
argstr="",
help="input file",
Expand Down Expand Up @@ -533,7 +525,6 @@ def test_docker_wf_state_inputspec_1(plugin, tmp_path):
shell.arg(
name="file",
type=File,
mandatory=True,
position=1,
argstr="",
help="input file",
Expand Down Expand Up @@ -578,7 +569,6 @@ def test_docker_wf_ndst_inputspec_1(plugin, tmp_path):
shell.arg(
name="file",
type=File,
mandatory=True,
position=1,
argstr="",
help="input file",
Expand Down
1 change: 0 additions & 1 deletion pydra/engine/tests/test_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ def create_shelly_inputfile(tempdir, filename, name, executable):
type=File,
position=1,
help="files",
mandatory=True,
argstr="",
)
]
Expand Down
2 changes: 2 additions & 0 deletions pydra/utils/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,8 @@ def is_fileset_or_union(type_: type) -> bool:
"""Check if the type is a FileSet or a Union containing a FileSet"""
if is_union(type_):
return any(is_fileset_or_union(t) for t in ty.get_args(type_))
elif not inspect.isclass(type_):
return False
return issubclass(type_, core.FileSet)


Expand Down

0 comments on commit ac7ab7f

Please sign in to comment.