Closed lochsh closed 1 month ago
Indeed, as of #11463, the name "qft"
is "reserved" for objects of type QFTGate
, the same way as the name "h"
is "reserved" for Hadamard gates (creating a custom gate and calling it "h"
would probably horrendously fail as well). Possibly this decision needs to be documented more clearly.
However, despite having an explicit qasm test for QFTGate
: https://github.com/Qiskit/qiskit/blob/1962704cf120499cee5f017eb21d3e217353c4d7/test/python/circuit/library/test_qft.py#L278-L287
it seems that it still does not work as I've expected.
First, in the above example, the qasm string qc_qasm
is:
OPENQASM 2.0;
include "qelib1.inc";
gate qft q0,q1,q2,q3 { h q3; cp(pi/2) q3,q2; cp(pi/4) q3,q1; cp(pi/8) q3,q0; h q2; cp(pi/2) q2,q1; cp(pi/4) q2,q0; h q1; cp(pi/2) q1,q0; h q0; swap q0,q3; swap q1,q2; }
gate qft_1563762431680 q0,q1,q2 { h q2; cp(pi/2) q2,q1; cp(pi/4) q2,q0; h q1; cp(pi/2) q1,q0; h q0; swap q0,q2; }
qreg q0[5];
qft q0[1],q0[2],q0[0],q0[4];
qft_1563762431680 q0[0],q0[1],q0[2];
h q0[0];
If the QFTGate
is special, do we really need to specify its definition in the qasm string? Do we need to have a different name for the second instance of the gate (here qft_1563762431680
)?
Second, the reconstructed circuit does not have any QFTGate
objects on it, but rather two custom gates (called qft
and qft_1563762431680
). Unfortunately, the isinstance
check in HighLevelSynthesis
plugin still fails for the gate qft
as per the original issue.
Third, we can probably remove this instance
check. Then the gate qft
will get synthesized using the plugin mechanism (disregarding whichever definition is given in the qasm), while the gate qft_1563762431680
will get synthesized using the custom definition. This asymmetry makes no sense.
@jakelishman, @Cryoris, any pointers how to best resolve these issues?
Update: we have discussed this problem between the developers, and (contrary to my previous comment) it is now fine to create custom gates called "qft".
Environment
What is happening?
If I transpile this qasm:
then I get a
TranspilerError
:backtrace
```python --------------------------------------------------------------------------- TranspilerError Traceback (most recent call last) File ~/.cache/pypoetry/virtualenvs/my-project-HV3wIkQ7-py3.10/lib/python3.10/site-packages/qiskit/transpiler/passmanager.py:464, in _replace_error.If I rename the custom gate defined in the QASM file to
qft_
, then transpilation succeeds. It seems like the name of the custom gate is colliding with qiskit's built-in QFT gate? The error does not occur in version 1.1 of qiskit.How can we reproduce the issue?
QASM file contents, assume file is called
example.qasm
Python to reproduce with qiskit 1.2:
What should happen?
Transpilation should succeed and not be dependent on the name of the custom gate, if the gate name is a valid QASM identifier.
Any suggestions?
No response