ข้ามไปยังเนื้อหาหลัก

แนะนำบริการ Qiskit AI-powered transpiler

เวลาใช้งาน QPU โดยประมาณ: ไม่มี (หมายเหตุ: tutorial นี้ไม่รันงานบน QPU เพราะเน้นที่การ transpilation)

พื้นหลัง

บริการ Qiskit AI-powered transpiler (QTS) นำการปรับปรุงที่ใช้ machine learning มาใช้ทั้งในขั้นตอน routing และ synthesis ผ่าน AI modes เหล่านี้ถูกออกแบบมาเพื่อแก้ข้อจำกัดของการ transpilation แบบดั้งเดิม โดยเฉพาะสำหรับ Circuit ขนาดใหญ่และ topology ของ hardware ที่ซับซ้อน

กรกฎาคม 2025 Transpiler Service ได้ถูกย้ายไปยัง IBM Quantum® Platform ใหม่และไม่มีให้บริการอีกต่อไป สำหรับข้อมูลล่าสุดเกี่ยวกับสถานะของ Transpiler Service โปรดดูที่ เอกสาร transpiler service ยังสามารถใช้ AI transpiler ในเครื่องได้ คล้ายกับการ transpilation มาตรฐานของ Qiskit เพียงแค่แทนที่ generate_preset_pass_manager() ด้วย generate_ai_pass_manager() ฟังก์ชันนี้จะสร้าง pass manager ที่รวม AI-powered routing และ synthesis passes เข้ากับ workflow การ transpilation ในเครื่องโดยตรง

คุณสมบัติหลักของ AI passes

  • Routing passes: AI-powered routing สามารถปรับเส้นทาง Qubit แบบไดนามิกตาม Circuit และ Backend เฉพาะ ลดความจำเป็นในการใช้ SWAP gates มากเกินไป

    • AIRouting: การเลือก layout และ routing ของ Circuit
  • Synthesis passes: เทคนิค AI ปรับปรุงการ decomposition ของ multi-qubit gates ให้ดีขึ้น ลดจำนวน two-qubit gates ซึ่งโดยทั่วไปมีแนวโน้มเกิดข้อผิดพลาดมากกว่า

    • AICliffordSynthesis: Clifford gate synthesis
    • AILinearFunctionSynthesis: Linear function circuit synthesis
    • AIPermutationSynthesis: Permutation circuit synthesis
    • AIPauliNetworkSynthesis: Pauli Network circuit synthesis (มีให้บริการเฉพาะใน Qiskit Transpiler Service ไม่รองรับในสภาพแวดล้อมในเครื่อง)
  • การเปรียบเทียบกับการ transpilation แบบดั้งเดิม: Transpiler มาตรฐานของ Qiskit เป็นเครื่องมือที่แข็งแกร่งซึ่งสามารถจัดการ quantum circuits ได้อย่างมีประสิทธิภาพในหลากหลายรูปแบบ อย่างไรก็ตาม เมื่อ Circuit มีขนาดใหญ่ขึ้นหรือการกำหนดค่า hardware ซับซ้อนมากขึ้น AI passes สามารถให้การปรับปรุงประสิทธิภาพเพิ่มเติมได้ ด้วยการใช้โมเดลที่เรียนรู้แล้วสำหรับ routing และ synthesis QTS จะปรับปรุง layout ของ Circuit และลด overhead สำหรับงาน quantum ที่ท้าทายหรือมีขนาดใหญ่ได้มากขึ้น

tutorial นี้ประเมิน AI modes โดยใช้ทั้ง routing และ synthesis passes เปรียบเทียบผลลัพธ์กับการ transpilation แบบดั้งเดิมเพื่อเน้นให้เห็นว่า AI มีข้อได้เปรียบด้านประสิทธิภาพในส่วนใด

สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับ AI passes ที่มีให้บริการ ดูที่ เอกสาร AI passes

ทำไมต้องใช้ AI สำหรับการ transpilation ของ quantum circuit?

เมื่อ quantum circuits มีขนาดและความซับซ้อนเพิ่มขึ้น วิธีการ transpilation แบบดั้งเดิมจะประสบปัญหาในการปรับปรุง layout และลดจำนวน gate อย่างมีประสิทธิภาพ Circuit ขนาดใหญ่ โดยเฉพาะที่มี Qubit หลายร้อยตัว สร้างความท้าทายอย่างมากต่อ routing และ synthesis เนื่องจากข้อจำกัดของอุปกรณ์ การเชื่อมต่อที่จำกัด และอัตราข้อผิดพลาดของ Qubit

นี่คือจุดที่ AI-powered transpilation มอบทางออกที่เป็นไปได้ ด้วยการใช้ประโยชน์จากเทคนิค machine learning AI-powered transpiler ใน Qiskit สามารถตัดสินใจได้ฉลาดขึ้นเกี่ยวกับ qubit routing และ gate synthesis นำไปสู่การปรับปรุง quantum circuits ขนาดใหญ่ได้ดียิ่งขึ้น

ผลการ benchmarking เบื้องต้น

กราฟแสดงประสิทธิภาพของ AI transpiler เทียบกับ Qiskit

