Skip to content

Commit 2ef0f01

Browse files
committed
Plot notebooks
1 parent 5b90124 commit 2ef0f01

File tree

5 files changed

+77
-12
lines changed

5 files changed

+77
-12
lines changed

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dependencies:
77
- pygraphviz=1.14
88
- aiida-workgraph=0.5.1
99
- conda_subprocess =0.0.6
10+
- networkx=3.4.2

python_workflow_definition/src/python_workflow_definition/plot.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44
import networkx as nx
55

66

7-
from python_workflow_definition.shared import get_kwargs, convert_nodes_list_to_dict
87
from python_workflow_definition.purepython import group_edges
9-
10-
11-
def plot(json_file_name):
12-
with open(json_file_name, "r") as f:
8+
from python_workflow_definition.shared import (
9+
get_kwargs,
10+
convert_nodes_list_to_dict,
11+
NODES_LABEL,
12+
EDGES_LABEL,
13+
SOURCE_LABEL,
14+
SOURCE_PORT_LABEL,
15+
)
16+
17+
18+
def plot(file_name):
19+
with open(file_name, "r") as f:
1320
content = json.load(f)
1421

1522
graph = nx.DiGraph()
16-
node_dict = convert_nodes_list_to_dict(nodes_list=content["nodes"])
17-
total_lst = group_edges(edges_lst=content["edges"])
23+
node_dict = convert_nodes_list_to_dict(nodes_list=content[NODES_LABEL])
24+
total_lst = group_edges(edges_lst=content[EDGES_LABEL])
1825

1926
for node_id, node_name in node_dict.items():
2027
graph.add_node(node_id, name=str(node_name), label=str(node_name))
@@ -23,12 +30,12 @@ def plot(json_file_name):
2330
target_node, edge_dict = edge_tuple
2431
edge_label_dict = {}
2532
for k, v in edge_dict.items():
26-
if v["source"] not in edge_label_dict:
27-
edge_label_dict[v["source"]] = []
28-
if v["sourcePort"] is None:
29-
edge_label_dict[v["source"]].append(k)
33+
if v[SOURCE_LABEL] not in edge_label_dict:
34+
edge_label_dict[v[SOURCE_LABEL]] = []
35+
if v[SOURCE_PORT_LABEL] is None:
36+
edge_label_dict[v[SOURCE_LABEL]].append(k)
3037
else:
31-
edge_label_dict[v["source"]].append(v["sourcePort"] + "=" + k)
38+
edge_label_dict[v[SOURCE_LABEL]].append(v[SOURCE_PORT_LABEL] + "=" + k)
3239
for k, v in edge_label_dict.items():
3340
graph.add_edge(str(k), str(target_node), label=", ".join(v))
3441

universal_workflow_nfdi.ipynb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77
"# Load Simple Workflow"
88
]
99
},
10+
{
11+
"metadata": {},
12+
"cell_type": "markdown",
13+
"source": "## Plot"
14+
},
15+
{
16+
"metadata": {},
17+
"cell_type": "code",
18+
"outputs": [],
19+
"execution_count": null,
20+
"source": "from python_workflow_definition.plot import plot"
21+
},
22+
{
23+
"metadata": {},
24+
"cell_type": "code",
25+
"outputs": [],
26+
"execution_count": null,
27+
"source": "plot(file_name='workflow_nfdi.json')"
28+
},
1029
{
1130
"cell_type": "markdown",
1231
"metadata": {},

universal_workflow_qe.ipynb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77
"# Load Quantum Espresso Energy Volume Curve Workflow"
88
]
99
},
10+
{
11+
"metadata": {},
12+
"cell_type": "markdown",
13+
"source": "## Plot"
14+
},
15+
{
16+
"metadata": {},
17+
"cell_type": "code",
18+
"outputs": [],
19+
"execution_count": null,
20+
"source": "from python_workflow_definition.plot import plot"
21+
},
22+
{
23+
"metadata": {},
24+
"cell_type": "code",
25+
"outputs": [],
26+
"execution_count": null,
27+
"source": "plot(file_name='workflow_qe.json')"
28+
},
1029
{
1130
"cell_type": "markdown",
1231
"metadata": {},

universal_workflow_simple.ipynb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77
"# Load Simple Workflow"
88
]
99
},
10+
{
11+
"metadata": {},
12+
"cell_type": "markdown",
13+
"source": "## Plot"
14+
},
15+
{
16+
"metadata": {},
17+
"cell_type": "code",
18+
"outputs": [],
19+
"execution_count": null,
20+
"source": "from python_workflow_definition.plot import plot"
21+
},
22+
{
23+
"metadata": {},
24+
"cell_type": "code",
25+
"outputs": [],
26+
"execution_count": null,
27+
"source": "plot(file_name='workflow_simple.json')"
28+
},
1029
{
1130
"cell_type": "markdown",
1231
"metadata": {},

0 commit comments

Comments
 (0)