Skip to content

Commit 8ec9cb7

Browse files
authored
Merge pull request #144 from fair-workflows/issue139_implement_noodles_execution
Issue139 implement noodles execution
2 parents 2e2741b + 349a3fe commit 8ec9cb7

6 files changed

Lines changed: 485 additions & 5 deletions

File tree

examples/noodles_fw.ipynb

Lines changed: 369 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,369 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "designed-spoke",
6+
"metadata": {},
7+
"source": [
8+
"# FairWorkflows execution demo"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "secure-render",
14+
"metadata": {},
15+
"source": [
16+
"## Define the steps of your workflow\n",
17+
"Each step should be its own function. Mark the function as such with the @fairstep decorator."
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": 9,
23+
"id": "spiritual-order",
24+
"metadata": {},
25+
"outputs": [],
26+
"source": [
27+
"from fairworkflows import is_fairworkflow, is_fairstep"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": 10,
33+
"id": "wired-bibliography",
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"@is_fairstep(label='Addition')\n",
38+
"def add(a:float, b:float) -> float:\n",
39+
" \"\"\"Adding up numbers!\"\"\"\n",
40+
" return a + b"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 11,
46+
"id": "brilliant-thumb",
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"@is_fairstep(label='Subtraction')\n",
51+
"def sub(a: float, b: float) -> float:\n",
52+
" \"\"\"Subtracting numbers.\"\"\"\n",
53+
" return a - b"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": 12,
59+
"id": "interested-margin",
60+
"metadata": {},
61+
"outputs": [],
62+
"source": [
63+
"@is_fairstep(label='Multiplication')\n",
64+
"def mul(a: float, b: float) -> float:\n",
65+
" \"\"\"Multiplying numbers.\"\"\"\n",
66+
" return a * b"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": 13,
72+
"id": "closing-vatican",
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"@is_fairstep(label='A strange step with little use')\n",
77+
"def weird(a: float, b:float) -> float:\n",
78+
" \"\"\"A weird function\"\"\"\n",
79+
" return a * 2 + b * 4\n",
80+
" "
81+
]
82+
},
83+
{
84+
"cell_type": "markdown",
85+
"id": "centered-nowhere",
86+
"metadata": {},
87+
"source": [
88+
"## Define your workflow using @fairworkflow\n",
89+
"Now write a function which describes your workflow. Mark this function with the @fairworkflow decorator."
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": 14,
95+
"id": "paperback-recycling",
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"@is_fairworkflow(label='My Workflow')\n",
100+
"def my_workflow(in1, in2, in3):\n",
101+
" \"\"\"\n",
102+
" A simple addition, subtraction, multiplication workflow\n",
103+
" \"\"\"\n",
104+
" t1 = add(in1, in2)\n",
105+
" t2 = sub(in1, in2)\n",
106+
" t3 = mul(weird(t1, in3), t2)\n",
107+
" return t3"
108+
]
109+
},
110+
{
111+
"cell_type": "markdown",
112+
"id": "sustained-sweden",
113+
"metadata": {},
114+
"source": [
115+
"## Create an instance of your workflow and display it"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": 15,
121+
"id": "noted-aviation",
122+
"metadata": {},
123+
"outputs": [
124+
{
125+
"data": {
126+
"text/plain": [
127+
"fairworkflows.fairworkflow.FairWorkflow"
128+
]
129+
},
130+
"execution_count": 15,
131+
"metadata": {},
132+
"output_type": "execute_result"
133+
}
134+
],
135+
"source": [
136+
"fw = my_workflow(1, 4, 3)\n",
137+
"type(fw)"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": 16,
143+
"id": "confirmed-hudson",
144+
"metadata": {},
145+
"outputs": [
146+
{
147+
"data": {
148+
"text/markdown": [
149+
"| workflow |\n",
150+
"| --- |\n",
151+
"| ![workflow workflow](control-workflow.svg) |"
152+
],
153+
"text/plain": [
154+
"<IPython.core.display.Markdown object>"
155+
]
156+
},
157+
"metadata": {},
158+
"output_type": "display_data"
159+
}
160+
],
161+
"source": [
162+
"fw.display()"
163+
]
164+
},
165+
{
166+
"cell_type": "markdown",
167+
"id": "outside-glance",
168+
"metadata": {},
169+
"source": [
170+
"## Execute your workflow using .execute()\n",
171+
"Set num_threads greater than 1 if you wish to exploit parallelisation in your workflow."
172+
]
173+
},
174+
{
175+
"cell_type": "code",
176+
"execution_count": 13,
177+
"id": "front-abuse",
178+
"metadata": {},
179+
"outputs": [
180+
{
181+
"data": {
182+
"text/plain": [
183+
"-66"
184+
]
185+
},
186+
"execution_count": 13,
187+
"metadata": {},
188+
"output_type": "execute_result"
189+
}
190+
],
191+
"source": [
192+
"answer = fw.execute(num_threads=2)\n",
193+
"answer"
194+
]
195+
},
196+
{
197+
"cell_type": "markdown",
198+
"id": "compound-shepherd",
199+
"metadata": {},
200+
"source": [
201+
"## Get retrospective provenance of run\n",
202+
"This is not in RDF format yet, but we have all the information needed."
203+
]
204+
},
205+
{
206+
"cell_type": "code",
207+
"execution_count": 12,
208+
"id": "comprehensive-finland",
209+
"metadata": {},
210+
"outputs": [
211+
{
212+
"ename": "AttributeError",
213+
"evalue": "'FairWorkflow' object has no attribute 'prov'",
214+
"output_type": "error",
215+
"traceback": [
216+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
217+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
218+
"\u001b[0;32m<ipython-input-12-fa58d0e49b7b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mfw\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprov\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
219+
"\u001b[0;31mAttributeError\u001b[0m: 'FairWorkflow' object has no attribute 'prov'"
220+
]
221+
}
222+
],
223+
"source": [
224+
"fw.prov()"
225+
]
226+
},
227+
{
228+
"cell_type": "markdown",
229+
"id": "precious-domain",
230+
"metadata": {},
231+
"source": [
232+
"## Get Plex RDF of workflow"
233+
]
234+
},
235+
{
236+
"cell_type": "code",
237+
"execution_count": null,
238+
"id": "concerned-massage",
239+
"metadata": {},
240+
"outputs": [],
241+
"source": [
242+
"fw.get_workflow()"
243+
]
244+
},
245+
{
246+
"cell_type": "raw",
247+
"id": "continent-editing",
248+
"metadata": {},
249+
"source": []
250+
},
251+
{
252+
"cell_type": "code",
253+
"execution_count": null,
254+
"id": "capital-minority",
255+
"metadata": {},
256+
"outputs": [],
257+
"source": []
258+
},
259+
{
260+
"cell_type": "code",
261+
"execution_count": null,
262+
"id": "smoking-lebanon",
263+
"metadata": {},
264+
"outputs": [],
265+
"source": []
266+
},
267+
{
268+
"cell_type": "code",
269+
"execution_count": null,
270+
"id": "controversial-control",
271+
"metadata": {},
272+
"outputs": [],
273+
"source": []
274+
},
275+
{
276+
"cell_type": "code",
277+
"execution_count": null,
278+
"id": "alternate-template",
279+
"metadata": {},
280+
"outputs": [],
281+
"source": []
282+
},
283+
{
284+
"cell_type": "code",
285+
"execution_count": null,
286+
"id": "ecological-divorce",
287+
"metadata": {},
288+
"outputs": [],
289+
"source": []
290+
},
291+
{
292+
"cell_type": "code",
293+
"execution_count": null,
294+
"id": "liberal-queen",
295+
"metadata": {},
296+
"outputs": [],
297+
"source": []
298+
},
299+
{
300+
"cell_type": "code",
301+
"execution_count": null,
302+
"id": "specific-humanitarian",
303+
"metadata": {},
304+
"outputs": [],
305+
"source": []
306+
},
307+
{
308+
"cell_type": "code",
309+
"execution_count": null,
310+
"id": "thick-budapest",
311+
"metadata": {},
312+
"outputs": [],
313+
"source": []
314+
},
315+
{
316+
"cell_type": "code",
317+
"execution_count": null,
318+
"id": "italic-color",
319+
"metadata": {},
320+
"outputs": [],
321+
"source": []
322+
},
323+
{
324+
"cell_type": "code",
325+
"execution_count": null,
326+
"id": "respiratory-netscape",
327+
"metadata": {},
328+
"outputs": [],
329+
"source": []
330+
},
331+
{
332+
"cell_type": "code",
333+
"execution_count": null,
334+
"id": "marked-shark",
335+
"metadata": {},
336+
"outputs": [],
337+
"source": []
338+
},
339+
{
340+
"cell_type": "code",
341+
"execution_count": null,
342+
"id": "material-robertson",
343+
"metadata": {},
344+
"outputs": [],
345+
"source": []
346+
}
347+
],
348+
"metadata": {
349+
"kernelspec": {
350+
"display_name": "Python 3",
351+
"language": "python",
352+
"name": "python3"
353+
},
354+
"language_info": {
355+
"codemirror_mode": {
356+
"name": "ipython",
357+
"version": 3
358+
},
359+
"file_extension": ".py",
360+
"mimetype": "text/x-python",
361+
"name": "python",
362+
"nbconvert_exporter": "python",
363+
"pygments_lexer": "ipython3",
364+
"version": "3.8.6"
365+
}
366+
},
367+
"nbformat": 4,
368+
"nbformat_minor": 5
369+
}

fairworkflows/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from ._version import __version__
2-
from .fairstep import FairStep, FairVariable, mark_as_fairstep
3-
from .fairworkflow import FairWorkflow
2+
from .fairstep import FairStep, FairVariable, mark_as_fairstep, is_fairstep
3+
from .fairworkflow import FairWorkflow, is_fairworkflow

0 commit comments

Comments
 (0)