การ Benchmark แบบ Real-time เพื่อเลือก Qubit
ประมาณการใช้งาน: 4 นาทีบน Eagle r2 processor (หมายเหตุ: นี่เป็นเพียงการประมาณเท่านั้น เวลาจริงอาจแตกต่างกัน)
# Added by doQumentation — required packages for this notebook
!pip install -q matplotlib numpy qiskit qiskit-experiments qiskit-ibm-runtime rustworkx
# This cell is hidden from users – it disables some lint rules
# ruff: noqa: E722
พื้นหลัง
บทแนะนำนี้แสดงวิธีรันการทดลอง characterization แบบ real-time และอัปเดต backend properties เพื่อปรับปรุงการเลือก Qubit เมื่อแมป Circuit ไปยัง physical qubit บน QPU คุณจะได้เรียนรู้การทดลอง characterization พื้นฐานที่ใช้กำหนด properties ของ QPU วิธีทำสิ่งเหล่านี้ใน Qiskit และวิธีอัปเดต properties ที่บันทึกไว้ใน backend object ที่แทน QPU ตามผลการทดลอง
QPU-reported properties จะอัปเดตวันละครั้ง แต่ระบบอาจเปลี่ยนแปลงเร็วกว่าช่วงเวลาระหว่างการอัปเดต สิ่งนี้อาจส่งผลต่อความน่าเชื่อถือของ qubit selection routines ในขั้นตอน Layout ของ pass manager เนื่องจากใช้ reported properties ที่ไม่สะท้อนสถานะปัจจุบันของ QPU ด้วยเหตุนี้ อาจคุ้มค่าที่จะใช้เวลา QPU บางส่วนไปกับการทดลอง characterization ซึ่งสามารถนำมาใช้อัปเดต QPU properties ที่ใช้โดย Layout routine ได้
สิ่งที่ต้องมี
ก่อนเริ่มบทแนะนำนี้ ตรวจสอบให้แน่ใจว่าติดตั้งสิ่งต่อไปนี้แล้ว:
- Qiskit SDK v2.0 หรือใหม่กว่า พร้อมรองรับ visualization
- Qiskit Runtime v0.40 หรือใหม่กว่า (
pip install qiskit-ibm-runtime) - Qiskit Experiments v0.12 หรือใหม่กว่า (
pip install qiskit-experiments) - Rustworkx graph library (
pip install rustworkx)
ตั้งค่า
from qiskit_ibm_runtime import SamplerV2
from qiskit.transpiler import generate_preset_pass_manager
from qiskit.quantum_info import hellinger_fidelity
from qiskit.transpiler import InstructionProperties
from qiskit_experiments.library import (
T1,
T2Hahn,
LocalReadoutError,
StandardRB,
)
from qiskit_experiments.framework import BatchExperiment, ParallelExperiment
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import Session
from datetime import datetime
from collections import defaultdict
import numpy as np
import rustworkx
import matplotlib.pyplot as plt
import copy
ขั้นตอนที่ 1: แมป input แบบ classical ไปยังปัญหา quantum
เพื่อ benchmark ความแตกต่างด้านประสิทธิภาพ เราพิจารณา Circuit ที่เตรียม Bell state ข้าม linear chain ที่มีความยาวต่างกัน โดยวัด fidelity ของ Bell state ที่ปลายทั้งสองของ chain
from qiskit import QuantumCircuit
ideal_dist = {"00": 0.5, "11": 0.5}
num_qubits_list = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 127]
circuits = []
for num_qubits in num_qubits_list:
circuit = QuantumCircuit(num_qubits, 2)
circuit.h(0)
for i in range(num_qubits - 1):
circuit.cx(i, i + 1)
circuit.barrier()
circuit.measure(0, 0)
circuit.measure(num_qubits - 1, 1)
circuits.append(circuit)
circuits[-1].draw(output="mpl", style="clifford", fold=-1)


