pyzx icon indicating copy to clipboard operation
pyzx copied to clipboard

Cannot parse quipper circuit with uncontrolled gates

Open DavideFrr opened this issue 4 years ago • 1 comments

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?

DavideFrr avatar Jun 19 '20 21:06 DavideFrr

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

jvdwetering avatar Jun 25 '20 11:06 jvdwetering

quipper-gse-example.zip

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

mhodson-rigetti avatar Sep 06 '22 08:09 mhodson-rigetti

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!

mhodson-rigetti avatar Sep 06 '22 11:09 mhodson-rigetti

Hi, I implemented your patch. Let me know if everything works as it should.

jvdwetering avatar Sep 06 '22 13:09 jvdwetering