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

รวมทรัพยากรควอนตัมภายนอกเข้ากับ Qiskit

Qiskit SDK ถูกสร้างขึ้นเพื่อรองรับบุคคลที่สามในการสร้าง provider ทรัพยากรควอนตัมภายนอก

หมายความว่าองค์กรใดก็ตามที่พัฒนาหรือนำทรัพยากรการประมวลผลควอนตัมไปใช้งานสามารถรวมบริการของตนเข้ากับ Qiskit และเข้าถึงฐานผู้ใช้ของมันได้

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

นอกจากนี้ แพ็กเกจต้องอนุญาตให้ผู้ใช้ส่งงานและดึงผลลัพธ์ผ่านการ implement ออบเจกต์ qiskit.primitives

การให้สิทธิ์เข้าถึง Backend

เพื่อให้ผู้ใช้สามารถ transpile และ execute ออบเจกต์ QuantumCircuit โดยใช้ทรัพยากรภายนอก พวกเขาต้องสร้าง instance ของออบเจกต์ที่มี Target ซึ่งให้ข้อมูลเกี่ยวกับข้อจำกัดของ QPU เช่น การเชื่อมต่อ, basis gate, และจำนวน qubit สามารถให้บริการผ่าน interface คล้ายกับ QiskitRuntimeService ซึ่งผู้ใช้สามารถร้องขอ QPU ได้ ออบเจกต์นี้ควรมี Target อย่างน้อย แต่วิธีที่ง่ายกว่าคือส่งคืน instance ของ BackendV2

ตัวอย่างการ implement อาจมีลักษณะดังนี้:

from qiskit.transpiler import Target
from qsikit.providers import BackendV2

class ProviderService:
""" Class for interacting with a provider's service"""

def __init__(
self,
#Receive arguments for authentication/instantiation
):
""" Initiate a connection with the provider service, given some method
of authentication """

def return_target(name: Str) -> Target:
""" Interact with the service and return a Target object """
return target

def return_backend(name: Str) -> BackendV2:
""" Interact with the service and return a BackendV2 object """
return backend

การให้ interface สำหรับการ execute

นอกจากการให้บริการที่ส่งคืนการกำหนดค่าฮาร์ดแวร์แล้ว บริการที่ให้สิทธิ์เข้าถึงทรัพยากร QPU ภายนอกอาจรองรับการ execute workload ควอนตัมด้วย การเปิดเผยความสามารถดังกล่าวสามารถทำได้โดยสร้างการ implement ของ interface primitives ของ Qiskit เช่น BasePrimitiveJob, BaseEstimatorV2 และ BaseSamplerV2 เป็นต้น อย่างน้อย interface เหล่านี้ควรมีเมธอดสำหรับการ execute, การ query สถานะงาน, และการส่งคืนผลลัพธ์ของงาน

ในการจัดการสถานะและผลลัพธ์ของงาน Qiskit SDK มีออบเจกต์ DataBin, PubResult, PrimitiveResult และ BasePrimitiveJob ที่ควรนำมาใช้

ดู เอกสาร API ของ qiskit.primitives รวมถึงการ implement อ้างอิง BackendEstimatorV2 และ BackendSampleV2 สำหรับข้อมูลเพิ่มเติม

ตัวอย่างการ implement ของ Estimator primitive อาจมีลักษณะดังนี้:

from qiskit.primitives import BaseEstimatorV2, BaseSamplerV2, EstimatorPubLike
from qiskit.primitives import DataBin, PubResult, PrimitiveResult, BasePrimitiveJob
from qiskit.providers import BackendV2

class EstimatorImplementation(BaseEstimatorV2):
""" Class for interacting with the provider's Estimator service """

def __init__(
self,
*,
backend: BackendV2,
options: dict
# Receive other arguments to instantiate an Estimator primitive with the service
):
self._backend = backend
self._options = options
self._default_precision = 0.01

@property
def backend(self) -> BackendV2:
""" Return the backend """
return self._backend

def run(
self, pubs: Iterable[EstimatorPubLike], *, precision: float | None = None
) -> BasePrimitiveJob[PrimitiveResult[PubResult]]:
""" Steps to implement:
1. Define a default precision if none is given
2. Validate pub format
3. Instantiate an object which inherits from BasePrimitiveJob
containing pub and runtime information
4. Send the job to the execution service of the provider
"""
job = BasePrimitiveJob(pubs, precision)
job_with_results = job.submit()
return job_with_results

และการ implement ของ Sampler primitive อาจมีลักษณะดังนี้:

class SamplerImplementation(BaseSamplerV2):
""" Class for interacting with the provider's Sampler service """

def __init__(
self,
*,
backend: BackendV2,
options: dict
# Receive other arguments to instantiate an Estimator primitive with the service
):
self._backend = backend
self._options = options
self._default_shots = 1024

@property
def backend(self) -> BackendV2:
""" Return the Sampler's backend """
return self._backend

def run(
self, pubs: Iterable[SamplerPubLike], *, shots: int | None = None
) -> BasePrimitiveJob[PrimitiveResult[SamplerPubResult]]:
""" Steps to implement:
1. Define a default number of shots if none is given
2. Validate pub format
3. Instantiate an object which inherits from BasePrimitiveJob
containing pub and runtime information
4. Send the job to the execution service of the provider
5. Return the data in some format
"""
job = BasePrimitiveJob(pubs, shots)
job_with_results = job.submit()
return job_with_results
Source: IBM Quantum docs — updated 29 ต.ค. 2568
English version on doQumentation — updated 7 พ.ค. 2569
This translation based on the English version of 11 มี.ค. 2569