Skip to content

Commit

Permalink
Copy graph more efficiently
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCBrammer committed Dec 23, 2024
1 parent 3368ebe commit 6fec3e4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tucan/canonicalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ def get_refinement_tree_node_children(m: nx.Graph) -> Generator[nx.Graph, None,
continue

# Split target partition.
m_artificially_split = m.copy()
m_artificially_split = (
nx.Graph()
) # Instantiate a new graph instead of using m.copy() to improve performance.
m_artificially_split.add_nodes_from(m.nodes(data=True))
m_artificially_split.add_edges_from(m.edges(data=True))
nx.set_node_attributes(
m_artificially_split,
{atom: n_partitions}, # Partitions are zero-based.
PARTITION,
)
m_artificially_split.graph["n_partitions"] = n_partitions + 1

m_artificially_refined = list(refine_partitions(m_artificially_split))[-1]

yield m_artificially_refined
Expand Down

0 comments on commit 6fec3e4

Please sign in to comment.