Qiskit Ignis untuk Measurement Error Mitigation, Mengurangi Noise pada Hasil Komputasi Riil Quantum Device

Spread the love

Perhatikan pada tutorial Hello World sebelumnya = https://keamanansiber.id/blog/2020/05/18/hello-world-memulai-pemrograman-pada-quantum-computer/

Ada perbedaan hasil dari simulator dengan hasil komputasi pada real quantum computer.
Solusinya adalah kita terapkan Measurement Error Mitigation = https://qiskit.org/textbook/ch-quantum-hardware/measurement-error-mitigation.html

1) buka jupyter notebook, utk menjalankan komputasi di simulator laptop:

from qiskit import *
nqubits = 3
circuit = QuantumCircuit(nqubits, nqubits)
circuit.h(0)
circuit.cx(0,1)
circuit.cx(1,2)
circuit.measure([0,1,2],[0,1,2])
%matplotlib inline
circuit.draw(output=’mpl’)

simulator = Aer.get_backend(‘qasm_simulator’)
sim_result = execute(circuit, backend=simulator, shots=1024).result()
from qiskit.tools.visualization import plot_histogram
plot_histogram(sim_result.get_counts(circuit))

2) jalankan komputasi di real quantum device nya IBM:

IBMQ.load_account()
provider = IBMQ.get_provider(‘ibm-q’)
device = provider.get_backend(‘ibmqx2’)

job = execute(circuit, backend=device, shots=1024)
print(job.job_id())
from qiskit.tools.monitor import job_monitor
job_monitor(job)

device_result = job.result()
plot_histogram(device_result.get_counts(circuit))

3) Measurement Error Mitigation
Perhatikan bahwa 2 gambar histogram plot di atas sedikit berbeda.
Plot pertama = hasil simulasi Qiskit Aer di lokal laptop kita, mensimulasikan kondisi ideal komputasi tanpa error / noise.
Plot kedua = hasil komputasi di real quantum device milik IBM, ada sedikit error karena noise.

Saat ini quantum device masih dalam tahap penyempurnaan oleh tim peneliti IBM, sehingga sedikit demi sedikit noise dan error tsb akan bisa dikurangi, untuk menuju ke kondisi ideal tanpa noise dan error seperti pada simulator Aer di laptop kita.

“How small error in quantum computation introduce measurement results that take us far away from an ideal quantum computer would give us.
We use Qiskit Ignis to understand what those kinds of errors are, and to find out what the parameters involved are to generate a fitter, and then to use that fitter to generate a filter which allowed us to mitigate the errors in our measurement outcome.”
sumber YouTube = https://www.youtube.com/watch?v=yuDxHJOKsVA&list=PLOFEBzvs-Vvp2xg9-POLJhQwtVktlYGbY&index=8

Solusi utk permasalahan error/noise ini, kita buat filter untuk menyaring hasil dari komputasi di real quantum device, dengan menggunakan Qiskit Ignis:

from qiskit.ignis.mitigation.measurement import (complete_meas_cal, CompleteMeasFitter)
cal_circuits, state_labels = complete_meas_cal(qr = circuit.qregs[0], circlabel = ‘measerrormitigationcal’)
cal_circuits[2].draw(output=’mpl’)

len(cal_circuits)

cal_job = execute(cal_circuits,
backend = device,
shots = 1024,
optimization_level = 0
)
print(cal_job.job_id())
job_monitor(cal_job)
cal_results = cal_job.result()

plot_histogram(cal_results.get_counts(cal_circuits[3]))

meas_fitter = CompleteMeasFitter(cal_results, state_labels)
meas_fitter.plot_calibration()

4) di titik ini, proses fitting selesai, dan kemudian kita membuat filter, utk nanti nya bisa dipakai me mitigasi error/noise pada kalkulasi di real quantum device:

meas_filter = meas_fitter.filter

mitigated_result = meas_filter.apply(device_result)
device_counts = device_result.get_counts(circuit)
mitigated_counts = mitigated_result.get_counts(circuit)
plot_histogram([device_counts, mitigated_counts], legend=[‘device, noisy’,’device, mitigated’])

5) mari kita coba lagi filternya utk circuit baru, di simulator (kondisi ideal tanpa noise, hasil komputasi = 001 dam 110) :

circuit2 = QuantumCircuit(3,3)
circuit2.x(1)
circuit2.h(0)
circuit2.cx(0,1)
circuit2.cx(1,2)
circuit2.measure([0,1,2],[0,1,2])
circuit2.draw(output=’mpl’)

plot_histogram(
execute(circuit2, backend=simulator, shots=1024).result().get_counts(circuit2)
)

job = execute(circuit2, backend=device, shots=1024)
job_monitor(job)
device_counts2 = job.result().get_counts(circuit2)

6) Perhatikan plot diatas ada banyak noise/error, selain dari hasil simulasi pada kondisi ideal yg hanya 000 dan 110.
Mari kita coba pakai filter utk me reduksi error/noise:

job = execute(circuit2, backend=device, shots=1024)
job_monitor(job)
device_counts2 = job.result().get_counts(circuit2)

# sebelum filter
plot_histogram(device_counts2)

# sesudah filter
device_mitigated_counts_2 = meas_filter.apply(device_counts2)
plot_histogram(device_mitigated_counts_2)

Source code tersedia di GitHub = https://github.com/keamanansiber/qiskit/blob/master/1MemulaiQiskitUntukPemula/MeasurementErrorMitigation.ipynb

Berikutnya = https://keamanansiber.id/blog/2020/05/21/quantum-operations-single-qubit-gates-u-gates/

Tinggalkan Balasan

This site uses Akismet to reduce spam. Learn how your comment data is processed.