Optimization Solver: A Qiskit Function by Q-CTRL Fire Opal
Qiskit Functions เป็นฟีเจอร์ทดลองที่ใช้ได้เฉพาะผู้ใช้ IBM Quantum® Premium Plan, Flex Plan และ On-Prem (ผ่าน IBM Quantum Platform API) Plan เท่านั้น อยู่ในสถานะพรีวิวและอาจมีการเปลี่ยนแปลงได้
Package versions
The code on this page was developed using the following requirements. We recommend using these versions or newer.
qiskit-ibm-runtime~=0.46.1
sympy~=1.14.0
ภาพรวม
ด้วย Fire Opal Optimization Solver คุณสามารถแก้ปัญหา optimization ระดับ utility-scale บน quantum hardware ได้โดยไม่ต้องมีความเชี่ยวชาญด้านควอนตัม แค่ป้อนนิยามปัญหาระดับสูงเข้าไป แล้ว Solver จะดูแลส่วนที่เหลือทั้งหมด กระบวนการทำงานทั้งหมดรับรู้ noise และใช้ประโยชน์จาก Fire Opal's Performance Management ภายใต้ฝาครอบ Solver ให้ผลลัพธ์ที่แม่นยำสม่ำเสมอสำหรับปัญหาที่ท้าทายสำหรับคอมพิวเตอร์คลาสสิก แม้กระทั่งในระดับ full-device บน IBM® QPU ที่ใหญ่ที่สุด
Solver มีความยืดหยุ่นและสามารถใช้แก้ปัญหา combinatorial optimization ที่นิยามเป็น objective functions หรือ arbitrary graphs ปัญหาไม่จำเป็นต้องถูก map ลงบน device topology ทั้งปัญหาที่ไม่มีข้อจำกัดและมีข้อจำกัดสามารถแก้ได้ โดยขอให้ข้อจำกัดนั้นสามารถเขียนเป็น penalty terms ได้ ตัวอย่างในคู่มือนี้แสดงวิธีแก้ปัญหา optimization ระดับ utility-scale ทั้งแบบมีและไม่มีข้อจำกัด โดยใช้ input type ของ Solver ต่างกัน ตัวอย่างแรกเป็นปัญหา max-cut บน graph แบบ 3-Regular 156 nodes ส่วนตัวอย่างที่สองจัดการกับปัญหา Minimum Vertex Cover ขนาด 50 nodes ที่นิยามด้วย cost function
หากต้องการเข้าถึง Optimization Solver ติดต่อ Q-CTRL
รายละเอียดฟังก์ชัน
Solver ปรับแต่งและทำให้ algorithm ทั้งหมดทำงานอัตโนมัติอย่างสมบูรณ์ ตั้งแต่การกดสัญญาณรบกวนในระดับ hardware ไปจนถึงการ mapping ปัญหาที่มีประสิทธิภาพและ closed-loop classical optimization เบื้องหลัง pipeline ของ Solver ลด error ในทุกขั้นตอน ช่วยให้ performance ที่ดีขึ้นที่จำเป็นต่อการ scale อย่างมีความหมาย กระบวนการทำงานพื้นฐานได้แรงบันดาลใจจาก Quantum Approximate Optimization Algorithm (QAOA) ซึ่งเป็น hybrid quantum-classical algorithm สำหรับสรุปรายละเอียดเต็มของกระบวนการ Optimization Solver ทั้งหมด ดูที่ บทความที่ตีพิมพ์แล้ว
ในการแก้ปัญหาทั่วไปด้วย Optimization Solver:
- นิยามปัญหาของคุณเป็น objective function, graph, หรือ
SparsePauliOpspin chain - เชื่อมต่อกับฟังก์ชันผ่าน Qiskit Functions Catalog
- รันปัญหากับ Solver และดึงผลลัพธ์
รูปแบบปัญหาที่รองรับ
- การแสดงผลด้วย Polynomial expression ของ objective function ควรสร้างใน Python ด้วย SymPy Poly object และ format เป็น string โดยใช้ sympy.srepr
- การแสดงผลด้วย Graph ของ problem type เฉพาะ ควรสร้าง graph โดยใช้ library networkx ใน Python แล้วแปลงเป็น string ด้วยฟังก์ชัน networkx
[nx.readwrite.json_graph.adjacency_data](http://nx.readwrite.json_graph.adjacency_data.) - การแสดงผลด้วย Spin chain ของปัญหาเฉพาะ ควรแสดงเป็น
SparsePauliOpobject ดู เอกสารประกอบ สำหรับรายละเอียดเพิ่มเติม
หากต้องการใช้ Backend ที่ฟังก์ชันนี้ยังไม่รองรับในปัจจุบัน ติดต่อ Q-CTRL เพื่อเพิ่มการรองรับ
Benchmarks
ผลลัพธ์ benchmarking ที่ตีพิมพ์แล้ว แสดงให้เห็นว่า Solver แก้ปัญหาที่มีมากกว่า 120 Qubit ได้สำเร็จ แม้กระทั่งมีประสิทธิภาพเหนือกว่าผลลัพธ์ที่ตีพิมพ์ก่อนหน้าบน quantum annealing และ trapped-ion devices ตัวชี้วัด benchmark ต่อไปนี้ให้ข้อบ่งชี้คร่าวๆ ของความแม่นยำและการ scale ของ problem types จากตัวอย่างบางส่วน ตัวชี้วัดจริงอาจแตกต่างกันตามคุณสมบัติต่างๆ ของปัญหา เช่น จำนวน terms ใน objective function (density) และ locality จำนวน variables และ polynomial order
"Number of qubits" ที่ระบุไม่ใช่ข้อจำกัดแบบ hard limit แต่แสดงถึงค่า threshold คร่าวๆ ที่คุณคาดว่าจะได้ความแม่นยำของ solution ที่สม่ำเสมอมาก ปัญหาขนาดใหญ่กว่านี้ได้รับการแก้สำเร็จมาแล้ว และสนับสนุนให้ทดสอบเกินขอบเขตเหล่านี้
รองรับ qubit connectivity แบบ arbitrary ในทุก problem types
| ประเภทปัญหา | จำนวน Qubit | ตัวอย่าง | ความแม่นยำ | เวลาทั้งหมด (s) | การใช้งาน Runtime (s) | จำนวน iteration |
|---|---|---|---|---|---|---|
| ปัญหา quadratic แบบ sparsely-connected | 156 | 3-regular max-cut | 100% | 1764 | 293 | 16 |
| Higher-order binary optimization | 156 | Ising spin-glass model | 100% | 1461 | 272 | 16 |
| ปัญหา quadratic แบบ densely-connected | 50 | Fully-connected max-cut | 100% | 1758 | 268 | 12 |
| ปัญหาแบบ constrained ด้วย penalty terms | 50 | Weighted Minimum Vertex Cover กับ edge density 8% | 100% | 1074 | 215 | 10 |
เริ่มต้นใช้งาน
ก่อนอื่น ยืนยันตัวตนโดยใช้ IBM Quantum API key จากนั้นเลือก Qiskit Function ดังนี้ (snippet นี้สมมติว่าคุณได้ บันทึกบัญชีของคุณ ไว้ใน local environment แล้ว)
# Added by doQumentation — required packages for this notebook
!pip install -q networkx numpy qiskit-ibm-catalog qiskit-ibm-runtime sympy
from qiskit_ibm_catalog import QiskitFunctionsCatalog
catalog = QiskitFunctionsCatalog(channel="ibm_quantum_platform")
# Access Function
solver = catalog.load("q-ctrl/optimization-solver")
ตัวอย่าง: Unconstrained optimization
รันปัญหา maximum cut (Max-Cut) ตัวอย่างต่อไปนี้แสดงความสามารถของ Solver บนปัญหา Max-Cut graph แบบ unweighted 3-regular ขนาด 156 nodes แต่คุณยังสามารถแก้ปัญหา weighted graph ได้เช่นกัน
นอกจาก qiskit-ibm-catalog แล้ว คุณยังต้องใช้ packages ต่อไปนี้ในการรันตัวอย่างนี้: networkx และ numpy สามารถติดตั้ง packages เหล่านี้โดย uncomment cell ต่อไปนี้หากคุณรันตัวอย่างนี้ใน notebook ที่ใช้ IPython kernel
# %pip install networkx numpy
import networkx as nx
import numpy as np
# Generate a random graph with 156 nodes
maxcut_graph = nx.random_regular_graph(d=3, n=156, seed=8)
1. นิยามปัญหา
คุณสามารถรันปัญหา Max-Cut โดยนิยาม graph problem และระบุ problem_type='maxcut'
# Optionally, visualize the graph
nx.draw_networkx(
maxcut_graph, nx.kamada_kawai_layout(maxcut_graph), node_size=100
)
# Convert graph to string
problem_as_str = nx.readwrite.json_graph.adjacency_data(maxcut_graph)
Solver รับ string เป็น input นิยามปัญหา
# This cell is hidden from users
from qiskit_ibm_runtime import QiskitRuntimeService
service = QiskitRuntimeService()
backend_name = service.least_busy(n_qubits=156).name
2. รันปัญหา
เมื่อใช้วิธี input แบบ graph-based ให้ระบุ problem type
# Solve the problem
maxcut_job = solver.run(
problem=problem_as_str,
problem_type="maxcut",
backend_name=backend_name, # E.g. "ibm_fez"
)
# Get job status
print(maxcut_job.status())
ตรวจสอบ สถานะ ของ Qiskit Function workload หรือดึง ผลลัพธ์ ดังนี้:
QUEUED
# Poll for results
maxcut_result = maxcut_job.result()
# Take the absolute value of the solution since the cost function is minimized
qctrl_maxcut = abs(maxcut_result["solution_bitstring_cost"])
# Print the optimal cut value found by the Optimization Solver
print(f"Optimal cut value: {qctrl_maxcut}")
3. ดึงผลลัพธ์
ดึงค่า optimal cut จาก results dictionary
การ mapping ของ variables ไปยัง bitstring อาจเปลี่ยนแปลงได้ output dictionary ประกอบด้วย sub-dictionary variables_to_bitstring_index_map ที่ช่วยตรวจสอบลำดับ
Optimal cut value: 210.0
# %pip install numpy networkx sympy
คุณสามารถตรวจสอบความแม่นยำของผลลัพธ์โดยแก้ปัญหาแบบ classically ด้วย open-source solvers เช่น PuLP หาก graph ไม่ได้ densely connected ปัญหา density สูงอาจต้องใช้ classical solvers ขั้นสูงเพื่อตรวจสอบ solution
ตัวอย่าง: Constrained optimization
ตัวอย่าง max-cut ก่อนหน้าเป็นปัญหา quadratic unconstrained binary optimization ทั่วไป Optimization Solver ของ Q-CTRL สามารถใช้กับ problem types ต่างๆ รวมถึง constrained optimization คุณสามารถแก้ arbitrary problem types ได้โดยป้อน problem definition ที่แสดงเป็น polynomial ที่ข้อจำกัดถูก model เป็น penalty terms
ตัวอย่างต่อไปนี้แสดงวิธีสร้าง cost function สำหรับปัญหา constrained optimization, minimum vertex cover (MVC)
นอกจาก packages qiskit-ibm-catalog และ qiskit แล้ว คุณยังต้องใช้ packages ต่อไปนี้: numpy, networkx, และ sympy สามารถติดตั้ง packages เหล่านี้โดย uncomment cell ต่อไปนี้หากคุณรันตัวอย่างนี้ใน notebook ที่ใช้ IPython kernel
import networkx as nx
from sympy import symbols, Poly, srepr
# To change the weights, change the seed to any integer.
rng_seed = 18
_rng = np.random.default_rng(rng_seed)
node_count = 50
edge_probability = 0.08
mvc_graph = nx.erdos_renyi_graph(
node_count, edge_probability, seed=rng_seed, directed=False
)
# add node weights
for i in mvc_graph.nodes:
mvc_graph.add_node(i, weight=_rng.random())
# Optionally, visualize the graph
nx.draw_networkx(mvc_graph, nx.kamada_kawai_layout(mvc_graph), node_size=200)
1. นิยามปัญหา
นิยามปัญหา MVC แบบสุ่มโดยสร้าง graph ที่มี weighted nodes แบบสุ่ม
# Construct the cost function.
variables = symbols([f"n[{i}]" for i in range(node_count)])
cost_function = Poly(0, variables)
for i in mvc_graph.nodes():
weight = mvc_graph.nodes[i].get("weight", 0)
cost_function += variables[i] * weight
โมเดล optimization มาตรฐานสำหรับ weighted MVC สามารถ formulate ได้ดังนี้ ก่อนอื่น ต้องเพิ่ม penalty สำหรับกรณีใดๆ ที่ edge ไม่ได้เชื่อมต่อกับ vertex ใน subset ดังนั้น ให้ หาก vertex อยู่ใน cover (คือ อยู่ใน subset) และ ถ้าไม่ใช่ ประการที่สอง เป้าหมายคือลดจำนวน vertices ทั้งหมดใน subset ให้น้อยที่สุด ซึ่งแสดงด้วยฟังก์ชันต่อไปนี้:
# Add penalty term.
penalty_constant = 2
for i, j in mvc_graph.edges():
cost_function += penalty_constant * (
1 - variables[i] - variables[j] + variables[i] * variables[j]
)
ตอนนี้ทุก edge ใน graph ควรมี endpoint อย่างน้อยหนึ่งจุดจาก cover ซึ่งแสดงเป็น inequality:
กรณีใดที่ edge ไม่ได้เชื่อมต่อกับ vertex ของ cover ต้องถูก penalize ซึ่งแสดงใน cost function โดยเพิ่ม penalty ในรูป เมื่อ เป็นค่าคงที่ penalty ที่เป็นบวก ดังนั้น unconstrained alternative สำหรับ constrained inequality ของ weighted MVC คือ:
# Solve the problem
mvc_job = solver.run(
problem=srepr(cost_function),
backend_name=backend_name, # E.g. "ibm_fez"
)
2. รันปัญหา
print(mvc_job.status())
ตรวจสอบ สถานะ ของ Qiskit Function workload หรือดึง ผลลัพธ์ ดังนี้:
QUEUED
3. ดูผลลัพธ์
ดึง solution และวิเคราะห์ผลลัพธ์ เนื่องจากปัญหานี้มี weighted nodes solution จึงไม่ใช่แค่จำนวน nodes น้อยที่สุดที่ cover แต่ solution cost แสดงถึงผลรวมของน้ำหนักของ vertices ที่รวมอยู่ใน vertex cover ซึ่งแสดงถึง "ต้นทุน" หรือ "น้ำหนัก" รวมในการ cover ทุก edge ใน graph โดยใช้ vertices ที่เลือก
mvc_result = mvc_job.result()
qctrl_cost = mvc_result["solution_bitstring_cost"]
# Print results
print(f"Solution cost: {qctrl_cost}")
Solution cost: 10.248198273708624
ขอความช่วยเหลือ
สำหรับคำถามหรือปัญหาใดๆ ติดต่อ Q-CTRL
Changelog
- 2026-02-11: รองรับ
ibm_miamiแล้ว
ขั้นตอนถัดไป
- ขอสิทธิ์เข้าถึง Q-CTRL Optimization Solver
- เยี่ยมชม API reference สำหรับ Qiskit Function นี้
- ลองทำ tutorial Solve higher-order binary optimization problems with Q-CTRL's Optimization Solver
- ทบทวน Sachdeva, N., et al. (2024). Quantum optimization using a 127-qubit gate-model IBM quantum computer can outperform quantum annealers for nontrivial binary optimization problems. arXiv preprint arXiv:2406.01743
- ทบทวน Loco, D., et al. (2026). Practical protein-pocket hydration-site prediction for drug discovery on a quantum computer. arXiv preprint arXiv:2512.08390
- ทบทวน case study Mazda
- ทบทวน case study Network Rail
- ทบทวน case study Australian Army
- ทบทวน case study Transport for New South Wales