Skip to content

Commit

Permalink
scalar from_json
Browse files Browse the repository at this point in the history
  • Loading branch information
akissinger committed Sep 26, 2024
1 parent 68e8c68 commit 7bd65b8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pyzx/graph/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@ def to_json(self) -> str:
return json.dumps(self.to_dict())

@classmethod
def from_json(cls, s: str) -> 'Scalar':
d = json.loads(s)
def from_json(cls, s: str|dict[str,Any]) -> 'Scalar':
if isinstance(s, str):
d = json.loads(s)
else:
d = s
d["phase"] = Fraction(d["phase"])
if "phasenodes" in d:
d["phasenodes"] = [Fraction(p) for p in d["phasenodes"]]
Expand Down

0 comments on commit 7bd65b8

Please sign in to comment.