Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.24k stars 2.36k forks source link

Incorrect transpiled circuit with specific `approximation_degree` #12743

Open weucode opened 4 months ago

weucode commented 4 months ago

Environment

What is happening?

I apply a rxx gate in the circuit and transpile it with different values of approximation_degree. In both fake simulators and real quantum computers, the discrepancies of measurement are noticeable when approximation_degree ranges from 0.0 to 0.6 and from 0.7 to 1.0.

A finding that may be helpful: After debugging, I located the relevant function _synth_su4_no_dag. Different return values of this function led to the observed discrepancies in measurement results.

How can we reproduce the issue?

Program:

from math import pi

from qiskit.circuit import QuantumCircuit
from qiskit import transpile
from qiskit_ibm_runtime.fake_provider import FakeSherbrooke, FakeBrisbane, FakeManilaV2
from qiskit_ibm_runtime import QiskitRuntimeService

qc = QuantumCircuit(2)
qc.rxx(pi/2, 0, 1)
qc.measure_all()
# print(qc.draw(idle_wires=False))

backend = FakeSherbrooke()
# backend = FakeBrisbane()
# backend = FakeManilaV2()
# service = QiskitRuntimeService()
# backend = service.get_backend("ibm_sherbrooke")

transpiled_qc1 = transpile(qc, backend=backend, optimization_level = 3)
# print(transpiled_qc1.draw(idle_wires=False))
job1 = backend.run(transpiled_qc1)
print(job1.result().get_counts())

transpiled_qc2 = transpile(qc, backend=backend, optimization_level = 3, approximation_degree=0.0)
# print(transpiled_qc2.draw(idle_wires=False))
job2 = backend.run(transpiled_qc2)
print(job2.result().get_counts())

Outputs:

{'01': 8, '11': 518, '10': 9, '00': 489}
{'01': 2, '10': 12, '11': 1010}

What should happen?

The same measurement results should be output.

Any suggestions?

No response

t-imamichi commented 2 months ago

According to the documentation approximation_degree=0.0 means "maximal approximation". So, the outputs could be different to some extent. https://github.com/Qiskit/qiskit/blob/713ab38cccb7e55a40a87372a2590a5a4430fa8f/qiskit/compiler/transpiler.py#L191-L192