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.23k stars 2.36k forks source link

3-qubit Grover's Algorithm Results #665

Closed wca-123 closed 6 years ago

wca-123 commented 6 years ago

Informations

What is the current behavior?

I ran a 3-qubit Grover's Algorithm searching for '111' on the ibmqx5 backend and did not get even remotely similar results to the simulated runs.

My code: image Simulated Run: image Actual Run: image

Steps to reproduce the problem

I tried 2-qubit Grover's Algorithm which worked - 0.72 probability of '11'.

What is the expected behavior?

A decently high probability of '111' whereas, in actuality, '111' had the lowest number of counts. Running it on the simulator, I got 0.9484 probability of '111' and on ibmqx5, I got 0.1035.

Suggested solutions

None.

chriseclectic commented 6 years ago

@Mystery8226 The grovers circuit is not going to run well on current hardware as it has 4 Toffoli (ccx) gates in it. Since this is not a native gate for the hardware, each of these gates is implemented on the device as 6 CNOT (cx) gates and single qubit rotations. You can see the equivalent circuits here:

q = QuantumRegister(3, name='q')
qc = QuantumCircuit(q)
qc.ccx(q[0], q[1], q[2])
circuit_drawer(qc)

is implemented as

q = QuantumRegister(3, name='q')
qc = QuantumCircuit(q)
qc.cx(q[1], q[2])
qc.tdg(q[2])
qc.cx(q[0], q[2])
qc.t(q[2])
qc.cx(q[1], q[2])
qc.tdg(q[2])
qc.cx(q[0], q[2])
qc.t(q[2])
qc.h(q[2])
qc.t(q[1])
qc.cx(q[0], q[1])
qc.t(q[1])
qc.tdg(q[1])
qc.cx(q[0], q[1])
circuit_drawer(qc)

To see why this would cause such a high error rate we can look at the gate times and T1 times of the device. The time for a CNOT gate in the Rueschlikon (ibmqx5) device is around 400ns depending on qubit pair so the grover circuit could take close to 10 microseconds to run all the pulses. T1 times for qubits in that device range 30-50 microseconds so you are already at around 25% error rate for that just from T1-relaxation alone. T1 isn't the only error present either, there are measurement errors (around 5-10% per measurement), other gate errors (around 3-5% per CNOT), and cross-talk errors for example. If you add all those together you can see why the results start to look like random noise.

wca-123 commented 6 years ago

Thank you so much for the response; I think I understand now. But also, are there any workarounds to this? If the Toffoli gate has so much error, how can I make my circuit better?

chriseclectic commented 6 years ago

You could see if you can find an equivalent circuit with fewer 2-qubit gates to implement the algorithm, and also try running it on a the Tenerife (ibmqx4) device since it has lower error rates