Skip to content

Commit d35320b

Browse files
committed
Last changes on pydantic-branch, before switching back to main
1 parent 3ad82fc commit d35320b

File tree

9 files changed

+2753
-313
lines changed

9 files changed

+2753
-313
lines changed

aiida_simple.json

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"nodes": [
3+
{
4+
"id": 0,
5+
"type": "function",
6+
"value": "workflow.get_prod_and_div"
7+
},
8+
{
9+
"id": 1,
10+
"type": "function",
11+
"value": "workflow.get_sum"
12+
},
13+
{
14+
"id": 2,
15+
"type": "function",
16+
"value": "workflow.square"
17+
},
18+
{
19+
"id": 3,
20+
"type": "input",
21+
"name": "x",
22+
"value": 1.0
23+
},
24+
{
25+
"id": 4,
26+
"type": "input",
27+
"name": "y",
28+
"value": 2.0
29+
},
30+
{
31+
"id": 5,
32+
"type": "output",
33+
"name": null,
34+
"value": null
35+
}
36+
],
37+
"edges": [
38+
{
39+
"target": 0,
40+
"targetPort": "x",
41+
"source": 3,
42+
"sourcePort": null
43+
},
44+
{
45+
"target": 0,
46+
"targetPort": "y",
47+
"source": 4,
48+
"sourcePort": null
49+
},
50+
{
51+
"target": 1,
52+
"targetPort": "x",
53+
"source": 0,
54+
"sourcePort": "prod"
55+
},
56+
{
57+
"target": 1,
58+
"targetPort": "y",
59+
"source": 0,
60+
"sourcePort": "div"
61+
},
62+
{
63+
"target": 2,
64+
"targetPort": "x",
65+
"source": 1,
66+
"sourcePort": null
67+
},
68+
{
69+
"target": 5,
70+
"targetPort": null,
71+
"source": 2,
72+
"sourcePort": null
73+
}
74+
]
75+
}

example_workflows/arithmetic/aiida.ipynb

