Importing and exporting quantum circuits and ZX-diagrams¶
There are several ways to import and export circuits and ZX-diagrams in PyZX.
Importing and exporting quantum circuits¶
There are a number of standards for representing quantum circuits that are supported in PyZX. To see if PyZX supports a certain file format, just call
circuit = zx.Circuit.load("path/to/circuit.extension")
The currently supported formats are
the ASCII format of Quipper,
the simple .qc format used for representing quantum circuits in LaTex,
and the qsim format used by Google.
PyZX also offers a convenience function to construct a circuit out of a string containing QASM code using either
To convert a Circuit into a PyZX Graph (i.e. a ZX-diagram), call the method
Importing and exporting ZX-diagrams¶
A ZX-diagram in PyZX is represented as an instance of
Graph. A ZX-diagram can be loaded using the
.qgraph format that Quantomatic uses, via
from_json. It can be converted into that format using
Apart from this reversible representation, there are also several one-way translations for exporting ZX-diagrams from PyZX. A graph can be exported to GraphML format using
To export a ZX-diagram to tikz for easy importing to Latex, use
Some ZX-diagrams can be converted into an equivalent circuit. For complicated ZX-diagrams, the function
extract_circuit is supplied. For ZX-diagrams that come directly from Circuits, e.g. those produced by calling
c.to_graph for a Circuit
c, one can also use the static method
from_graph, which is more lightweight.