ในการทดสอบ benchmarking AI transpiler สร้าง Circuit ที่ตื้นกว่าและมีคุณภาพสูงกว่าเมื่อเทียบกับ Qiskit transpiler มาตรฐานอย่างสม่ำเสมอ สำหรับการทดสอบเหล่านี้ เราใช้กลยุทธ์ pass manager เริ่มต้นของ Qiskit ซึ่งกำหนดค่าด้วย [generate_preset_passmanager] แม้ว่ากลยุทธ์เริ่มต้นนี้มักจะมีประสิทธิภาพดี แต่อาจประสบปัญหากับ Circuit ขนาดใหญ่หรือซับซ้อนมากขึ้น ในทางตรงกันข้าม AI-powered passes ทำให้จำนวน two-qubit gate ลดลงเฉลี่ย 24% และความลึกของ Circuit ลดลง 36% สำหรับ Circuit ขนาดใหญ่ (100+ qubits) เมื่อ transpile ไปยัง heavy-hex topology ของ IBM Quantum hardware สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ benchmarks เหล่านี้ อ้างอิงได้จาก blog นี้

tutorial นี้สำรวจประโยชน์หลักของ AI passes และวิธีเปรียบเทียบกับวิธีการแบบดั้งเดิม

# Added by doQumentation — required packages for this notebook
!pip install -q matplotlib numpy pandas qiskit qiskit-ibm-runtime qiskit-ibm-transpiler
# This cell is hidden from users;
# it just disables a linting rule.
# ruff: noqa: F811

ข้อกำหนดเบื้องต้น

ก่อนเริ่ม tutorial นี้ ตรวจสอบให้แน่ใจว่าได้ติดตั้งสิ่งต่อไปนี้แล้ว:

  • Qiskit SDK v1.0 ขึ้นไป พร้อม visualization support
  • Qiskit Runtime (pip install qiskit-ibm-runtime) v0.22 ขึ้นไป
  • Qiskit IBM® Transpiler พร้อม AI local mode (pip install 'qiskit-ibm-transpiler[ai-local-mode]')

ตั้งค่า

from qiskit import QuantumCircuit
from qiskit.circuit.library import efficient_su2, PermutationGate
from qiskit.synthesis.qft import synth_qft_full
from qiskit.circuit.random import random_circuit, random_clifford_circuit
from qiskit.transpiler import generate_preset_pass_manager, CouplingMap
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_transpiler import generate_ai_pass_manager
from qiskit.synthesis.permutation import (
synth_permutation_depth_lnn_kms,
synth_permutation_basic,
)
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import time
import logging

seed = 42

# Used for generating permutation circuits in part two for comparison
def generate_permutation_circuit(width, pattern):
circuit = QuantumCircuit(width)
circuit.append(
PermutationGate(pattern=pattern),
qargs=range(width),
)
return circuit

# Creates a Bernstein-Vazirani circuit given the number of qubits
def create_bv_circuit(num_qubits):
qc = QuantumCircuit(num_qubits, num_qubits - 1)
qc.x(num_qubits - 1)
qc.h(qc.qubits)
for i in range(num_qubits - 1):
qc.cx(i, num_qubits - 1)
qc.h(qc.qubits[:-1])
return qc

# Transpile a circuit with a given pass manager and return metrics
def transpile_with_metrics(pass_manager, circuit):
start = time.time()
qc_out = pass_manager.run(circuit)
elapsed = time.time() - start

depth_2q = qc_out.depth(lambda x: x.operation.num_qubits == 2)
gate_count = qc_out.size()

return qc_out, {
"depth_2q": depth_2q,
"gate_count": gate_count,
"time_s": elapsed,
}

# Used for collecting metrics for part 3 of synthesis methods
def synth_transpile_with_metrics(qc, pm, pattern_id, method):
start = time.time()
qc = pm.run(qc)
elapsed = time.time() - start

return {
"Pattern": pattern_id,
"Method": method,
"Depth (2Q)": qc.depth(lambda x: x.operation.num_qubits == 2),
"Gates": qc.size(),
"Time (s)": elapsed,
}

# Ignore logs like "INFO:qiskit_ibm_transpiler.wrappers.ai_local_synthesis:Running Linear Functions AI synthesis on local mode"

logging.getLogger(
"qiskit_ibm_transpiler.wrappers.ai_local_synthesis"
).setLevel(logging.WARNING)

ส่วนที่ 1. Qiskit patterns

มาดูวิธีใช้งาน AI transpiler service กับ quantum circuit แบบง่าย โดยใช้ Qiskit patterns กัน สิ่งสำคัญคือการสร้าง PassManager ด้วย generate_ai_pass_manager() แทน generate_preset_pass_manager() มาตรฐาน

ขั้นตอนที่ 1: แปลง input แบบ classical ให้เป็นปัญหา quantum

ในส่วนนี้ เราจะทดสอบ AI transpiler กับ efficient_su2 circuit ซึ่งเป็น hardware-efficient ansatz ที่ใช้กันอย่างแพร่หลาย Circuit นี้มีความเกี่ยวข้องเป็นพิเศษสำหรับ variational quantum algorithms (เช่น VQE) และงาน quantum machine learning ทำให้เป็นกรณีทดสอบที่เหมาะสมสำหรับประเมินประสิทธิภาพการ transpilation

efficient_su2 circuit ประกอบด้วยชั้นสลับกันของ single-qubit rotations และ entangling gates เช่น CNOTs ชั้นเหล่านี้ช่วยให้สำรวจ quantum state space ได้อย่างยืดหยุ่น ขณะที่ยังคง gate depth ไว้ในระดับที่จัดการได้ ด้วยการปรับปรุง Circuit นี้ เรามุ่งหมายที่จะลดจำนวน gate เพิ่มความแม่นยำ และลด noise ทำให้เป็นผู้สมัครที่ดีสำหรับทดสอบประสิทธิภาพของ AI transpiler

