qiskit-community / qiskit-ignis

Ignis (deprecated) provides tools for quantum hardware verification, noise characterization, and error correction.
Apache License 2.0
167 stars 160 forks source link

Server is always down when performing error mitigation on the device of ibmq_16_melbourne #468

Closed cyx617 closed 4 years ago

cyx617 commented 4 years ago

Informations

The experiment was performed on the jupyter notebook from Quantum Lab of IBM Quantum Experience website, so the above information is for the remote server.

What is the current behavior?

I was trying to perform error mitigation for circuits with a large number of qubits on the device of ibmq_16_melbourne. But the maximum number of experiments this device supports is 75, which is much smaller than the number of experiments required in my case (e.g., 16384 for 14 qubits). So I designed a function to split the experiments into multiple jobs and update the measurement correction fitter batch by batch. Here is the code:

#Importing standard Qiskit libraries and configuring account
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
#Loading your IBM Q account(s)
provider = IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q')
device = provider.get_backend('ibmq_16_melbourne')

import qiskit
from qiskit import QuantumCircuit,QuantumRegister
from qiskit.ignis.mitigation.measurement import (complete_meas_cal,CompleteMeasFitter)

def error_mitigation(qubit_nb,batch_size):
    qr = QuantumRegister(qubit_nb)
    meas_calibs, state_labels = complete_meas_cal(qr=qr, circlabel='mcal')
    circ_nb = len(meas_calibs)
    print("Total experiments : %d" % (circ_nb))
    # Initialize the measurement correction fitter with the first batch of calibration circuits
    job_res_first_batch = qiskit.execute(meas_calibs[0:batch_size], backend=device, shots=1024,optimization_level=0).result()
    meas_fitter = CompleteMeasFitter(job_res_first_batch, state_labels, circlabel='mcal')
    print("Finished experiment %d to %d" % (0,batch_size))
    # Update the measurement correction fitter with other batchs of calibration circuits
    for i in range (batch_size,batch_size*(circ_nb//batch_size),batch_size):
        job_res_temp = qiskit.execute(meas_calibs[i:(i+batch_size)], backend=device, shots=1024,optimization_level=0).result()
        meas_fitter.add_data(new_results=job_res_temp)
        print("Finished experiment %d to %d" % (i,i + batch_size))
    # Update the measurement correction fitter with the last batch
    # if the total number of calibration circuits can not be devided by exactly batch_size
    if circ_nb%batch_size != 0:
        last_batch_size = circ_nb%batch_size
        job_res_last_batch = qiskit.execute(meas_calibs[-last_batch_size:], backend=device, shots=1024,optimization_level=0).result()
        meas_fitter.add_data(new_results=job_res_last_batch)
        print("Finished the last %d experiments" % (last_batch_size))
    return meas_fitter

meas_fitter = error_mitigation(15,75)

The first parameter qubit_nb of the error_mitigation function represents the amount of qubits to include in the circuit and the second one batch_size is the number of experiments per job. I used this code to run experiments for circuits with 4, 8, 12, and even 14 qubits, and they were all successful. However, when I tried the circuits for 15 qubits, the server was always down, as shown in the image below image where the warning message says the service seems to be down but it will restart immediately (I got this message in Chinese perhaps due to my location. Sorry for any inconvenience.) I don't know if this is due to an overloaded server or some other reason.

Steps to reproduce the problem

What is the expected behavior?

The code should in principle work for circuits with arbitrary number of qubits.

Suggested solutions

ShellyGarion commented 4 years ago

We appreciate very much your interest in ignis, however it does not seem that the issue is with the measurement mitigation code in ignis. Did you try to ask your question in qiskit-ignis slack channel: https://app.slack.com/client/T7RSPHKK2 ? Did you try to run your code using a QasmSimulator backend, see: https://qiskit.org/documentation/tutorials/noise/3_measurement_error_mitigation.html

cyx617 commented 4 years ago

@ShellyGarion Thanks for you reply:smiley:. I've tried the qasm_simulator as shown in the qiskit tutorial and it worked well. But when I run the code using a real device such as ibmq_16_melbourne backend, it didn't work for the circuit with 15 qubits. Yes, I think there should not be the issue with the measurement mitigation code in ignis. I'm guessing the problem is perhaps due to the server or system workload. I haven't asked this question in qiskit-ignis slack channel. But I can have a try.

ShellyGarion commented 4 years ago

Since it does not seem to be an issue with the ignis code (as it's running well on a simulator) - I'll close this issue. Please post your question in the slack channels: either qiskit-ignis or general or ibm-q-systems. Thanks!