zxcalc / zxlive

A graphical tool for the ZX calculus
Apache License 2.0
51 stars 20 forks source link

Saner JSON formats #354

Closed akissinger closed 2 months ago

akissinger commented 2 months ago

Creating a PR before I merge, since this is potentially a breaking change.

Current JSON formats for proofs and rewrites have JSON containing strings containing JSON (which sometimes contain strings containing JSON containing strings containing JSON...).

Technically this works, but its a bit clunky to run the JSON parser many times to load a single file, especially if you want to consume JSON in an external tool. This branch gets rid of the nested JSON strings by splitting the old to_json method into two parts: to_dict which serialises to a python dict, then a thin wrapper to_json which just called json.dumps on the output of to_dict. Nested structures are added directly as dicts rather than strings.

The from_json will either accept a string (in which case it parses JSON first) or a python dict. Hence, ZX live can still read old-style files, but it will save in the new format.

Note this needs zxcalc/pyzx@aab09ad843d931c197f963729009853e92df0d09 .