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

แนะนำ options

คุณสามารถใช้ options เพื่อปรับแต่ง Qiskit Runtime primitives ให้ตรงตามความต้องการ

โครงสร้าง

เมื่อเรียก primitives คุณสามารถส่ง options โดยใช้ options class หรือ dictionary ก็ได้ Options ที่ใช้บ่อย เช่น resilience_level จะอยู่ในระดับแรก ส่วน options อื่นจะจัดกลุ่มไว้ในหมวดหมู่ต่างๆ เช่น execution ระบุ options ในรูปแบบ: options.option.sub-option.sub-sub-option = choice ตัวอย่างเช่น: options.dynamical_decoupling.enable = True

ค่าเริ่มต้น

ถ้าคุณไม่ระบุค่าสำหรับ option ใด มันจะได้ค่าพิเศษ Unset และจะใช้ค่า default ของเซิร์ฟเวอร์แทน ดังนั้นค่า default จะเหมือนกันไม่ว่าจะใช้ code version ไหน

ตารางในส่วน "สรุป Options classes" บนหน้า "options" ของแต่ละ primitive จะแสดงค่า default ไว้

ตั้งค่า options

สามารถกำหนด options ก่อนสร้าง primitive แล้วส่งให้กับ primitive ในรูปแบบ instance ของ options class หรือ dictionary primitive จะสำเนาค่าเหล่านั้น ซึ่งหมายความว่าการเปลี่ยน dictionary หรือ options instance ต้นฉบับจะไม่ส่งผลต่อ options ที่ primitive ถืออยู่

นอกจากนี้ยังเปลี่ยน options ของ primitive ได้หลังจากสร้างแล้ว ใช้วิธีที่เหมาะกับแอปพลิเคชันของคุณ

หมายเหตุเกี่ยวกับการระบุ primitive options
  • คุณสามารถดู options ที่ใช้ได้ระหว่างหรือหลังการ initialize primitive
  • ถ้าคุณไม่ระบุค่าสำหรับ option ใด มันจะได้ค่าพิเศษ Unset และจะใช้ค่า default ของเซิร์ฟเวอร์แทน
  • attribute options เป็น Python type dataclass คุณสามารถใช้ method asdict ที่มีอยู่แล้วเพื่อแปลงเป็น dictionary ได้

options class

เมื่อสร้าง instance ของ primitive class คุณสามารถส่ง instance ของ options class เข้าไปได้ Options เหล่านั้นจะถูกนำไปใช้เมื่อคุณใช้ run() ในการคำนวณ ระบุ options ในรูปแบบ: options.option.sub-option.sub-sub-option = choice ตัวอย่างเช่น: options.dynamical_decoupling.enable = True

ดู SamplerOptions หรือ EstimatorOptions สำหรับรายละเอียดทั้งหมดเกี่ยวกับ class

ตัวอย่างต่อไปนี้ใช้ Estimator primitive แต่รูปแบบสำหรับ primitive อื่นจะคล้ายกัน

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
from qiskit_ibm_runtime.options import EstimatorOptions

service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)

options = EstimatorOptions(
resilience_level=2,
resilience={"zne_mitigation": True, "zne": {"noise_factors": [1, 3, 5]}},
)

# or...
options = EstimatorOptions()
options.resilience_level = 2
options.resilience.zne_mitigation = True
options.resilience.zne.noise_factors = [1, 3, 5]

estimator = Estimator(mode=backend, options=options)

Dictionary

คุณสามารถระบุ options เป็น dictionary เมื่อ initialize primitive ก็ได้

ตัวอย่างต่อไปนี้ใช้ Estimator primitive แต่รูปแบบสำหรับ primitive อื่นจะคล้ายกัน

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator

service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)

# Setting options during initialization
estimator = Estimator(
backend,
options={
"resilience_level": 2,
"resilience": {
"zne_mitigation": True,
"zne": {"noise_factors": [1, 3, 5]},
},
},
)

อัปเดต options หลัง initialization

คุณสามารถระบุ options ในรูปแบบ: _primitive_.options.option.sub-option.sub-sub-option = choice เพื่อใช้ประโยชน์จาก auto-complete หรือใช้ method update() สำหรับการอัปเดตแบบกลุ่ม

ไม่จำเป็นต้องสร้าง instance ของ options class ของ primitive (EstimatorOptions หรือ SamplerOptions) ถ้าคุณตั้งค่า options หลังจาก initialize primitive แล้ว

ตัวอย่างต่อไปนี้ใช้ Estimator primitive แต่รูปแบบสำหรับ primitive อื่นจะคล้ายกัน

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator

service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)

estimator = Estimator(mode=backend)

# Setting options after initialization
# This uses auto-complete.
estimator.options.default_precision = 0.01
# This does bulk update.
estimator.options.update(
default_precision=0.02, resilience={"zne_mitigation": True}
)

ขั้นตอนถัดไป

คำแนะนำ
  • ดูรายละเอียดวิธีกำหนดค่า error suppression และ error mitigation
  • เรียนรู้เพิ่มเติมเกี่ยวกับ Estimator options
  • เรียนรู้เพิ่มเติมเกี่ยวกับ Sampler options
  • เรียนรู้เพิ่มเติมเกี่ยวกับ Executor options