pyzx
pyzx copied to clipboard
Cannot parse quipper circuit with uncontrolled gates
I found my self needing to convert circuits that were generated within the quipper framework, to the qasm format. The problem is that in those circuits, gates with no controls do not end with the "nocontrol" keyword, thus raising an exception.
Is this a real issue or are those circuits wrongly written?
Were these circuits generated by Quipper? Could you give me some examples? I have never used Quipper myself, and only built the parser to work with the circuits I needed to, but if Quipper sometimes produces circuits without the "nocontrol" keyword, then I could just modify the parser
I have attached an example of a Quipper output from the Ground State Estimation application. In addition to omitting the "nocontrol" keyword, Quipper circuits may omit declaration of the qubits up front, which causes a parse failure (as the loader is looking for a colon-separated string of qubits). Both issues can be resolved with a fairly simple patch. I'll aim to provide one.
Reference for the source Quipper GSE algorithm:
https://www.mathstat.dal.ca/~selinger/quipper/doc/Quipper-Algorithms-GSE-Main.html
46-fix-parse-quipper-nocontrol.zip
@jvdwetering - Here is a patch for the minimal change set to support the absence of "nocontrol", and also to support other Quipper commands including QMeas, QDiscard. Includes a test that compares the internal qubits and gate list for a version of test_circuit.circuit
modified for the additional commands (but otherwise logically the same).
Would it be possible for you to stage this on a branch, so we can depend on it, and consider it for release?
Thanks!
Hi, I implemented your patch. Let me know if everything works as it should.