Skip to content

Commit

Permalink
debugging cf execution within notebooks, implemented byte-code hashin…
Browse files Browse the repository at this point in the history
…g of functions
  • Loading branch information
tclose committed Jan 25, 2025
1 parent e59d86e commit 834024e
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 98 deletions.
44 changes: 44 additions & 0 deletions new-docs/source/tutorial/1-getting-started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,50 @@
"print(\"\\n\".join(str(p) for p in outputs.out_file))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Executing tasks in parallel\n",
"\n",
"By default, Pydra will use the *debug* worker, which executes each task sequentially.\n",
"This makes it easier to debug tasks and workflows, however, in most cases, once a workflow\n",
"is ready to go, a concurrent worker is preferable so tasks can be executed in parallel\n",
"(see [Workers](./2-advanced-execution.html#Workers)). To use multiple processes on a\n",
"workstation, select the `cf` worker option when executing the task/workflow.\n",
"\n",
"Note that when multiprocessing in Python on Windows and macOS (and good practice on Linux/POSIX\n",
"OSs for compatibility), you need to place a `if __name__ == \"__main__\"` block when\n",
"executing in top-level scripts to allow the script to be imported, but not executed,\n",
"by subprocesses."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'nifti_dir' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], 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;28;01mif\u001b[39;00m \u001b[38;5;18m__name__\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m__main__\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;66;03m# <-- Add this block to allow the script to imported by subprocesses\u001b[39;00m\n\u001b[0;32m----> 4\u001b[0m mrgrid \u001b[38;5;241m=\u001b[39m MrGrid(operation\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mregrid\u001b[39m\u001b[38;5;124m\"\u001b[39m, voxel\u001b[38;5;241m=\u001b[39m(\u001b[38;5;241m0.5\u001b[39m,\u001b[38;5;241m0.5\u001b[39m,\u001b[38;5;241m0.5\u001b[39m))\u001b[38;5;241m.\u001b[39msplit(in_file\u001b[38;5;241m=\u001b[39m\u001b[43mnifti_dir\u001b[49m\u001b[38;5;241m.\u001b[39miterdir())\n\u001b[1;32m 5\u001b[0m outputs \u001b[38;5;241m=\u001b[39m mrgrid(worker\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcf\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# <-- Select the \"cf\" worker here\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mjoin(\u001b[38;5;28mstr\u001b[39m(p) \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m outputs\u001b[38;5;241m.\u001b[39mout_file))\n",
"\u001b[0;31mNameError\u001b[0m: name 'nifti_dir' is not defined"
]
}
],
"source": [
"from pydra.tasks.mrtrix3.v3_0 import MrGrid\n",
"\n",
"if __name__ == \"__main__\": # <-- Add this block to allow the script to imported by subprocesses\n",
" mrgrid = MrGrid(operation=\"regrid\", voxel=(0.5,0.5,0.5)).split(in_file=nifti_dir.iterdir())\n",
" outputs = mrgrid(worker=\"cf\") # <-- Select the \"cf\" worker here\n",
" print(\"\\n\".join(str(p) for p in outputs.out_file))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Loading

0 comments on commit 834024e

Please sign in to comment.