Skip to content

Commit

Permalink
Fixed wrongly loading auto_simplify value
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdwetering committed Jan 21, 2025
1 parent 06eb82f commit 5cc673f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyzx/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def from_json(cls, js:Union[str,Dict[str,Any]]) -> BaseGraph[VT,ET]:
"""Converts the given .qgraph json string into a Graph.
Works with the output of :meth:`to_json`."""
from .jsonparser import json_to_graph
return json_to_graph(js, backend=cls.backend)
return json_to_graph(js)

@classmethod
def from_tikz(cls, tikz: str, warn_overlap:bool= True, fuse_overlap:bool = True, ignore_nonzx:bool = False) -> BaseGraph[VT,ET]:
Expand Down
3 changes: 2 additions & 1 deletion pyzx/graph/jsonparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ def dict_to_graph(d: Dict[str,Any], backend: Optional[str]=None) -> BaseGraph:
if g.backend == 'multigraph':
if TYPE_CHECKING:
assert isinstance(g, Multigraph)
g.set_auto_simplify(d.get('auto_simplify', True))
b = True if d.get('auto_simplify', True) in ('true', True) else False
g.set_auto_simplify(b)
for v_d in d['vertices']:
pos = v_d['pos']
v = v_d['id']
Expand Down
8 changes: 8 additions & 0 deletions tests/test_jsonparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,16 @@ def test_load_multigraph_preserve_parallel_edges(self):

d = g.to_dict()
g2 = Graph.from_json(d)
self.assertTrue(g2.backend,'multigraph')
self.assertFalse(g2.get_auto_simplify())
self.assertEqual(g.num_edges(), g2.num_edges())

js = json.dumps(d)
g3 = Graph.from_json(js)
self.assertTrue(g3.backend,'multigraph')
self.assertFalse(g3.get_auto_simplify())
self.assertEqual(g.num_edges(), g3.num_edges())

def test_load_json_old_format(self):
js = json.dumps(test_graph_old_format)
g = Graph.from_json(js)
Expand Down

0 comments on commit 5cc673f

Please sign in to comment.