2

I would like to discuss the discrepancies between what we see in the simulator versus what we see in the actual running of the code on any IBMQ machine for any qubits at 5 or above. I am doing a final project on grover's algorithm, and the premise would require an extremely large number of qubits. I have tested my theory on the simulators up to 26 qubits (took 6 hours), and they are ~100% accurate. When I went to test the theory using the exact same circuit, I couldn't get a circuit of 4 qubits to even deviate from statistical random distrubution.

First of all, I have used Qiskit and Q# to create the exact same algorithm. If you could provide me with a methodology that would allow for easier work / do the work for the transpiler on qiskit, or the ability to utilize a real quantum computer in Q#, I would appreciate it.

Currently the transpiler in qiskit / IBMQ for grover's algorithm is limited to around 6-7 qubits. I don't like that I don't have more gates available. Regardless of this issue, I get garbage results for an oracle / ancilla at or larger than 4 qubits total. Why is is that the transpiler / decoherance that is occuring within the circuit is so terrible that I cannot construct Grover's algorithm using gates at or larger than 4 qubits? The probabilties of the simulators themselves are upwards of 99%, but even after a two qubit Grover's algorithm, it shows as only 40ish %?

When I go to three qubits, the entire algorithm is garbage, and I cannot provide ANY accuracy other than a random distribution, and when I tabulated it the accuracy was actually less than the statistical random distrubution. I'm not happy with what is going on here, as I cannot feasibly run anything of meaning on any IBMQ machine. I don't understand why the transpiler is inserting such a ludicrous range in the possible number of gates (about a hundred different possible gate configurations for 5 qubit Grover's algorithm)

Is this an issue with the transpiler? Is this just an issue with general decoherance? I don't understand why the quantum computer can't peform a grover's algorithm of 5 or more.

Please help me to understand what I am not getting here. Are the physical devices that far off from where I felt the technology was? I was hoping that a 15 qubit machine would be able to actually perform better, esp. in the 5 qubit realm.

#initialization
import matplotlib.pyplot as plt
import math
import numpy as np

importing Qiskit

from qiskit import ClassicalRegister, QuantumRegister from qiskit.providers.ibmq import least_busy from qiskit.quantum_info import Statevector from qiskit.providers.aer import QasmSimulator

import basic plot tools

from qiskit.visualization import plot_histogram

def initialize_s(qc,qubits): """Apply a H-gate to 'qubits' in qc""" for q in qubits: qc.h(q) return qc

def numberofiterations(nqubits): temp = 2 ** nqubits; squareRoot = math.sqrt(temp) iterations = round(squareRoot) return iterations

def oracle(nqubits): q = QuantumRegister(nqubits) qc = QuantumCircuit(q) #set the oracle's 0 bits qc.x(q[1]) qc.x(q[2]) #qc.x(q[5]) #qc.x(q[7]) #qc.x(q[8]) #qc.x(q[12]) #qc.x(q[13]) #qc.x(q[15]) #qc.x(q[19]) #qc.x(q[20]) #qc.x(q[21]) #qc.x(q[22]) #qc.x(q[24]) qc.h(q[nqubits-1]) #[0,3,4,6,9,10,11,14,16,17,18,23,26,27],30,ancilla_qubits=None, mode='noancilla') #qc.mcx([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],q[25],ancilla_qubits=None, mode='noancilla') #qc.cx([0],[1]) qc.mcx([0,1,2],q[nqubits-1],ancilla_qubits=None, mode='noancilla') qc.x(q[1]) qc.x(q[2]) #qc.x(q[5]) #qc.x(q[7]) #qc.x(q[8]) #qc.x(q[12]) #qc.x(q[13]) #qc.x(q[15]) #qc.x(q[19]) #qc.x(q[20]) #qc.x(q[21]) #qc.x(q[22]) #qc.x(q[24]) qc.h(q[nqubits-1]) #return the oracle as a gate. oracle = qc.to_gate() oracle.name = "U$_\omega$" return oracle

def diffuser(nqubits): qc = QuantumCircuit(nqubits) # Apply transformation |s> -> |00..0> (H-gates) for qubit in range(nqubits): qc.h(qubit) # Apply transformation |00..0> -> |11..1> (X-gates) for qubit in range(nqubits): qc.x(qubit) # Do multi-controlled-Z gate qc.h(nqubits-1) qc.mcx(list(range(nqubits-1)), nqubits-1) # multi-controlled-toffoli #qc.cx([0],[1]) qc.h(nqubits-1) # Apply transformation |11..1> -> |00..0> for qubit in range(nqubits): qc.x(qubit) # Apply transformation |00..0> -> |s> for qubit in range(nqubits): qc.h(qubit) # We will return the diffuser as a gate U_s = qc.to_gate() U_s.name = "$U_s$" return U_s

n = 4 qr = QuantumRegister(n-1, 'register') anc = QuantumRegister(1, 'ancilla') cr = ClassicalRegister(n-1, 'classical') grover_circuit = QuantumCircuit(qr,anc) grover_circuit = initialize_s(grover_circuit, list(range(n))) iterations = numberofiterations(n-1) for j in range(iterations ): grover_circuit.append(oracle(n), list(range(n))) grover_circuit.append(diffuser(n), list(range(n))) measure_circuit = QuantumCircuit(qr,cr) measure_circuit.measure(qr,cr) ```

glS
  • 24,708
  • 5
  • 34
  • 108
  • Grover circuits tend to be fairly deep. What is the depth of the circuit you are running? Ie circuit.depth() – Paul Nation Nov 19 '20 at 21:47
  • @JoelAnthonyCollins IBM has a detailed tutorial walking through Grover's algorithm on 2 and 3 qubits in Qiskit: https://qiskit.org/textbook/ch-algorithms/grover.html. If you're looking for help on your particular implementation, you probably need to show your circuit. – Jonathan Trousdale Nov 19 '20 at 23:31
  • The depth is Apparently 7 for a 4 qubit system, @Paul Nation – Joel Anthony Collins Nov 20 '20 at 01:54
  • @Jonathan Trousdale, I have the IBM documentation. That is the way I implemented it except for some small things here and there. I use an MCX gate instead of the CX gate, etc. The issue is not with my implementation. If you take ANY implementation above 3 qubits, it falls flat on it's face. – Joel Anthony Collins Nov 20 '20 at 01:55
  • for the above code, you just run execute([grover_circuit+measure_circuit] with whatever settings you want and then plot the histogram. This will graph only the instances where the ancilla has been triggered. and will not include the ancilla in the answer. – Joel Anthony Collins Nov 20 '20 at 02:17
  • https://quantumcomputing.stackexchange.com/questions/5747/what-is-maximum-circuit-depth-and-size-ibm-q5-and-q16-could-handle <- this is more the problem that I'm thinking is occuring, but it is happening much sooner than I expected, and wanted to discuss it. – Joel Anthony Collins Nov 20 '20 at 20:47
  • @PaulNation I believe that I tagged you incorrectly, I will delete this comment as soon as you respond. – Joel Anthony Collins Nov 20 '20 at 20:58
  • @JoelAnthonyCollins Thanks for adding the code. SE is good about white space insensitivity for tagging, so the earlier tags worked. – Jonathan Trousdale Nov 20 '20 at 21:56
  • So it definitely appears that your circuit, once compiled to a given device, is just too long to get a reasonable fidelity out. This is what I guessed because it is typical of Grover type problems. – Paul Nation Nov 22 '20 at 00:14
  • @PaulNation is there an easy way to see how many gates are in the current circuit? and is there any way to get an offical mean error per gate, so I can reference it? I had seen that at one time IBMQ experience had given that information out, but it may no longer be available? – Joel Anthony Collins Nov 22 '20 at 00:27
  • @JoelAnthonyCollins In an earlier comment you said that the depth of a 4 qubit Grover circuit is 7. But is that the depth you obtain after you transpile your circuit using the basis gates of the real backend of interest? Because in the actual backend the transpiled circuit is what is executed due to the limitations on the available gates that can be implemented on a backend. And I believe that the depth of the circuit post transpiling would be quite huge. – Tharrmashastha V Dec 24 '20 at 19:10

0 Answers0