Skip to content

Commit

Permalink
allow parser to accept python dict
Browse files Browse the repository at this point in the history
  • Loading branch information
akissinger committed Sep 26, 2024
1 parent 4b160f6 commit 68e8c68
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pyzx/graph/jsonparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ def _new_var(name: str) -> Poly:
except Exception as e:
raise ValueError(e)

def json_to_graph(js: str, backend:Optional[str]=None) -> BaseGraph:
def json_to_graph(js: str|dict[str,Any], backend:Optional[str]=None) -> BaseGraph:
"""Converts the json representation of a .qgraph Quantomatic graph into
a pyzx graph."""
j = json.loads(js, cls=ComplexDecoder)
a pyzx graph. If JSON is given as a string, parse it first."""
if isinstance(js, str):
j = json.loads(js, cls=ComplexDecoder)
else:
j = js
g = Graph(backend)
g.variable_types = j.get('variable_types',{})

Expand Down

0 comments on commit 68e8c68

Please sign in to comment.