Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions aiida_simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"nodes": [
{
"id": 0,
"type": "function",
"value": "workflow.get_prod_and_div"
},
{
"id": 1,
"type": "function",
"value": "workflow.get_sum"
},
{
"id": 2,
"type": "function",
"value": "workflow.square"
},
{
"id": 3,
"type": "input",
"name": "x",
"value": 1.0
},
{
"id": 4,
"type": "input",
"name": "y",
"value": 2.0
},
{
"id": 5,
"type": "output",
"name": null,
"value": null
}
],
"edges": [
{
"target": 0,
"targetPort": "x",
"source": 3,
"sourcePort": null
},
{
"target": 0,
"targetPort": "y",
"source": 4,
"sourcePort": null
},
{
"target": 1,
"targetPort": "x",
"source": 0,
"sourcePort": "prod"
},
{
"target": 1,
"targetPort": "y",
"source": 0,
"sourcePort": "div"
},
{
"target": 2,
"targetPort": "x",
"source": 1,
"sourcePort": null
},
{
"target": 5,
"targetPort": null,
"source": 2,
"sourcePort": null
}
]
}
304 changes: 187 additions & 117 deletions example_workflows/arithmetic/aiida.ipynb

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions example_workflows/arithmetic/aiida_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# %% [markdown]
# # Aiida

# %% [markdown]
# ## Define workflow with aiida

# %%
from python_workflow_definition.aiida import AiidaPwdConverter

from aiida_workgraph import WorkGraph, task
from aiida import orm, load_profile
from rich.pretty import pprint

load_profile()

workflow_json_filename = "aiida_simple.json"

# %%
from workflow import (
get_sum as _get_sum,
get_prod_and_div as _get_prod_and_div,
square as _square
)

# %%
wg = WorkGraph("arithmetic")

# %%
get_prod_and_div_task = wg.add_task(
task(outputs=['prod', 'div'])(_get_prod_and_div),
name="get_prod_and_div",
x=orm.Float(1),
y=orm.Float(2),
)

# %%
get_sum_task = wg.add_task(
_get_sum,
name="get_sum",
x=get_prod_and_div_task.outputs.prod,
y=get_prod_and_div_task.outputs.div,
)

# %%
square_task = wg.add_task(
_square,
name="square",
x=get_sum_task.outputs.result,
)

# %%
aiida_converter = AiidaPwdConverter()
model = aiida_converter.workgraph_to_model(wg=wg)
pprint(model.model_dump())

# model.dump_json_file(file_name=workflow_json_filename)

wg = aiida_converter.model_to_workgraph(model)
wg
# model.dump_json_file(file_name=workflow_json_filename)

# %%
# Currently conversion PWD <-> WG is not atomic, as information is lost due to the `group_outputs` workaround, and the
# fact that `group_inputs` is not implemented in WG, at all

# pwd_wf = PwdWorkflow.load_json_file(workflow_json_filename)
# wg = aiida_converter.model_to_workgraph(workflow_model=pwd_wf)

# model = aiida_converter.workgraph_to_model(wg)
# pprint(model.model_dump())

# %%

# %% [markdown]
# ## Load Workflow with jobflow

# %%
from python_workflow_definition.jobflow import load_workflow_json

# %%
from jobflow.managers.local import run_locally

# %%
flow = load_workflow_json(file_name=workflow_json_filename)

# %%
result = run_locally(flow)
result

# %% [markdown]
# ## Load Workflow with pyiron_base

# %%
from python_workflow_definition.pyiron_base import load_workflow_json

# %%
delayed_object_lst = load_workflow_json(file_name=workflow_json_filename)
delayed_object_lst[-1].draw()

# %%
delayed_object_lst[-1].pull()


51 changes: 51 additions & 0 deletions example_workflows/arithmetic/aiida_simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"nodes": [
{
"id": 0,
"type": "function",
"value": "workflow.get_prod_and_div"
},
{
"id": 1,
"type": "function",
"value": "workflow.get_sum"
},
{
"id": 2,
"type": "function",
"value": "workflow.square"
},
{
"id": 3,
"type": "output",
"name": "result",
"value": null
}
],
"edges": [
{
"target": 1,
"targetPort": "x",
"source": 0,
"sourcePort": "prod"
},
{
"target": 1,
"targetPort": "y",
"source": 0,
"sourcePort": "div"
},
{
"target": 2,
"targetPort": "x",
"source": 1,
"sourcePort": null
},
{
"target": 3,
"targetPort": null,
"source": 2,
"sourcePort": null
}
]
}
22 changes: 13 additions & 9 deletions example_workflows/arithmetic/workflow.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"nodes": [
{"id": 0, "function": "workflow.get_prod_and_div"},
{"id": 1, "function": "workflow.get_sum"},
{"id": 2, "value": 1},
{"id": 3, "value": 2}
{ "id": 0, "type": "function", "value": "workflow.get_prod_and_div" },
{ "id": 1, "type": "function", "value": "workflow.get_sum" },
{ "id": 2, "type": "function", "value": "workflow.square" },
{ "id": 3, "type": "input", "name": "a", "value": 1.0 },
{ "id": 4, "type": "input", "name": "b", "value": 2.0 },
{ "id": 5, "type": "output", "name": "result", "value": null }
],
"edges": [
{"target": 0, "targetPort": "x", "source": 2, "sourcePort": null},
{"target": 0, "targetPort": "y", "source": 3, "sourcePort": null},
{"target": 1, "targetPort": "x", "source": 0, "sourcePort": "prod"},
{"target": 1, "targetPort": "y", "source": 0, "sourcePort": "div"}
{ "target": 0, "targetPort": "x", "source": 3, "sourcePort": null },
{ "target": 0, "targetPort": "y", "source": 4, "sourcePort": null },
{ "target": 1, "targetPort": "x", "source": 0, "sourcePort": "prod" },
{ "target": 1, "targetPort": "y", "source": 0, "sourcePort": "div" },
{ "target": 2, "targetPort": "x", "source": 1, "sourcePort": null },
{ "target": 5, "targetPort": null, "source": 2, "sourcePort": null }
]
}
}
3 changes: 3 additions & 0 deletions example_workflows/arithmetic/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ def get_prod_and_div(x, y):

def get_sum(x, y):
return x + y

def square(x):
return x**2
Loading