# For our transpilation, we will use a large circuit of 101 qubits
qc = efficient_su2(90, entanglement="circular", reps=1).decompose()

# Draw a smaller version of the circuit to get a visual representation
qc_small = efficient_su2(5, entanglement="circular", reps=1).decompose()
qc_small.draw(output="mpl")

ผลลัพธ์จาก code cell ก่อนหน้า

ขั้นตอนที่ 2: ปรับปรุงปัญหาให้เหมาะสมสำหรับการรันบน quantum hardware

เลือก Backend

สำหรับตัวอย่างนี้ เราเลือก IBM Quantum backend ที่ไม่ใช่ simulator ที่ว่างที่สุด มีการทำงานจริง และมี Qubit อย่างน้อย 100 ตัว:

หมายเหตุ: เนื่องจาก backend ที่ว่างที่สุดอาจเปลี่ยนแปลงตามเวลา อุปกรณ์ต่างกันอาจถูกเลือกในการรันแต่ละครั้ง คุณสมบัติเฉพาะของอุปกรณ์ เช่น coupling maps อาจนำไปสู่ความแตกต่างใน Circuit ที่ผ่านการ transpile แล้ว

service = QiskitRuntimeService()
backend = service.least_busy(
operational=True, simulator=False, min_num_qubits=100
)
cm = backend.coupling_map
print(f"Using backend: {backend.name}")
Using backend: ibm_torino

สร้าง AI และ traditional pass managers

เพื่อประเมินประสิทธิภาพของ AI transpiler เราจะรัน transpilation 2 ครั้ง ครั้งแรก เราจะ transpile Circuit โดยใช้ AI transpiler จากนั้น เราจะเปรียบเทียบโดย transpile Circuit เดิมโดยไม่ใช้ AI transpiler โดยใช้วิธีการแบบดั้งเดิม ทั้งสองกระบวนการ transpilation จะใช้ coupling map เดียวกันจาก backend ที่เลือก และตั้งค่า optimization level เป็น 3 เพื่อการเปรียบเทียบที่ยุติธรรม

ทั้งสองวิธีนี้สะท้อนแนวทางมาตรฐานในการสร้าง PassManager instances สำหรับการ transpile Circuit ใน Qiskit

pm_ai = generate_ai_pass_manager(
optimization_level=3,
ai_optimization_level=3,
coupling_map=cm,
include_ai_synthesis=True, # used for part 3 when comparing synthesis methods
)

pm_no_ai = generate_preset_pass_manager(
optimization_level=3,
coupling_map=cm,
seed_transpiler=seed, # note that the AI pass manager does not currently support seeding
)

Transpile Circuit และบันทึกเวลา

# Transpile using standard (non-AI) pass manager
_, metrics_no_ai = transpile_with_metrics(pm_no_ai, qc)
print(
f"Standard transpilation: Depth (2q) {metrics_no_ai['depth_2q']}, "
f"Gate count {metrics_no_ai['gate_count']}, Time {metrics_no_ai['time_s']}"
)

# Transpile using AI pass manager
_, metrics_ai = transpile_with_metrics(pm_ai, qc)
print(
f"AI transpilation : Depth (2q) {metrics_ai['depth_2q']}, "
f"Gate count {metrics_ai['gate_count']}, Time {metrics_ai['time_s']}"
)
Standard transpilation: Depth (2q) 95, Gate count 458, Time 0.04650712013244629
AI transpilation : Depth (2q) 90, Gate count 456, Time 0.9342479705810547

ในการทดสอบนี้ เราเปรียบเทียบประสิทธิภาพของ AI transpiler และวิธี transpilation มาตรฐานบน efficient_su2 circuit AI transpiler สร้าง Circuit ที่มีความลึกน้อยกว่าอย่างเห็นได้ชัด ขณะที่ยังคงจำนวน gate ที่ใกล้เคียงกัน

  • ความลึกของ Circuit: AI transpiler สร้าง Circuit ที่มี two-qubit depth น้อยกว่า เป็นที่คาดว่า AI passes ได้รับการฝึกให้ปรับปรุง depth โดยเรียนรู้รูปแบบการโต้ตอบของ Qubit และใช้ประโยชน์จาก hardware connectivity ได้อย่างมีประสิทธิภาพกว่า rule-based heuristics

  • จำนวน Gate: จำนวน gate รวมยังคงใกล้เคียงกันระหว่างสองวิธี สอดคล้องกับที่คาดไว้ เนื่องจาก SABRE-based transpilation มาตรฐานจะลด swap count อย่างชัดเจน ซึ่งเป็นตัวหลักที่ทำให้ gate overhead เพิ่มขึ้น AI transpiler จะให้ความสำคัญกับ depth โดยรวมแทน และอาจแลกเปลี่ยน gate เพิ่มเติมบางส่วนเพื่อให้ได้ execution path ที่สั้นลง

  • เวลา transpilation: AI transpiler ใช้เวลาในการรันนานกว่าวิธีมาตรฐาน เนื่องจากค่าใช้จ่ายด้านการคำนวณเพิ่มเติมจากการเรียกใช้โมเดลที่เรียนรู้แล้วในระหว่าง routing และ synthesis ในทางตรงกันข้าม SABRE-based transpiler นั้นเร็วกว่ามากหลังจากที่ถูกเขียนใหม่และปรับปรุงใน Rust ซึ่งให้ heuristic routing ที่มีประสิทธิภาพสูงในระดับขนาดใหญ่

