diff --git a/docs/source/tutorial/6-workflow.ipynb b/docs/source/tutorial/6-workflow.ipynb index 73e61afac..c37677e7c 100644 --- a/docs/source/tutorial/6-workflow.ipynb +++ b/docs/source/tutorial/6-workflow.ipynb @@ -56,15 +56,30 @@ "metadata": {}, "outputs": [], "source": [ + "from pydra.compose import workflow, python\n", + "from pydra.utils import show_workflow, print_help\n", + "import tempfile\n", + "\n", + "cache_root = tempfile.mkdtemp()\n", + "\n", + "# Example python tasks\n", + "@python.define\n", + "def Add(a, b):\n", + " return a + b\n", + "\n", + "\n", + "@python.define\n", + "def Mul(a, b):\n", + " return a * b\n", + " \n", "@workflow.define\n", "def BasicWorkflow(a, b):\n", " add = workflow.add(Add(a=a, b=b))\n", " mul = workflow.add(Mul(a=add.out, b=b))\n", " return mul.out\n", "\n", - "\n", - "print_help(BasicWorkflow)\n", - "show_workflow(BasicWorkflow, figsize=(2, 2.5))" + "wf = BasicWorkflow(a=2, b=3)\n", + "print(wf())" ] }, { @@ -577,7 +592,7 @@ ], "metadata": { "kernelspec": { - "display_name": "wf13", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -591,7 +606,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.1" + "version": "3.12.11" } }, "nbformat": 4, diff --git a/pydra/compose/tests/test_workflow_run.py b/pydra/compose/tests/test_workflow_run.py index 9e314dda3..2973b0821 100644 --- a/pydra/compose/tests/test_workflow_run.py +++ b/pydra/compose/tests/test_workflow_run.py @@ -4606,3 +4606,28 @@ def Worky(x: int, y: ty.List[int]): outputs = Worky(x=10, y=[1, 2, 3, 4])(cache_root=tmp_path) assert outputs.sum == 100 assert outputs.products == [10, 20, 30, 40] + + +def test_plot_exec_workflow(tmp_path: Path): + + # Example python tasks + @python.define + def Add(a, b): + return a + b + + @python.define + def Mul(a, b): + return a * b + + @workflow.define + def BasicWorkflow(a, b): + add = workflow.add(Add(a=a, b=b)) + mul = workflow.add(Mul(a=add.out, b=b)) + return mul.out + + wf = BasicWorkflow(a=2, b=3) + + plot_workflow(BasicWorkflow, tmp_path / "plot-out") + + outputs = wf(cache_root=tmp_path / "cache") + assert outputs.out == 15 diff --git a/pydra/utils/general.py b/pydra/utils/general.py index 3c9dc7a1c..747fb78cc 100644 --- a/pydra/utils/general.py +++ b/pydra/utils/general.py @@ -4,6 +4,7 @@ import inspect import sys import typing as ty +import shutil from collections.abc import Mapping, Collection from copy import copy import re @@ -45,6 +46,11 @@ default_run_cache_root = user_cache_root / "run-cache" +def clean_run_cache(): + """Deletes the cache run directory to remove any stale data.""" + shutil.rmtree(default_run_cache_root) + + def add_exc_note(e: Exception, note: str) -> Exception: """Adds a note to an exception in a Python <3.11 compatible way diff --git a/pyproject.toml b/pyproject.toml index 72f4ccabd..e891964a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,7 @@ doc = [ "packaging", "pandas", "pandoc", - "pydra-mrtrix3 >=3.0.4a17", + "pydra-tasks-mrtrix3 >=3.0.4a17", "scipy", "sphinx", "sphinx-argparse", @@ -100,7 +100,7 @@ tutorial = [ "openneuro-py", "pandas", "psutil", - "pydra-mrtrix3 >=3.0.4a17", + "pydra-tasks-mrtrix3 >=3.0.4a17", "scipy", "sh", ]