Skip to content

Commit 4eb1108

Browse files
authored
Update simple example to be a bit more complex (#58)
1 parent b7fb607 commit 4eb1108

File tree

7 files changed

+962
-57
lines changed

7 files changed

+962
-57
lines changed

README.md

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,32 @@ different workflow engines to enable interoperability.
1717
As a first example we define two Python functions which add multiple inputs:
1818
```python
1919
def add_x_and_y(x, y):
20-
z = x + y
21-
return x, y, z
22-
23-
def add_x_and_y_and_z(x, y, z):
24-
w = x + y + z
25-
return w
20+
return x + y
21+
22+
def get_prod_and_div(x: float, y: float) -> dict:
23+
return {"prod": x * y, "div": x / y}
2624
```
2725
These two Python functions are combined in the following example workflow:
2826
```python
29-
x, y, z = add_x_and_y(x=1, y=2)
30-
w = add_x_and_y_and_z(x=x, y=y, z=z)
27+
tmp_dict = get_prod_and_div(x=1, y=2)
28+
result = add_x_and_y(x=tmp_dict["prod"], y=tmp_dict["div"])
3129
```
3230
For the workflow representation of these Python functions the Python functions are stored in the [simple_workflow.py](simple_workflow.py)
3331
Python module. The connection of the Python functions are stored in the [workflow_simple.json](workflow_simple.json)
3432
JSON file:
3533
```
3634
{
3735
"nodes": [
38-
{"id": 0, "function": "simple_workflow.add_x_and_y_and_z"},
36+
{"id": 0, "function": "simple_workflow.get_prod_and_div"},
3937
{"id": 1, "function": "simple_workflow.add_x_and_y"},
40-
{"id": 2, "function": "simple_workflow.add_x_and_y"},
41-
{"id": 3, "function": "simple_workflow.add_x_and_y"},
42-
{"id": 4, "value": 1},
43-
{"id": 5, "value": 2}
38+
{"id": 2, "value": 1},
39+
{"id": 3, "value": 2}
4440
],
4541
"edges": [
46-
{"target": 0, "targetPort": "x", "source": 1, "sourcePort": "x"},
47-
{"target": 1, "targetPort": "x", "source": 4, "sourcePort": null},
48-
{"target": 1, "targetPort": "y", "source": 5, "sourcePort": null},
49-
{"target": 0, "targetPort": "y", "source": 2, "sourcePort": "y"},
50-
{"target": 2, "targetPort": "x", "source": 4, "sourcePort": null},
51-
{"target": 2, "targetPort": "y", "source": 5, "sourcePort": null},
52-
{"target": 0, "targetPort": "z", "source": 3, "sourcePort": "z"},
53-
{"target": 3, "targetPort": "x", "source": 4, "sourcePort": null},
54-
{"target": 3, "targetPort": "y", "source": 5, "sourcePort": null}
42+
{"target": 0, "targetPort": "x", "source": 2, "sourcePort": null},
43+
{"target": 0, "targetPort": "y", "source": 3, "sourcePort": null},
44+
{"target": 1, "targetPort": "x", "source": 0, "sourcePort": "prod"},
45+
{"target": 1, "targetPort": "y", "source": 0, "sourcePort": "div"}
5546
]
5647
}
5748
```

aiida_simple.ipynb

Lines changed: 279 additions & 1 deletion
Large diffs are not rendered by default.

book/simple.md

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,32 @@
22
As a first example we define two Python functions which add multiple inputs:
33
```python
44
def add_x_and_y(x, y):
5-
z = x + y
6-
return x, y, z
7-
8-
def add_x_and_y_and_z(x, y, z):
9-
w = x + y + z
10-
return w
5+
return x + y
6+
7+
def get_prod_and_div(x: float, y: float) -> dict:
8+
return {"prod": x * y, "div": x / y}
119
```
1210
These two Python functions are combined in the following example workflow:
1311
```python
14-
x, y, z = add_x_and_y(x=1, y=2)
15-
w = add_x_and_y_and_z(x=x, y=y, z=z)
12+
tmp_dict = get_prod_and_div(x=1, y=2)
13+
result = add_x_and_y(x=tmp_dict["prod"], y=tmp_dict["div"])
1614
```
1715
For the workflow representation of these Python functions the Python functions are stored in the [simple_workflow.py](simple_workflow.py)
1816
Python module. The connection of the Python functions are stored in the [workflow_simple.json](workflow_simple.json)
1917
JSON file:
2018
```
2119
{
2220
"nodes": [
23-
{"id": 0, "function": "simple_workflow.add_x_and_y_and_z"},
21+
{"id": 0, "function": "simple_workflow.get_prod_and_div"},
2422
{"id": 1, "function": "simple_workflow.add_x_and_y"},
25-
{"id": 2, "function": "simple_workflow.add_x_and_y"},
26-
{"id": 3, "function": "simple_workflow.add_x_and_y"},
27-
{"id": 4, "value": 1},
28-
{"id": 5, "value": 2}
23+
{"id": 2, "value": 1},
24+
{"id": 3, "value": 2}
2925
],
3026
"edges": [
31-
{"target": 0, "targetPort": "x", "source": 1, "sourcePort": "x"},
32-
{"target": 1, "targetPort": "x", "source": 4, "sourcePort": null},
33-
{"target": 1, "targetPort": "y", "source": 5, "sourcePort": null},
34-
{"target": 0, "targetPort": "y", "source": 2, "sourcePort": "y"},
35-
{"target": 2, "targetPort": "x", "source": 4, "sourcePort": null},
36-
{"target": 2, "targetPort": "y", "source": 5, "sourcePort": null},
37-
{"target": 0, "targetPort": "z", "source": 3, "sourcePort": "z"},
38-
{"target": 3, "targetPort": "x", "source": 4, "sourcePort": null},
39-
{"target": 3, "targetPort": "y", "source": 5, "sourcePort": null}
27+
{"target": 0, "targetPort": "x", "source": 2, "sourcePort": null},
28+
{"target": 0, "targetPort": "y", "source": 3, "sourcePort": null},
29+
{"target": 1, "targetPort": "x", "source": 0, "sourcePort": "prod"},
30+
{"target": 1, "targetPort": "y", "source": 0, "sourcePort": "div"}
4031
]
4132
}
4233
```

0 commit comments

Comments
 (0)