pyzx icon indicating copy to clipboard operation
pyzx copied to clipboard

Q: preconditions for 'pyzx.extract_circuit`?

Open mhlr opened this issue 3 years ago • 1 comments

What are the minimum preconditions for pyzx.extract_circuit to work? i presume equal number of inputs & outputs is the barest minimum, but I am not clear on the rest. I often get error like:

~/anaconda3/lib/python3.8/site-packages/pyzx/extract.py in filter_duplicate_cnots(cnots)
    386     """Cancels adjacent CNOT gates in a list of CNOT gates."""
    387     from .optimize import basic_optimization
--> 388     qubits = max([max(cnot.control,cnot.target) for cnot in cnots]) + 1
    389     c = Circuit(qubits)
    390     c.gates = cnots.copy() # type: ignore

ValueError: max() arg is an empty sequence

but I am tnot sure if that is a bug or if there is a problem with my graph

mhlr avatar Nov 02 '21 17:11 mhlr

Hmm, that particular one looks like a bug. But to answer your question: it is really hard to give necessary preconditions for the extraction to work, as it depends on the graph having a gflow. But in any case: all spiders should be Z-spiders and maximally fused together.

jvdwetering avatar Nov 02 '21 22:11 jvdwetering