สิ่งสำคัญที่ต้องทราบคือผลลัพธ์เหล่านี้อ้างอิงจาก Circuit เพียงหนึ่งตัว เพื่อให้เข้าใจอย่างครบถ้วนว่า AI transpiler เปรียบเทียบกับวิธีการแบบดั้งเดิมอย่างไร จำเป็นต้องทดสอบกับ Circuit หลากหลายประเภท ประสิทธิภาพของ QTS อาจแตกต่างกันมากขึ้นอยู่กับประเภทของ Circuit ที่กำลังปรับปรุง สำหรับการเปรียบเทียบที่ครอบคลุมมากขึ้น อ้างอิง benchmarks ข้างต้นหรือเยี่ยมชม blog

ขั้นตอนที่ 3: รันโดยใช้ Qiskit primitives

เนื่องจาก tutorial นี้เน้นที่การ transpilation จึงไม่มีการรันการทดลองบนอุปกรณ์ quantum เป้าหมายคือการใช้ประโยชน์จากการปรับปรุงใน Step 2 เพื่อให้ได้ Circuit ที่ผ่านการ transpile แล้วที่มี depth หรือจำนวน gate ลดลง

ขั้นตอนที่ 4: Post-process และส่งคืนผลลัพธ์ในรูปแบบ classical ที่ต้องการ

เนื่องจากไม่มีการรันใน notebook นี้ จึงไม่มีผลลัพธ์ที่ต้องทำ post-process

ส่วนที่ 2. วิเคราะห์และ benchmark Circuit ที่ผ่านการ transpile แล้ว

ในส่วนนี้ เราจะสาธิตวิธีวิเคราะห์ Circuit ที่ผ่านการ transpile แล้วและ benchmark เปรียบเทียบกับเวอร์ชันต้นฉบับอย่างละเอียดมากขึ้น เราจะเน้นที่ metrics เช่น circuit depth จำนวน gate และเวลา transpilation เพื่อประเมินประสิทธิภาพของการปรับปรุง นอกจากนี้ เราจะหารือว่าผลลัพธ์อาจแตกต่างกันอย่างไรในหลายประเภท Circuit เพื่อให้เข้าใจประสิทธิภาพโดยรวมของ transpiler ในสถานการณ์ต่างๆ

# Circuits to benchmark
seed = 42
circuits = [
{
"name": "Random",
"qc": random_circuit(num_qubits=30, depth=10, seed=seed),
},
{
"name": "Clifford",
"qc": random_clifford_circuit(
num_qubits=40, num_gates=200, seed=seed
),
},
{
"name": "QFT",
"qc": synth_qft_full(num_qubits=20, do_swaps=False).decompose(),
},
{
"name": "BV",
"qc": create_bv_circuit(40),
},
]

results = []

# Run the transpilation for each circuit and store the results
for circuit in circuits:
qc_no_ai, metrics_no_ai = transpile_with_metrics(pm_no_ai, circuit["qc"])
qc_ai, metrics_ai = transpile_with_metrics(pm_ai, circuit["qc"])

print("Completed transpilation for", circuit["name"])

results.append(
{
"Circuit": circuit["name"],
"Depth 2Q (No AI)": metrics_no_ai["depth_2q"],
"Gate Count (No AI)": metrics_no_ai["gate_count"],
"Time (No AI)": metrics_no_ai["time_s"],
"Depth 2Q (AI)": metrics_ai["depth_2q"],
"Gate Count (AI)": metrics_ai["gate_count"],
"Time (AI)": metrics_ai["time_s"],
}
)

df = pd.DataFrame(results)
df
Completed transpilation for Random
Completed transpilation for Clifford
Completed transpilation for QFT
Completed transpilation for BV
Circuit  Depth 2Q (No AI)  Gate Count (No AI)  Time (No AI)  \
0 Random 37 221 0.039347
1 Clifford 36 232 0.036633
2 QFT 165 924 0.077458
3 BV 65 155 0.024993

Depth 2Q (AI) Gate Count (AI) Time (AI)
0 24 181 0.773718
1 43 267 1.097431
2 130 913 3.660771
3 70 155 0.345522

เปอร์เซ็นต์การลดลงเฉลี่ยสำหรับแต่ละ metric ค่าบวกคือการปรับปรุง ค่าลบคือการถดถอย

# Average reduction from non-AI to AI transpilation as a percentage
avg_reduction_depth = (
(df["Depth 2Q (No AI)"] - df["Depth 2Q (AI)"]).mean()
/ df["Depth 2Q (No AI)"].mean()
* 100
)
avg_reduction_gates = (
(df["Gate Count (No AI)"] - df["Gate Count (AI)"]).mean()
/ df["Gate Count (No AI)"].mean()
* 100
)
avg_reduction_time = (
(df["Time (No AI)"] - df["Time (AI)"]).mean()
/ df["Time (No AI)"].mean()
* 100
)

