Closed jli0108 closed 1 year ago
The optimization level 3 removes swaps at the end of a circuit or before a measurement, as they can be implemented as a classical postprocessing on the measurements. The QFT has such a final layer of swaps which is removed in optimization level 3.
You can verify the circuit is still correct, either by re-ordering the entries in the IFFT
matrix, or by re-inserting the swaps:
for i in range(4):
compiled_circuit = transpile(circuit, optimization_level=i)
# insert swaps for the check
if i == 3:
for j in range(n // 2):
compiled_circuit.swap(j, n - j - 1)
fidelity = np.abs(np.trace(Operator(compiled_circuit).to_matrix() @ np.conj(IFFT.T))) / N
print(f"(Optimization level {i}) Fidelity: {fidelity}")
if fidelity > 0.99:
print("Good.")
else:
print("Bad.")
I see, thanks for the clarification. I didn't know about this. I'll close the issue.
Environment
What is happening?
The Qiskit transpiler seems to give incorrect circuits for the QFT when the optimization level is set to 3.
How can we reproduce the issue?
Minimal working example provided here:
Output:
What should happen?
The Qiskit transpiler is supposed to give a correct circuit even if the optimization level is set to 3.
Any suggestions?
No response