Lines changed: 19 additions & 27 deletions
Large diffs are not rendered by default.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# %% [markdown]
2+
# # Aiida
3+
4+
# %% [markdown]
5+
# ## Define workflow with aiida
6+
7+
# %%
8+
from python_workflow_definition.aiida import AiidaPwdConverter
9+
10+
from aiida_workgraph import WorkGraph, task
11+
from aiida import orm, load_profile
12+
from rich.pretty import pprint
13+
14+
load_profile()
15+
16+
workflow_json_filename = "aiida_simple.json"
17+
18+
# %%
19+
from workflow import (
20+
get_sum as _get_sum,
21+
get_prod_and_div as _get_prod_and_div,
22+
square as _square
23+
)
24+
25+
# %%
26+
wg = WorkGraph("arithmetic")
27+
28+
# %%
29+
get_prod_and_div_task = wg.add_task(
30+
task(outputs=['prod', 'div'])(_get_prod_and_div),
31+
name="get_prod_and_div",
32+
x=orm.Float(1),
33+
y=orm.Float(2),
34+
)
35+
36+
# %%
37+
get_sum_task = wg.add_task(
38+
_get_sum,
39+
name="get_sum",
40+
x=get_prod_and_div_task.outputs.prod,
41+
y=get_prod_and_div_task.outputs.div,
42+
)
43+
44+
# %%
45+
square_task = wg.add_task(
46+
_square,
47+
name="square",
48+
x=get_sum_task.outputs.result,
49+
)
50+
51+
# %%
52+
aiida_converter = AiidaPwdConverter()
53+
model = aiida_converter.workgraph_to_model(wg=wg)
54+
pprint(model.model_dump())
55+
56+
# model.dump_json_file(file_name=workflow_json_filename)
57+
58+
wg = aiida_converter.model_to_workgraph(model)
59+
wg
60+
# model.dump_json_file(file_name=workflow_json_filename)
61+
62+
# %%
63+
# Currently conversion PWD <-> WG is not atomic, as information is lost due to the `group_outputs` workaround, and the
64+
# fact that `group_inputs` is not implemented in WG, at all
65+
66+
# pwd_wf = PwdWorkflow.load_json_file(workflow_json_filename)
67+
# wg = aiida_converter.model_to_workgraph(workflow_model=pwd_wf)
68+
69+
# model = aiida_converter.workgraph_to_model(wg)
70+
# pprint(model.model_dump())
71+
72+
# %%
73+
74+
# %% [markdown]
75+
# ## Load Workflow with jobflow
76+
77+
# %%
78+
from python_workflow_definition.jobflow import load_workflow_json
79+
80+
# %%
81+
from jobflow.managers.local import run_locally
82+
83+
# %%
84+
flow = load_workflow_json(file_name=workflow_json_filename)
85+
86+
# %%
87+
result = run_locally(flow)
88+
result
89+
90+
# %% [markdown]
91+
# ## Load Workflow with pyiron_base
92+
93+
# %%
94+
from python_workflow_definition.pyiron_base import load_workflow_json
95+
96+
# %%
97+
delayed_object_lst = load_workflow_json(file_name=workflow_json_filename)
98+
delayed_object_lst[-1].draw()
99+
100+
# %%
101+
delayed_object_lst[-1].pull()
102+
103+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"nodes": [
3+
{
4+
"id": 0,
5+
"type": "function",
6+
"value": "workflow.get_prod_and_div"
7+
},
8+
{
9+
"id": 1,
10+
"type": "function",
11+
"value": "workflow.get_sum"
12+
},
13+
{
14+
"id": 2,
15+
"type": "function",
16+
"value": "workflow.square"
17+
},
18+
{
19+
"id": 3,
20+
"type": "output",
21+
"name": "result",
22+
"value": null
23+
}
24+
],
25+
"edges": [
26+
{
27+
"target": 1,
28+
"targetPort": "x",
29+
"source": 0,
30+
"sourcePort": "prod"
31+
},
32+
{
33+
"target": 1,
34+
"targetPort": "y",
35+
"source": 0,
36+
"sourcePort": "div"
37+
},
38+
{
39+
"target": 2,
40+
"targetPort": "x",
41+
"source": 1,
42+
"sourcePort": null
43+
},
44+
{
45+
"target": 3,
46+
"targetPort": null,
47+
"source": 2,
48+
"sourcePort": null
49+
}
50+
]
51+
}
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
"nodes": [
3-
{"id": 0, "function": "workflow.get_prod_and_div"},
4-
{"id": 1, "function": "workflow.get_sum"},
5-
{"id": 2, "value": 1},
6-
{"id": 3, "value": 2}
3+
{ "id": 0, "type": "function", "value": "workflow.get_prod_and_div" },
4+
{ "id": 1, "type": "function", "value": "workflow.get_sum" },
5+
{ "id": 2, "type": "function", "value": "workflow.square" },
6+
{ "id": 3, "type": "input", "name": "a", "value": 1.0 },
7+
{ "id": 4, "type": "input", "name": "b", "value": 2.0 },
8+
{ "id": 5, "type": "output", "name": "result", "value": null }
79
],
810
"edges": [
9-
{"target": 0, "targetPort": "x", "source": 2, "sourcePort": null},
10-
{"target": 0, "targetPort": "y", "source": 3, "sourcePort": null},
11-
{"target": 1, "targetPort": "x", "source": 0, "sourcePort": "prod"},
12-
{"target": 1, "targetPort": "y", "source": 0, "sourcePort": "div"}
11+
{ "target": 0, "targetPort": "x", "source": 3, "sourcePort": null },
12+
{ "target": 0, "targetPort": "y", "source": 4, "sourcePort": null },
13+
{ "target": 1, "targetPort": "x", "source": 0, "sourcePort": "prod" },
14+
{ "target": 1, "targetPort": "y", "source": 0, "sourcePort": "div" },
15+
{ "target": 2, "targetPort": "x", "source": 1, "sourcePort": null },
16+
{ "target": 5, "targetPort": null, "source": 2, "sourcePort": null }
1317
]
14-
}
18+
}

0 commit comments

Comments
 (0)