Skip to content

Commit b7fb607

Browse files
authored
Add plotting function (#54)
* Add plotting function * Plot notebooks * add empty line at the end of environment
1 parent 12a7a03 commit b7fb607

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
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
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import json
2+
3+
from IPython.display import SVG, display
4+
import networkx as nx
5+
6+
7+
from python_workflow_definition.purepython import group_edges
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:
20+
content = json.load(f)
21+
22+
graph = nx.DiGraph()
23+
node_dict = convert_nodes_list_to_dict(nodes_list=content[NODES_LABEL])
24+
total_lst = group_edges(edges_lst=content[EDGES_LABEL])
25+
26+
for node_id, node_name in node_dict.items():
27+
graph.add_node(node_id, name=str(node_name), label=str(node_name))
28+
29+
for edge_tuple in total_lst:
30+
target_node, edge_dict = edge_tuple
31+
edge_label_dict = {}
32+
for k, v in edge_dict.items():
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)
37+
else:
38+
edge_label_dict[v[SOURCE_LABEL]].append(v[SOURCE_PORT_LABEL] + "=" + k)
39+
for k, v in edge_label_dict.items():
40+
graph.add_edge(str(k), str(target_node), label=", ".join(v))
41+
42+
svg = nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")
43+
display(SVG(svg))

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)