Skip to content

Commit aa912c3

Browse files
committed
Overloaded the from_json method in Multigraph, so that it always loads a graph into backend multigraph. Useful for ZXLive.
1 parent 9697249 commit aa912c3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pyzx/graph/multigraph.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import itertools
1818
from collections import Counter
1919
from fractions import Fraction
20-
from typing import Tuple, Dict, Set, Any
20+
from typing import Tuple, Dict, Set, Union, Any
2121

2222
from .base import BaseGraph
2323

@@ -436,3 +436,10 @@ def set_vdata(self, vertex, key, val):
436436
self._vdata[vertex][key] = val
437437
else:
438438
self._vdata[vertex] = {key:val}
439+
440+
@classmethod
441+
def from_json(cls, js:Union[str,Dict[str,Any]]) -> 'Multigraph':
442+
"""Converts the given .qgraph json string into a Multigraph.
443+
Works with the output of :meth:`to_json`."""
444+
from .jsonparser import json_to_graph
445+
return json_to_graph(js,backend='multigraph') # type:ignore

0 commit comments

Comments
 (0)