|
29 | 29 | "outputs": [], |
30 | 30 | "source": [ |
31 | 31 | "from pydra.compose import workflow, python\n", |
| 32 | + "from pydra.utils import show_workflow, print_help\n", |
32 | 33 | "\n", |
33 | 34 | "\n", |
34 | 35 | "# Example python tasks\n", |
|
59 | 60 | "def BasicWorkflow(a, b):\n", |
60 | 61 | " add = workflow.add(Add(a=a, b=b))\n", |
61 | 62 | " mul = workflow.add(Mul(a=add.out, b=b))\n", |
62 | | - " return mul.out" |
| 63 | + " return mul.out\n", |
| 64 | + "\n", |
| 65 | + "\n", |
| 66 | + "show_workflow(BasicWorkflow, figsize=(2, 2.5))" |
63 | 67 | ] |
64 | 68 | }, |
65 | 69 | { |
|
109 | 113 | " )(in_video=add_watermark.out_video, width=1280, height=720)\n", |
110 | 114 | " ).out_video\n", |
111 | 115 | "\n", |
112 | | - " return output_video # test implicit detection of output name" |
| 116 | + " return output_video # test implicit detection of output name\n", |
| 117 | + "\n", |
| 118 | + "\n", |
| 119 | + "show_workflow(ShellWorkflow, figsize=(2.5, 3))" |
113 | 120 | ] |
114 | 121 | }, |
115 | 122 | { |
|
136 | 143 | "def SplitWorkflow(a: list[int], b: list[float]) -> list[float]:\n", |
137 | 144 | " # Multiply over all combinations of the elements of a and b, then combine the results\n", |
138 | 145 | " # for each a element into a list over each b element\n", |
139 | | - " mul = workflow.add(Mul().split(x=a, y=b).combine(\"x\"))\n", |
| 146 | + " mul = workflow.add(Mul().split(a=a, b=b).combine(\"a\"))\n", |
140 | 147 | " # Sume the multiplications across all all b elements for each a element\n", |
141 | 148 | " sum = workflow.add(Sum(x=mul.out))\n", |
142 | | - " return sum.out" |
| 149 | + " return sum.out\n", |
| 150 | + "\n", |
| 151 | + "\n", |
| 152 | + "show_workflow(SplitWorkflow, figsize=(2, 2.5))" |
143 | 153 | ] |
144 | 154 | }, |
145 | 155 | { |
|
157 | 167 | "source": [ |
158 | 168 | "@workflow.define\n", |
159 | 169 | "def SplitThenCombineWorkflow(a: list[int], b: list[float], c: float) -> list[float]:\n", |
160 | | - " mul = workflow.add(Mul().split(x=a, y=b))\n", |
161 | | - " add = workflow.add(Add(x=mul.out, y=c).combine(\"Mul.x\"))\n", |
| 170 | + " mul = workflow.add(Mul().split(a=a, b=b))\n", |
| 171 | + " add = workflow.add(Add(a=mul.out, b=c).combine(\"Mul.a\"))\n", |
162 | 172 | " sum = workflow.add(Sum(x=add.out))\n", |
163 | | - " return sum.out" |
| 173 | + " return sum.out\n", |
| 174 | + "\n", |
| 175 | + "\n", |
| 176 | + "show_workflow(SplitThenCombineWorkflow, figsize=(3, 3.5))" |
164 | 177 | ] |
165 | 178 | }, |
166 | 179 | { |
|
214 | 227 | " )(in_video=handbrake_input, width=1280, height=720)\n", |
215 | 228 | " ).out_video\n", |
216 | 229 | "\n", |
217 | | - " return output_video # test implicit detection of output name" |
| 230 | + " return output_video # test implicit detection of output name\n", |
| 231 | + "\n", |
| 232 | + "\n", |
| 233 | + "show_workflow(ConditionalWorkflow(watermark_dims=(10, 10)), figsize=(2.5, 3))" |
218 | 234 | ] |
219 | 235 | }, |
220 | 236 | { |
|
238 | 254 | "\n", |
239 | 255 | "@workflow.define\n", |
240 | 256 | "def RecursiveNestedWorkflow(a: float, depth: int) -> float:\n", |
241 | | - " add = workflow.add(Add(x=a, y=1))\n", |
| 257 | + " add = workflow.add(Add(a=a, b=1))\n", |
242 | 258 | " decrement_depth = workflow.add(Subtract(x=depth, y=1))\n", |
243 | 259 | " if depth > 0:\n", |
244 | 260 | " out_node = workflow.add(\n", |
245 | 261 | " RecursiveNestedWorkflow(a=add.out, depth=decrement_depth.out)\n", |
246 | 262 | " )\n", |
247 | 263 | " else:\n", |
248 | 264 | " out_node = add\n", |
249 | | - " return out_node.out" |
| 265 | + " return out_node.out\n", |
| 266 | + "\n", |
| 267 | + "\n", |
| 268 | + "print_help(RecursiveNestedWorkflow)" |
250 | 269 | ] |
251 | 270 | }, |
252 | 271 | { |
|
327 | 346 | " Mp4Handbrake(in_video=add_watermark.out_video, width=1280, height=720),\n", |
328 | 347 | " ) # The type of the input video is now correct\n", |
329 | 348 | "\n", |
330 | | - " return handbrake.output_video" |
| 349 | + " return handbrake.out_video\n", |
| 350 | + "\n", |
| 351 | + "\n", |
| 352 | + "show_workflow(TypeErrorWorkflow, plot_type=\"detailed\")" |
331 | 353 | ] |
332 | 354 | }, |
333 | 355 | { |
|
372 | 394 | "\n", |
373 | 395 | " wf = workflow.this()\n", |
374 | 396 | "\n", |
375 | | - " add = wf.add(Add(x=a, y=b), name=\"addition\")\n", |
376 | | - " mul = wf.add(python.define(Mul, outputs={\"out\": float})(x=add.z, y=b))\n", |
377 | | - " divide = wf.add(Divide(x=wf[\"addition\"].lzout.z, y=mul.out), name=\"division\")\n", |
| 397 | + " add = wf.add(Add(a=a, b=b), name=\"addition\")\n", |
| 398 | + " mul = wf.add(Mul(a=add.out, b=b))\n", |
| 399 | + " divide = wf.add(Divide(x=wf[\"addition\"].lzout.out, y=mul.out), name=\"division\")\n", |
378 | 400 | "\n", |
379 | 401 | " # Alter one of the inputs to a node after it has been initialised\n", |
380 | | - " wf[\"Mul\"].inputs.y *= 2\n", |
| 402 | + " wf[\"Mul\"].inputs.b *= 2\n", |
381 | 403 | "\n", |
382 | | - " return mul.out, divide.divided" |
| 404 | + " return mul.out, divide.divided\n", |
| 405 | + "\n", |
| 406 | + "\n", |
| 407 | + "show_workflow(DirectAccesWorkflow(b=1), plot_type=\"detailed\")" |
383 | 408 | ] |
384 | 409 | }, |
385 | 410 | { |
|
410 | 435 | "\n", |
411 | 436 | " wf = workflow.this()\n", |
412 | 437 | "\n", |
413 | | - " add = wf.add(Add(x=a, y=b), name=\"addition\")\n", |
414 | | - " mul = wf.add(python.define(Mul, outputs={\"out\": float})(x=add.z, y=b))\n", |
415 | | - " divide = wf.add(Divide(x=wf[\"addition\"].lzout.z, y=mul.out), name=\"division\")\n", |
| 438 | + " add = wf.add(Add(a=a, b=b), name=\"addition\")\n", |
| 439 | + " mul = wf.add(Mul(a=add.out, b=b))\n", |
| 440 | + " divide = wf.add(Divide(x=wf[\"addition\"].lzout.out, y=mul.out), name=\"division\")\n", |
416 | 441 | "\n", |
417 | 442 | " # Alter one of the inputs to a node after it has been initialised\n", |
418 | | - " wf[\"Mul\"].inputs.y *= 2\n", |
| 443 | + " wf[\"Mul\"].inputs.b *= 2\n", |
419 | 444 | "\n", |
420 | 445 | " # Set the outputs of the workflow directly\n", |
421 | 446 | " wf.outputs.out1 = mul.out\n", |
422 | | - " wf.outputs.out2 = divide.divided" |
| 447 | + " wf.outputs.out2 = divide.divided\n", |
| 448 | + "\n", |
| 449 | + "\n", |
| 450 | + "show_workflow(SetOutputsOfWorkflow(b=3), plot_type=\"detailed\")" |
423 | 451 | ] |
424 | 452 | }, |
425 | 453 | { |
|
514 | 542 | " return output_conversion.out_file\n", |
515 | 543 | "\n", |
516 | 544 | "\n", |
517 | | - "test_dir = tempfile.mkdtemp()\n", |
| 545 | + "test_dir = Path(tempfile.mkdtemp())\n", |
518 | 546 | "\n", |
519 | 547 | "nifti_file = Nifti1.sample(test_dir, seed=0)\n", |
520 | 548 | "\n", |
521 | 549 | "wf = ToyMedianThreshold(in_image=nifti_file)\n", |
522 | 550 | "\n", |
523 | | - "outputs = wf()\n", |
| 551 | + "outputs = wf(cache_dir=test_dir / \"cache\")\n", |
524 | 552 | "\n", |
525 | 553 | "print(outputs)" |
526 | 554 | ] |
|
0 commit comments