ตั้งค่า Backend และ coupling map
ก่อนอื่น เลือก Backend
# To run on hardware, select the backend with the fewest number of jobs in the queue
service = QiskitRuntimeService()
backend = service.least_busy(
operational=True, simulator=False, min_num_qubits=127
)
qubits = list(range(backend.num_qubits))
จากนั้นดึง coupling map ของมัน
coupling_graph = backend.coupling_map.graph.to_undirected(multigraph=False)
# Get unidirectional coupling map
one_dir_coupling_map = coupling_graph.edge_list()
เพื่อ benchmark two-qubit Gate ให้ได้มากที่สุดพร้อมกัน เราแยก coupling map ออกเป็น layered_coupling_map object นี้ประกอบด้วยรายการของ layer โดยแต่ละ layer คือรายการ edge ที่สามารถรัน two-qubit Gate พร้อมกันได้ วิธีนี้เรียกอีกอย่างว่า edge coloring ของ coupling map
# Get layered coupling map
edge_coloring = rustworkx.graph_bipartite_edge_color(coupling_graph)
layered_coupling_map = defaultdict(list)
for edge_idx, color in edge_coloring.items():
layered_coupling_map[color].append(
coupling_graph.get_edge_endpoints_by_index(edge_idx)
)
layered_coupling_map = [
sorted(layered_coupling_map[i])
for i in sorted(layered_coupling_map.keys())
]
การทดลอง Characterization
มีการใช้ชุดการทดลองเพื่อ characterize คุณสมบัติหลักของ Qubit ใน QPU ซึ่งได้แก่ , , readout error และ single-qubit กับ two-qubit gate error เราจะสรุปสั้น ๆ ว่าคุณสมบัติเหล่านี้คืออะไร และอ้างอิงการทดลองใน package qiskit-experiments ที่ใช้ characterize สิ่งเหล่านี้
T1
คือเวลาลักษณะที่ใช้สำหรับ Qubit ที่ถูกกระตุ้นให้ตกกลับสู่ ground state เนื่องจากกระบวนการ decoherence แบบ amplitude-damping ใน การทดลอง เราวัด Qubit ที่ถูกกระตุ้นหลังจากหน่วงเวลา ยิ่งหน่วงเวลานานขึ้น Qubit ก็ยิ่งมีโอกาสตกลงสู่ ground state มากขึ้น เป้าหมายของการทดลองคือ characterize อัตราการ decay ของ Qubit ไปยัง ground state
T2
แสดงถึ งช่วงเวลาที่ Bloch vector projection ของ Qubit เดี่ยวบนระนาบ XY ลดลงเหลือประมาณ 37% () ของ amplitude เริ่มต้น เนื่องจากกระบวนการ decoherence แบบ dephasing ใน การทดลอง Hahn Echo เราสามารถประมาณอัตราการ decay นี้ได้
การ characterize ความผิดพลาด State preparation and measurement (SPAM)
ใน การทดลอง characterize ความผิดพลาด SPAM Qubit จะถูกเตรียมในสถานะหนึ่ง ( หรือ ) และวัด ความน่าจะเป็นของการวัดสถานะที่ต่างจากสถานะที่เตรียมไว้จะให้ความน่าจะเป็นของความผิดพลาด
Randomized benchmarking สำหรับ single-qubit และ two-qubit
Randomized benchmarking (RB) เป็น protocol ยอดนิยมสำหรับ characterize อัตราความผิดพลาดของ quantum processor การทดลอง RB ประกอบด้วยการสร้า ง random Clifford Circuit บน Qubit ที่กำหนด โดย unitary ที่ Circuit คำนวณได้คือ identity หลังจากรัน Circuit นับจำนวน shot ที่เกิดความผิดพลาด (นั่นคือ output ที่แตกต่างจาก ground state) และจากข้อมูลนี้สามารถอนุมานประมาณการความผิดพลาดสำหรับอุปกรณ์ quantum ได้โดยการคำนวณ Error Per Clifford
# Create T1 experiments on all qubit in parallel
t1_exp = ParallelExperiment(
[
T1(
physical_qubits=[qubit],
delays=[1e-6, 20e-6, 40e-6, 80e-6, 200e-6, 400e-6],
)
for qubit in qubits
],
backend,
analysis=None,
)
# Create T2-Hahn experiments on all qubit in parallel
t2_exp = ParallelExperiment(
[
T2Hahn(
physical_qubits=[qubit],
delays=[1e-6, 20e-6, 40e-6, 80e-6, 200e-6, 400e-6],
)
for qubit in qubits
],
backend,
analysis=None,
)
# Create readout experiments on all qubit in parallel
readout_exp = LocalReadoutError(qubits)
# Create single-qubit RB experiments on all qubit in parallel
singleq_rb_exp = ParallelExperiment(
[
StandardRB(
physical_qubits=[qubit], lengths=[10, 100, 500], num_samples=10
)
for qubit in qubits
],
backend,
analysis=None,
)
# Create two-qubit RB experiments on the three layers of disjoint edges of the heavy-hex
twoq_rb_exp_batched = BatchExperiment(
[
ParallelExperiment(
[
StandardRB(
physical_qubits=pair,
lengths=[10, 50, 100],
num_samples=10,
)
for pair in layer
],
backend,
analysis=None,
)
for layer in layered_coupling_map
],
backend,
flatten_results=True,
analysis=None,
)
QPU properties ตามช่วงเวลา
เมื่อดู reported QPU properties ตามช่วงเวลา (เราจะพิจารณาช่วงหนึ่งสัปดาห์ด้านล่าง) จะเห็นว่าสิ่งเหล่านี ้สามารถผันผวนได้ในระดับวันเดียว ความผันผวนเล็กน้อยอาจเกิดขึ้นได้แม้ภายในวันเดียวกัน ในสถานการณ์นี้ reported properties (อัปเดตวันละครั้ง) จะไม่สะท้อนสถานะปัจจุบันของ QPU ได้อย่างแม่นยำ ยิ่งกว่านั้น หาก job ถูก transpile ในเครื่อง (โดยใช้ reported properties ปัจจุบัน) แล้ว submit แต่รันในภายหลัง (ไม่ว่าจะเป็นนาทีหรือวัน) ก็อาจเสี่ยงที่จะใช้ properties ที่ล้าสมัยในการเลือก Qubit ระหว่างขั้นตอน transpilation สิ่งนี้แสดงให้เห็นถึงความสำคัญของการมีข้อมูลที่อัปเดตเกี่ยวกับ QPU ณ เวลาที่รัน ก่อนอื่น มาดึง properties ในช่วงเวลาหนึ่งกัน
instruction_2q_name = "cz" # set the name of the default 2q of the device
errors_list = []
for day_idx in range(10, 17):
calibrations_time = datetime(
year=2025, month=8, day=day_idx, hour=0, minute=0, second=0
)
targer_hist = backend.target_history(datetime=calibrations_time)
t1_dict, t2_dict = {}, {}
for qubit in range(targer_hist.num_qubits):
t1_dict[qubit] = targer_hist.qubit_properties[qubit].t1
t2_dict[qubit] = targer_hist.qubit_properties[qubit].t2
errors_dict = {
"1q": targer_hist["sx"],
"2q": targer_hist[f"{instruction_2q_name}"],
"spam": targer_hist["measure"],
"t1": t1_dict,
"t2": t2_dict,
}
errors_list.append(errors_dict)
จากนั้น มา plot ค่าต่าง ๆ กัน
fig, axs = plt.subplots(5, 1, figsize=(10, 20), sharex=False)
# Plot for T1 values
for qubit in range(targer_hist.num_qubits):
t1s = []
for errors_dict in errors_list:
t1_dict = errors_dict["t1"]
try:
t1s.append(t1_dict[qubit] / 1e-6)
except:
print(f"missing t1 data for qubit {qubit}")
axs[0].plot(t1s)
axs[0].set_title("T1")
axs[0].set_ylabel(r"Time ($\mu s$)")
axs[0].set_xlabel("Days")
# Plot for T2 values
for qubit in range(targer_hist.num_qubits):
t2s = []
for errors_dict in errors_list:
t2_dict = errors_dict["t2"]
try:
t2s.append(t2_dict[qubit] / 1e-6)
except:
print(f"missing t2 data for qubit {qubit}")
axs[1].plot(t2s)
axs[1].set_title("T2")
axs[1].set_ylabel(r"Time ($\mu s$)")
axs[1].set_xlabel("Days")
# Plot SPAM values
for qubit in range(targer_hist.num_qubits):
spams = []
for errors_dict in errors_list:
spam_dict = errors_dict["spam"]
spams.append(spam_dict[tuple([qubit])].error)
axs[2].plot(spams)
axs[2].set_title("SPAM Errors")
axs[2].set_ylabel("Error Rate")
axs[2].set_xlabel("Days")
# Plot 1Q Gate Errors
for qubit in range(targer_hist.num_qubits):
oneq_gates = []
for errors_dict in errors_list:
oneq_gate_dict = errors_dict["1q"]
oneq_gates.append(oneq_gate_dict[tuple([qubit])].error)
axs[3].plot(oneq_gates)
axs[3].set_title("1Q Gate Errors")
axs[3].set_ylabel("Error Rate")
axs[3].set_xlabel("Days")
# Plot 2Q Gate Errors
for pair in one_dir_coupling_map:
twoq_gates = []
for errors_dict in errors_list:
twoq_gate_dict = errors_dict["2q"]
twoq_gates.append(twoq_gate_dict[pair].error)
axs[4].plot(twoq_gates)
axs[4].set_title("2Q Gate Errors")
axs[4].set_ylabel("Error Rate")
axs[4].set_xlabel("Days")
plt.subplots_adjust(hspace=0.5)
plt.show()

จะเห็นได้ว่าในช่วงหลายวัน คุณสมบัติบางอย่างของ Qubit อาจเปลี่ยนแปลงได้อย่างมีนัยสำคัญ สิ่งนี้แสดงให้เห็นถึงความสำคัญของการมีข้อมูลที่สดใหม่เกี่ยวกับสถานะ QPU เพื่อให้สามารถเลือก Qubit ที่ทำงานได้ดีที่สุดสำหรับการทดลอง