print(f"Average reduction in depth: {avg_reduction_depth:.2f}%")
print(f"Average reduction in gate count: {avg_reduction_gates:.2f}%")
print(f"Average reduction in transpilation time: {avg_reduction_time:.2f}%")
Average reduction in depth: 11.88%
Average reduction in gate count: 1.04%
Average reduction in transpilation time: -3193.95%
fig, axs = plt.subplots(1, 3, figsize=(21, 6))
df.plot(
x="Circuit",
y=["Depth 2Q (No AI)", "Depth 2Q (AI)"],
kind="bar",
ax=axs[0],
)
axs[0].set_title("Circuit Depth Comparison")
axs[0].set_ylabel("Depth")
axs[0].set_xlabel("Circuit")
axs[0].tick_params(axis="x", rotation=45)
df.plot(
x="Circuit",
y=["Gate Count (No AI)", "Gate Count (AI)"],
kind="bar",
ax=axs[1],
)
axs[1].set_title("Gate Count Comparison")
axs[1].set_ylabel("Gate Count")
axs[1].set_xlabel("Circuit")
axs[1].tick_params(axis="x", rotation=45)
df.plot(x="Circuit", y=["Time (No AI)", "Time (AI)"], kind="bar", ax=axs[2])
axs[2].set_title("Time Comparison")
axs[2].set_ylabel("Time (seconds)")
axs[2].set_xlabel("Circuit")
axs[2].tick_params(axis="x", rotation=45)
fig.suptitle(
"Benchmarking AI transpilation vs Non-AI transpilation for various circuits"
)

plt.tight_layout()
plt.show()

ผลลัพธ์จาก code cell ก่อนหน้า

ประสิทธิภาพของ AI transpiler แตกต่างกันอย่างมีนัยสำคัญตามประเภทของ Circuit ที่กำลังปรับปรุง ในบางกรณี มันบรรลุการลดลงอย่างเห็นได้ชัดใน circuit depth และจำนวน gate เมื่อเทียบกับ transpiler มาตรฐาน อย่างไรก็ตาม การปรับปรุงเหล่านี้มักมาพร้อมกับการเพิ่มขึ้นอย่างมีนัยสำคัญของ runtime

สำหรับ Circuit บางประเภท AI transpiler อาจให้ผลลัพธ์ที่ดีกว่าเล็กน้อยในแง่ของ circuit depth แต่อาจนำไปสู่การเพิ่มขึ้นของจำนวน gate และบทลงโทษด้าน runtime อย่างมีนัยสำคัญ การสังเกตเหล่านี้บ่งชี้ว่าประโยชน์ของ AI transpiler ไม่เหมือนกันสำหรับ Circuit ทุกประเภท แต่ประสิทธิภาพของมันขึ้นอยู่กับลักษณะเฉพาะของ Circuit ทำให้เหมาะสมกว่าสำหรับ use cases บางอย่างมากกว่าอื่นๆ

เมื่อไหรควรเลือกใช้การ Transpile แบบ AI?

Transpiler ที่ขับเคลื่อนด้วย AI ใน Qiskit โดดเด่นในสถานการณ์ที่วิธีการ Transpile แบบดั้งเดิมทำได้ยาก โดยเฉพาะกับ Circuit ควอนตัมขนาดใหญ่และซับซ้อน สำหรับ Circuit ที่มี Qubit หลายร้อยตัว หรือ Circuit ที่ต้องการฮาร์ดแวร์ที่มี coupling map ซับซ้อน AI Transpiler ให้การปรับแต่งที่ดีกว่าในแง่ความลึกของ Circuit จำนวน Gate และประสิทธิภาพ runtime ในการทดสอบ benchmarking มันทำได้เหนือกว่าวิธีการแบบดั้งเดิมอย่างสม่ำเสมอ ให้ Circuit ที่ตื้นกว่าอย่างมีนัยสำคัญและลดจำนวน Gate ซึ่งเป็นสิ่งสำคัญสำหรับการเพิ่มประสิทธิภาพและลดสัญญาณรบกวนบนฮาร์ดแวร์ควอนตัมจริง

ผู้ใช้ควรพิจารณา Transpile แบบ AI เมื่อทำงานกับ:

  • Circuit ขนาดใหญ่ที่วิธีการแบบดั้งเดิมไม่สามารถจัดการขนาดได้อย่างมีประสิทธิภาพ
  • Topology ของฮาร์ดแวร์ที่ซับซ้อน ซึ่งมีปัญหาเรื่องการเชื่อมต่อและ routing ของอุปกรณ์
  • แอปพลิเคชันที่ต้องการประสิทธิภาพสูง ที่การลดความลึกของ Circuit และการปรับปรุง fidelity มีความสำคัญสูงสุด

ส่วนที่ III. สำรวจการสังเคราะห์ permutation network แบบ AI

Permutation network เป็นรากฐานสำคัญในการคอมพิวเตอร์ควอนตัม โดยเฉพาะสำหรับระบบที่ถูกจำกัดด้วย topology แบบจำกัด เครือข่ายเหล่านี้ช่วยให้การปฏิสัมพันธ์ระยะไกลทำได้โดยการสลับ Qubit แบบ dynamic เพื่อจำลองการเชื่อมต่อแบบ all-to-all บนฮาร์ดแวร์ที่มีการเชื่อมต่อจำกัด การแปลงเช่นนี้จำเป็นสำหรับการนำ algorithm ควอนตัมซับซ้อนไปใช้บนอุปกรณ์ near-term ที่การปฏิสัมพันธ์มักครอบคลุมเกินเพื่อนบ้านที่ใกล้ที่สุด

