-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
291 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from networkx import DiGraph | ||
|
||
from jobflow_remote.jobs.data import FlowInfo | ||
|
||
|
||
def get_graph(flow: FlowInfo, label: str = "name") -> DiGraph: | ||
import networkx as nx | ||
|
||
graph = nx.DiGraph() | ||
|
||
ids_mapping = flow.ids_mapping | ||
|
||
# Add nodes | ||
for job_prop in flow.iter_job_prop(): | ||
db_id = job_prop["db_id"] | ||
job_prop["label"] = job_prop[label] | ||
# change this as the "name" is used in jobflow's graph plotting util | ||
job_prop["job_name"] = job_prop.pop("name") | ||
graph.add_node(db_id, **job_prop) | ||
|
||
# Add edges based on parents | ||
for child_node, parents in zip(flow.db_ids, flow.parents): | ||
for parent_uuid in parents: | ||
for parent_node in ids_mapping[parent_uuid].values(): | ||
graph.add_edge(parent_node, child_node) | ||
|
||
return graph |
Oops, something went wrong.