Skip to content

Commit

Permalink
Overloaded the from_json method in Multigraph, so that it always lo…
Browse files Browse the repository at this point in the history
…ads a graph into backend multigraph. Useful for ZXLive.
  • Loading branch information
jvdwetering committed Jan 23, 2025
1 parent 9697249 commit aa912c3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pyzx/graph/multigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import itertools
from collections import Counter
from fractions import Fraction
from typing import Tuple, Dict, Set, Any
from typing import Tuple, Dict, Set, Union, Any

from .base import BaseGraph

Expand Down Expand Up @@ -436,3 +436,10 @@ def set_vdata(self, vertex, key, val):
self._vdata[vertex][key] = val
else:
self._vdata[vertex] = {key:val}

@classmethod
def from_json(cls, js:Union[str,Dict[str,Any]]) -> 'Multigraph':
"""Converts the given .qgraph json string into a Multigraph.
Works with the output of :meth:`to_json`."""
from .jsonparser import json_to_graph
return json_to_graph(js,backend='multigraph') # type:ignore

0 comments on commit aa912c3

Please sign in to comment.