After several atempts, I cannot mitigate the error when running the code on a NISQ, via the qiskit library (more specifically on the 'ibmq_16_melbourne').
I've already mapped the connected qubits and simplified my circuit to the basic gates accepted by the backend.
The code is as it follows:
from qiskit import *
from qiskit.circuit.library.standard_gates import HGate
from qiskit.circuit.library import QFT, WeightedAdder
from qiskit.visualization import plot_histogram
def qft_dagger(qc, n):
"""n-qubit QFTdagger the first n qubits in circ"""
# Don't forget the Swaps!
for qubit in range(n//2):
qc.swap(qubit, n-qubit-1)
for j in range(n):
for m in range(j):
qc.cp(-math.pi/float(2**(j-m)), m, j)
qc.h(j)
IBMQ.load_account()
provider = IBMQ.get_provider('ibm-q')
#backend = Aer.get_backend('qasm_simulator')
shots = 8192
#INFO CIRC
nCountingQ = 3
w = 3.8
#LISTS
tempo = []
eigenvalues = []
allCircs = []
#DEF TEMPO
t0 = 0
tmax = 2
nrInvervalos = 70
deltaT = tmax/nrInvervalos
t = t0
qr = QuantumRegister(4,'qr')
cr = ClassicalRegister(3,'cr')
#CICLO
while t<tmax:
circ = QuantumCircuit(qr,cr)
theta = 2*w*t
#HADAMARD
for i in range(nCountingQ):
circ.h(i)
#UNITARY
repetitions = 1
for counting_qubit in range(nCountingQ):
for i in range(repetitions):
circ.rz(theta/2,nCountingQ)
circ.cx(counting_qubit,nCountingQ)
circ.rz(-theta/2,nCountingQ)
circ.cx(counting_qubit,nCountingQ)
repetitions *= 2
#QFT
qft_dagger(circ,nCountingQ)
#MEASUREMENT
for i in range(nCountingQ):
circ.measure(i,i)
#ATUALIZAR TEMPOS
tempo.append(t)
t+=deltaT
#ADICIONAR CIRC A TODOS
allCircs.append(circ)
And I execute the code with the following command:
job = execute(allCircs, backend = backend, shots = shots, initial_layout={qr[0]:4, qr[1]:9, qr[2]:11, qr[3]:10})
Finally, I process the data with a weighted average:
answer = job.result().get_counts()
#MEDIA PESADA
for x in answer:
#print(x)
numerador = 0
denominador = 0
for key,value in x.items():
key = int(key,2)
numerador += (key/2**nCountingQ)*value
denominador += value
media_pesada = numerador/denominador
eigenvalues.append(media_pesada)
The results I should've be obtaining are:
But what I'm consistently obtaining is (extremely random):
Unfortunaly, I couldn't find the correct information to help me mitigate this specific errors
Thank you for your time!