Plot graph to graph.png in canonize_and_save_graph after setting planar positions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+14
-1
@@ -1,4 +1,4 @@
|
||||
"""Utilities for canonizing and saving colored graphs."""
|
||||
"""Utilities for canonizing and saving graphs."""
|
||||
import base64
|
||||
import tempfile
|
||||
from collections import defaultdict
|
||||
@@ -53,6 +53,19 @@ def plot_colored_graph_to_data_uri(g: Graph, coloring: VertexColoring) -> str:
|
||||
return f"data:image/png;base64,{base64.b64encode(png_bytes).decode()}"
|
||||
|
||||
|
||||
def canonize_and_save_graph(g: Graph) -> Graph:
|
||||
"""Canonize g, save to data/graphs/<graph_id>/graph.sobj, and return the canonical graph."""
|
||||
canonical = cast(Graph, g.canonical_label())
|
||||
graph_id = base64.urlsafe_b64encode(canonical.graph6_string().encode()).decode()
|
||||
out_dir = DIR / "data" / "graphs" / graph_id
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
print(graph_id)
|
||||
canonical.is_planar(set_embedding=True, set_pos=True)
|
||||
canonical.plot().save(out_dir / 'graph.png')
|
||||
save(canonical, str(out_dir / 'graph'))
|
||||
return canonical
|
||||
|
||||
|
||||
def save_colored_graph(g: Graph, coloring: VertexColoring) -> tuple[Graph, VertexColoring, ColoredGraphId]:
|
||||
"""
|
||||
Canonize g and coloring, save to disk, and return the canonical forms with id.
|
||||
|
||||
Reference in New Issue
Block a user