ในส่วนนี้ เราเน้นการสังเคราะห์ permutation network เป็นกรณีการใช้งานที่น่าสนใจสำหรับ AI Transpiler ใน Qiskit โดยเฉพาะ pass AIPermutationSynthesis ใช้การปรับแต่งแบบ AI เพื่อสร้าง Circuit ที่มีประสิทธิภาพสำหรับงาน qubit permutation ในทางตรงกันข้าม วิธีการสังเคราะห์ทั่วไปมักมีปัญหาในการสมดุลจำนวน Gate และความลึกของ Circuit โดยเฉพาะในสถานการณ์ที่มีการปฏิสัมพันธ์ Qubit หนาแน่น หรือเมื่อพยายามให้ได้การเชื่อมต่อแบบเต็ม

เราจะผ่านตัวอย่าง Qiskit patterns ที่แสดงการสังเคราะห์ permutation network เพื่อให้ได้การเชื่อมต่อแบบ all-to-all สำหรับชุด Qubit เราจะเปรียบเทียบประสิทธิภาพของ AIPermutationSynthesis กับวิธีการสังเคราะห์มาตรฐานใน Qiskit ตัวอย่างนี้จะแสดงให้เห็นว่า AI Transpiler ปรับแต่งเพื่อความลึก Circuit และจำนวน Gate ที่น้อยลงได้อย่างไร โดยเน้น ข้อดีในกระบวนการ workflow ควอนตัมจริง เพื่อเปิดใช้งาน AI synthesis pass เราจะใช้ฟังก์ชัน generate_ai_pass_manager() โดยตั้งค่า parameter include_ai_synthesis เป็น True

ขั้นตอนที่ 1: แมป input แบบ classical ไปยังปัญหาควอนตัม

เพื่อแทนปัญหา permutation แบบ classical บนคอมพิวเตอร์ควอนตัม เราเริ่มด้วยการกำหนดโครงสร้างของ Circuit ควอนตัม สำหรับตัวอย่างนี้:

  1. การเริ่มต้น Circuit ควอนตัม: เราจัดสรร 27 Qubit เพื่อให้ตรงกับ Backend ที่จะใช้ ซึ่งมี 27 Qubit

  2. ใช้ permutation: เราสร้างรูปแบบ permutation แบบสุ่มสิบแบบ (pattern_1 ถึง pattern_10) โดยใช้ seed ที่กำหนดไว้เพื่อให้ผลลัพธ์ซ้ำได้ รูปแบบ permutation แต่ละอัน ถูกใช้กับ Circuit ควอนตัมแยกกัน (qc_1 ถึง qc_10)

  3. การ decompose Circuit: การดำเนินการ permutation แต่ละอันถูก decompose เป็น native gate set ที่เข้ากันได้กับฮาร์ดแวร์ควอนตัมเป้าหมาย เราวิเคราะห์ความลึกและจำนวน two-qubit gate (nonlocal gate) สำหรับแต่ละ Circuit ที่ถูก decompose

ผลลัพธ์ให้ข้อมูลเชิงลึกเกี่ยวกับความซับซ้อนของการแทนปัญหา permutation แบบ classical บนอุปกรณ์ควอนตัม โดยแสดงให้เห็นถึงความต้องการทรัพยากรสำหรับรูปแบบ permutation ต่างๆ

# Parameters
width = 27
num_circuits = 10

# Set random seed
np.random.seed(seed)

# Generate random patterns and circuits
patterns = [
np.random.permutation(width).tolist() for _ in range(num_circuits)
]
circuits = {
f"qc_{i}": generate_permutation_circuit(width, pattern)
for i, pattern in enumerate(patterns, start=1)
}

# Display one of the circuits
circuits["qc_1"].decompose(reps=3).draw(output="mpl", fold=-1)

Output of the previous code cell

ขั้นตอนที่ 2: ปรับแต่งปัญหาสำหรับการรันบนฮาร์ดแวร์ควอนตัม

ในขั้นตอนนี้ เราดำเนินการปรับแต่งโดยใช้ AI synthesis pass

สำหรับ AI synthesis pass นั้น PassManager ต้องการเพียง coupling map ของ Backend อย่างไรก็ตามสิ่งสำคัญที่ต้องทราบคือไม่ใช่ทุก coupling map ที่เข้ากันได้ เฉพาะ coupling map ที่ pass AIPermutationSynthesis ได้รับการฝึกมาเท่านั้นที่จะใช้งานได้ ปัจจุบัน pass AIPermutationSynthesis รองรับบล็อกขนาด 65, 33 และ 27 Qubit สำหรับตัวอย่างนี้เราใช้ QPU ขนาด 27 Qubit

เพื่อการเปรียบเทียบ เราจะประเมินประสิทธิภาพของ AI synthesis เทียบกับวิธีการสังเคราะห์ permutation ทั่วไปใน Qiskit ซึ่งรวมถึง:

  • synth_permutation_depth_lnn_kms: วิธีนี้สังเคราะห์ permutation Circuit สำหรับ architecture linear nearest-neighbor (LNN) โดยใช้ algorithm Kutin, Moulton, และ Smithline (KMS) รับประกัน Circuit ที่มีความลึกไม่เกิน nn และขนาดไม่เกิน n(n1)/2n(n-1)/2 โดยทั้งความลึกและขนาดวัดเป็น SWAP Gate

  • synth_permutation_basic: นี่คือการนำไปใช้งานแบบตรงไปตรงมาที่สังเคราะห์ permutation Circuit โดยไม่มีข้อจำกัดเรื่อง connectivity หรือการปรับแต่งสำหรับ architecture เฉพาะ ทำหน้าที่เป็น baseline สำหรับเปรียบเทียบประสิทธิภาพกับวิธีการขั้นสูงกว่า

