-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transpiled circuit with optimization level 3 is not equivalent to the original circuit #7961
Comments
Thanks for the report! This particular case is the exact same behaviour that causes #7341, where discussion seems to have stalled a little bit. The trick is that the synthesis routines in the transpiler have some approximations turned on by default (whether or not they should be doing that is another question...). You can work around the issue by setting For others, a more minimal reproducer of the error: import qiskit
from qiskit.test.mock import FakeLagos
import numpy as np
backend = FakeLagos()
circuit = qiskit.QuantumCircuit(2)
for i in range(4):
circuit.rz(3*np.pi/4, 1)
circuit.sx(1)
circuit.cnot(0,1)
approximate = qiskit.transpile(circuit, backend=backend, optimization_level=3, approximation_degree=None)
exact = qiskit.transpile(circuit, backend=backend, optimization_level=3, approximation_degree=0)
def reduce_circuit(circuit):
"""Quick hack to reduce a larger circuit to the minimal set of qubits."""
active_qubits = set()
for _, qargs, _ in circuit.data:
active_qubits.update(qargs)
bit_map = {bit: i for i, bit in enumerate(active_qubits)}
out = qiskit.QuantumCircuit(len(bit_map))
out.global_phase = circuit.global_phase
for op, qargs, _ in circuit.data:
out.append(op, [bit_map[q] for q in qargs], [])
return out
approximate = reduce_circuit(approximate)
exact = reduce_circuit(exact) You can then see that (using |
Thanks Jake! Setting the I would suggest that by default it should always be set to zero until the issue is resolved. Incorrect transpilation on a 5 CNOT 2Q circuit sounds like a bad default setting. |
Since this is already tacked by #8043, closing. Thanks @pranavm1502 ! |
Informations
Qiskit version:
{'qiskit-terra': '0.19.2', 'qiskit-aer': '0.10.3', 'qiskit-ignis': '0.7.0', 'qiskit-ibmq-provider': '0.18.3', 'qiskit-aqua': None, 'qiskit': '0.34.2', 'qiskit-nature': None, 'qiskit-finance': None, 'qiskit-optimization': None, 'qiskit-machine-learning': None}
Python version:
Python 3.10
Operating system:
Mac OS Monterey 12.3.1
What is the current behavior?
Transpiled 2qubit circuit with optimization level 3 is not equivalent to the original circuit
Steps to reproduce the problem
Look at the attached jupyter notebook
Qiskit transpiler level 3 investigation.ipynb.zip
What is the expected behavior?
The result outputs should be same (upto shot noise).
Suggested solutions
The text was updated successfully, but these errors were encountered: