07ad553568
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
938 B
Python
25 lines
938 B
Python
import hashlib
|
|
from typing import Any, TypedDict
|
|
from sage.all import Graph # type: ignore[attr-defined] # pylint: disable=no-name-in-module
|
|
from lib.colored_graphs import ColoredGraphId, VertexColoring
|
|
|
|
class Operation(TypedDict):
|
|
"""Information about a change made to a (colored) graph"""
|
|
name: Any
|
|
meta: Any
|
|
source_graph: Graph
|
|
source_canon_id: ColoredGraphId
|
|
result_graph: Graph
|
|
result_coloring: VertexColoring
|
|
result_canon_id: ColoredGraphId
|
|
|
|
def colored_graph_id_to_string(cid: ColoredGraphId) -> str:
|
|
return f"{cid['graph_id']} {cid['coloring_id']}"
|
|
|
|
def operation_to_string(op: Operation) -> str:
|
|
return f"{colored_graph_id_to_string(op['source_canon_id'])} -> {colored_graph_id_to_string(op['result_canon_id'])}"
|
|
|
|
def operation_sequence_id(ops: list[Operation]) -> str:
|
|
joined = "\n".join(operation_to_string(op) for op in ops)
|
|
return hashlib.sha256(joined.encode()).hexdigest()
|