แต่ละวิธีเหล่านี้แสดงถึงแนวทางที่แตกต่างกันในการสังเคราะห์ permutation network ให้ benchmark ที่ครอบคลุมเทียบกับวิธีการขับเคลื่อนด้วย AI

สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับวิธีการสังเคราะห์ใน Qiskit ดูที่ Qiskit API documentation กำหนด coupling map ที่แทน QPU ขนาด 27 Qubit

coupling_map = [
[1, 0],
[2, 1],
[3, 2],
[3, 5],
[4, 1],
[6, 7],
[7, 4],
[7, 10],
[8, 5],
[8, 9],
[8, 11],
[11, 14],
[12, 10],
[12, 13],
[12, 15],
[13, 14],
[16, 14],
[17, 18],
[18, 15],
[18, 21],
[19, 16],
[19, 22],
[20, 19],
[21, 23],
[23, 24],
[25, 22],
[25, 24],
[26, 25],
]
CouplingMap(coupling_map).draw()

Output of the previous code cell

Transpile แต่ละ permutation Circuit โดยใช้ AI synthesis pass และวิธีการสังเคราะห์ทั่วไป

results = []
pm_no_ai_synth = generate_preset_pass_manager(
coupling_map=cm,
optimization_level=1, # set to 1 since we are using the synthesis methods
)

# Transpile and analyze all circuits
for i, (qc_name, qc) in enumerate(circuits.items(), start=1):
pattern = patterns[i - 1] # Get the corresponding pattern

qc_depth_lnn_kms = synth_permutation_depth_lnn_kms(pattern)
qc_basic = synth_permutation_basic(pattern)

# AI synthesis
results.append(
synth_transpile_with_metrics(
qc.decompose(reps=3),
pm_ai,
qc_name,
"AI",
)
)

# Depth-LNN-KMS Method
results.append(
synth_transpile_with_metrics(
qc_depth_lnn_kms.decompose(reps=3),
pm_no_ai_synth,
qc_name,
"Depth-LNN-KMS",
)
)

# Basic Method
results.append(
synth_transpile_with_metrics(
qc_basic.decompose(reps=3),
pm_no_ai_synth,
qc_name,
"Basic",
)
)

results_df = pd.DataFrame(results)

บันทึก metric (ความลึก จำนวน Gate เวลา) สำหรับแต่ละ Circuit หลังการ Transpile

# Calculate averages for each metric
average_metrics = results_df.groupby("Method")[
["Depth (2Q)", "Gates", "Time (s)"]
].mean()
average_metrics = average_metrics.round(3) # Round to two decimal places
print("\n=== Average Metrics ===")
print(average_metrics)

# Identify the best non-AI method based on least average depth
non_ai_methods = [
method for method in results_df["Method"].unique() if method != "AI"
]
best_non_ai_method = average_metrics.loc[non_ai_methods][
"Depth (2Q)"
].idxmin()
print(
f"\nBest Non-AI Method (based on least average depth): {best_non_ai_method}"
)

# Compare AI to the best non-AI method
ai_metrics = average_metrics.loc["AI"]
best_non_ai_metrics = average_metrics.loc[best_non_ai_method]

comparison = {
"Metric": ["Depth (2Q)", "Gates", "Time (s)"],
"AI": [
ai_metrics["Depth (2Q)"],
ai_metrics["Gates"],
ai_metrics["Time (s)"],
],
best_non_ai_method: [
best_non_ai_metrics["Depth (2Q)"],
best_non_ai_metrics["Gates"],
best_non_ai_metrics["Time (s)"],
],
"Improvement (AI vs Best Non-AI)": [
ai_metrics["Depth (2Q)"] - best_non_ai_metrics["Depth (2Q)"],
ai_metrics["Gates"] - best_non_ai_metrics["Gates"],
ai_metrics["Time (s)"] - best_non_ai_metrics["Time (s)"],
],
}

comparison_df = pd.DataFrame(comparison)
print("\n=== Comparison of AI vs Best Non-AI Method ===")
comparison_df
=== Average Metrics ===
Depth (2Q) Gates Time (s)
Method
AI 23.9 82.8 0.248
Basic 29.8 91.0 0.012
Depth-LNN-KMS 70.8 531.6 0.017

Best Non-AI Method (based on least average depth): Basic

=== Comparison of AI vs Best Non-AI Method ===
Metric      AI   Basic  Improvement (AI vs Best Non-AI)
0 Depth (2Q) 23.900 29.800 -5.900
1 Gates 82.800 91.000 -8.200
2 Time (s) 0.248 0.012 0.236

ผลลัพธ์แสดงให้เห็นว่า AI Transpiler ทำได้เหนือกว่าวิธีการสังเคราะห์อื่นๆ ทั้งหมดใน Qiskit สำหรับชุด permutation Circuit แบบสุ่มนี้ ข้อค้นพบสำคัญได้แก่:

  1. ความลึก: AI Transpiler ได้ความลึกเฉลี่ยต่ำสุด แสดงถึงการปรับแต่ง layout Circuit ที่เหนือกว่า
  2. จำนวน Gate: ลดจำนวน Gate ได้อย่างมีนัยสำคัญเมื่อเทียบกับวิธีอื่น ปรับปรุง fidelity และประสิทธิภาพการรัน
  3. เวลา Transpile: ทุกวิธีทำงานได้เร็วมากในระดับนี้ ทำให้ใช้งานจริงได้ อย่างไรก็ตาม AI Transpiler มีเวลา runtime เพิ่มขึ้นอย่างเห็นได้ชัดเมื่อเทียบกับวิธีการแบบดั้งเดิม เนื่องจากความซับซ้อนของ AI model ที่ใช้

ผลลัพธ์เหล่านี้ยืนยันว่า AI Transpiler เป็นแนวทางที่มีประสิทธิภาพที่สุดสำหรับ benchmark นี้ โดยเฉพาะในการปรับแต่งความลึกและจำนวน Gate พล็อตผลลัพธ์เพื่อเปรียบเทียบประสิทธิภาพของ AI synthesis pass กับวิธีการสังเคราะห์ทั่วไป

methods = results_df["Method"].unique()

fig, axs = plt.subplots(1, 3, figsize=(18, 5))

# Pivot the DataFrame and reorder columns to ensure AI is first
pivot_depth = results_df.pivot(
index="Pattern", columns="Method", values="Depth (2Q)"
)[["AI", "Depth-LNN-KMS", "Basic"]]
pivot_gates = results_df.pivot(
index="Pattern", columns="Method", values="Gates"
)[["AI", "Depth-LNN-KMS", "Basic"]]
pivot_time = results_df.pivot(
index="Pattern", columns="Method", values="Time (s)"
)[["AI", "Depth-LNN-KMS", "Basic"]]

pivot_depth.plot(kind="bar", ax=axs[0], legend=False)
axs[0].set_title("Circuit Depth Comparison")
axs[0].set_ylabel("Depth")
axs[0].set_xlabel("Pattern")
axs[0].tick_params(axis="x", rotation=45)
pivot_gates.plot(kind="bar", ax=axs[1], legend=False)
axs[1].set_title("2Q Gate Count Comparison")
axs[1].set_ylabel("Number of 2Q Gates")
axs[1].set_xlabel("Pattern")
axs[1].tick_params(axis="x", rotation=45)
pivot_time.plot(
kind="bar", ax=axs[2], legend=True, title="Legend"
) # Show legend on the last plot
axs[2].set_title("Time Comparison")
axs[2].set_ylabel("Time (seconds)")
axs[2].set_xlabel("Pattern")
axs[2].tick_params(axis="x", rotation=45)
fig.suptitle(
"Benchmarking AI Synthesis Methods vs Non-AI Synthesis Methods For Random Permutations Circuits",
fontsize=16,
y=1,
)

plt.tight_layout()
plt.show()

Output of the previous code cell

กราฟนี้แสดงผลลัพธ์รายบุคคลสำหรับแต่ละ Circuit (qc_1 ถึง qc_10) ในวิธีการสังเคราะห์ต่างๆ:

แม้ว่าผลลัพธ์เหล่านี้จะย้ำถึงประสิทธิภาพของ AI Transpiler สำหรับ permutation Circuit แต่สิ่งสำคัญคือต้องทราบข้อจำกัดของมัน วิธีการสังเคราะห์แบบ AI ในปัจจุบันมีให้ใช้งานเฉพาะกับ coupling map บางอย่างเท่านั้น ซึ่งอาจจำกัดการนำไปใช้ในวงกว้าง ข้อจำกัดนี้ควรพิจารณาเมื่อประเมินการใช้งานในสถานการณ์ต่างๆ

โดยรวม AI Transpiler แสดงให้เห็นการปรับปรุงที่น่าสัญญาในการปรับแต่งความลึกและจำนวน Gate สำหรับ Circuit เฉพาะเหล่านี้ ขณะที่ยังคงเวลา Transpile ที่ใกล้เคียงกัน

ขั้นตอนที่ 3: รันโดยใช้ Qiskit primitives

เนื่องจากบทแนะนำนี้เน้นที่การ Transpile จึงไม่มีการรันการทดลองบนอุปกรณ์ควอนตัม เป้าหมายคือการใช้การปรับแต่งจากขั้นตอนที่ 2 เพื่อให้ได้ Circuit ที่ผ่าน Transpile แล้วที่มีความลึกหรือจำนวน Gate ที่น้อยลง

ขั้นตอนที่ 4: Post-process และคืนผลลัพธ์ในรูปแบบ classical ที่ต้องการ

เนื่องจากไม่มีการรันสำหรับ notebook นี้ จึงไม่มีผลลัพธ์ที่ต้อง post-process

แบบสอบถามของบทแนะนำ

Link to survey

Note: This survey is provided by IBM Quantum and relates to the original English content. To give feedback on doQumentation's website, translations, or code execution, please open a GitHub issue.

กรุณาทำแบบสอบถามสั้นๆ นี้เพื่อให้ feedback เกี่ยวกับบทแนะนำนี้ ข้อมูลของคุณจะช่วยให้เราปรับปรุงเนื้อหาและประสบการณ์ผู้ใช้ของเรา

Source: IBM Quantum docs — updated 27 เม.ย. 2569
English version on doQumentation — updated 7 พ.ค. 2569
This translation based on the English version of 9 เม.ย. 2569