การระบุตัวเลือก Sampler
เวอร์ชันแพ็กเกจ
โค้ดในหน้านี้พัฒนาโดยใช้ข้อกำหนดต่อไปนี้ แนะนำให้ใช้เวอร์ชันเหล่านี้หรือใหม่กว่า
qiskit[all]~=2.4.0
qiskit-ibm-runtime~=0.46.1
คุณสามารถใช้ตัวเลือกเพื่อปรับแต่ง Sampler primitive ได้ ส่วนนี้จะเน้นวิธีระบุตัวเลือก Qiskit Runtime primitive อินเทอร์เฟซของเมธอด run() ของ primitive นั้นเหมือนกันทุกการใช้งาน แต่ตัวเลือกไม่ใช่ ดูข้อมูลเกี่ยวกับตัวเลือก qiskit.primitives.BackendSamplerV2 และ qiskit_aer.primitives.SamplerV2 ได้จาก API reference ที่เกี่ยวข้อง
ตั้งค่าตัวเลือก Sampler
คุณตั้งค่าตัวเลือกได้เมื่อเริ่มต้น Sampler หลังจากเริ่มต้น Sampler หรืออัปเดตตัวเลือกหลังจากที่ Sampler ถูกเริ่มต้นแล้ว ดูคำแนะนำการใช้เทคนิคเหล่านี้ได้ที่หัวข้อ บทนำสู่ตัวเลือก
นอกจากนี้ คุณสามารถตั้งค่า shots ในเมธอด run() ได้ตามที่อธิบายในส่วนถัดไป
เมธอด Run()
ค่าเดียวที่สามารถส่งไปยัง run() คือค่าที่กำหนดไว้ในอินเทอร์เฟซ นั่นคือ shots ซึ่งจะเขียนทับค่าที่ตั้งไว้สำหรับ default_shots ในการรันปัจจุบัน
# Added by doQumentation — required packages for this notebook
!pip install -q qiskit qiskit-ibm-runtime
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import SamplerV2 as Sampler
from qiskit.circuit.library import random_iqp
from qiskit.transpiler import generate_preset_pass_manager
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
circuit1 = random_iqp(3)
circuit1.measure_all()
circuit2 = random_iqp(3)
circuit2.measure_all()
pass_manager = generate_preset_pass_manager(
optimization_level=3, backend=backend
)
transpiled1 = pass_manager.run(circuit1)
transpiled2 = pass_manager.run(circuit2)
sampler = Sampler(mode=backend)
# Default shots to use if not specified in run()
sampler.options.default_shots = 500
# Sample two circuits at 128 shots each.
sampler.run([transpiled1, transpiled2], shots=128)
<RuntimeJobV2('d8286680bvlc73d1vmu0', 'sampler')>
กรณีพิเศษ
Shots
เมธอด SamplerV2.run รับอาร์กิวเมนต์สองตัว ได้แก่ รายการ PUB ซึ่งแต่ละตัวสามารถระบุค่า shots เฉพาะ PUB และอาร์กิวเมนต์คีย์เวิร์ด shots ค่า shots เหล่านี้เป็นส่วนหนึ่งของอินเทอร์เฟซการดำเนินการ Sampler และเป็นอิสระจากตัวเลือกของ Runtime Sampler ค่าเหล่านี้มีลำดับความสำคัญสูงกว่าค่าที่ระบุเป็นตัวเลือก เพื่อให้สอดคล้องกับการ abstract ของ Sampler
อย่างไรก็ตาม หาก shots ไม่ได้ถูกระบุโดย PUB ใดหรือในอาร์กิวเมนต์คีย์เวิร์ดของ run (หรือถ้าทั้งหมดเป็น None) ค่า shots จากตัวเลือกจะถูกใช้ โดยเฉพาะ default_shots
สรุปแล้ว นี่คือลำดับความสำคัญในการระบุ shots ใน Sampler สำหรับ PUB ใด ๆ:
- ถ้า PUB ระบุ shots ให้ใช้ค่านั้น
- ถ้าอาร์กิวเมนต์คีย์เวิร์ด
shotsถูกระบุในrunให้ใช้ค่านั้น - ถ้า
twirlingเปิดใช้งาน (True ตามค่าเริ่มต้น) จะใช้ผลคูณของnum_randomizationsและshots_per_randomizationตามที่ระบุเป็นตัวเลือกtwirling - ถ้า
sampler.options.default_shotsถูกระบุ ให้ใช้ค่านั้น
ดังนั้น ถ้า shots ถูกระบุในทุกตำแหน่งที่เป็นไปได้ ค่าที่มีลำดับความสำคัญสูงสุด (shots ที่ระบุใน PUB) จะถูกใช้
แม้ว่า shots ที่ระบุใน PUB และใน run จะมีลำดับความสำคัญสูงกว่า แต่งานจะล้มเหลวถ้า twirling เปิดใช้งานและผลคูณของ num_randomizations และ shots_per_randomization มีค่าน้อยกว่าค่า shots ในสถานการณ์นี้ SamplerV2 ไม่สามารถจัดสรร shots ให้กับ num_randomizations ที่ระบุได้
ตัวอย่าง:
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import SamplerV2 as Sampler
from qiskit.circuit.library import random_iqp
from qiskit.transpiler import generate_preset_pass_manager
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
circuit1 = random_iqp(3)
circuit1.measure_all()
circuit2 = random_iqp(3)
circuit2.measure_all()
pass_manager = generate_preset_pass_manager(
optimization_level=3, backend=backend
)
transpiled1 = pass_manager.run(circuit1)
transpiled2 = pass_manager.run(circuit2)
# Setting shots during primitive initialization
sampler = Sampler(mode=backend, options={"default_shots": 4096})
# Setting options after primitive initialization
# This uses auto-complete.
sampler.options.default_shots = 2000
# This does bulk update. The value for default_shots is overridden
# if you specify shots with run() or in the PUB.
sampler.options.update(
default_shots=1024, dynamical_decoupling={"sequence_type": "XpXm"}
)
# Sample two circuits at 128 shots each.
sampler.run([transpiled1, transpiled2], shots=128)
<RuntimeJobV2('d82868ugbeec73alfa80', 'sampler')>
ตัวเลือกที่มีให้ใช้
ตารางต่อไปนี้แสดงตัวเลือกจากเวอร์ชันล่าสุดของ qiskit-ibm-runtime หากต้องการดูเวอร์ชันตัวเลือกเก่ากว่า ให้ไปที่ API reference ของ qiskit-ibm-runtime และเลือกเวอร์ชันก่อนหน้า
default_shots
จำนวน shots ทั้งหมดที่จะใช้ต่อวงจรต่อการกำหนดค่า
ตัวเลือก: จำนวนเต็ม >= 0
ค่าเริ่มต้น: None
dynamical_decoupling
ควบคุมการตั้งค่าการลดข้อผิดพลาด dynamical decoupling
เอกสาร API ของ dynamical_decoupling
dynamical_decoupling.enable
ตัวเลือก: True, False
ค่าเริ่มต้น: False
dynamical_decoupling.extra_slack_distribution
ตัวเลือก: middle, edges
ค่าเริ่มต้น: middle
dynamical_decoupling.scheduling_method
ตัวเลือก: asap, alap
ค่าเริ่มต้น: alap
dynamical_decoupling.sequence_type
ตัวเลือก: XX, XpXm, XY4
ค่าเริ่มต้น: XX
dynamical_decoupling.skip_reset_qubits
ตัวเลือก: True, False
ค่าเริ่มต้น: False
environment
environment.job_tags
รายการแท็ก
ตัวเลือก: None
ค่าเริ่มต้น: None
environment.log_level
ตัวเลือก: DEBUG, INFO, WARNING, ERROR, CRITICAL
ค่าเริ่มต้น: WARNING
environment.private
ตัวเลือก: True, False
ค่าเริ่มต้น: False
execution
execution.init_qubits
ว่าจะรีเซ็ต Qubit ให้กลับสู่สถานะพื้นฐานสำหรับแต่ละ shot หรือไม่
ตัวเลือก: True, False
ค่าเริ่มต้น: True
execution.rep_delay
การหน่วงเวลาระหว่างการวัดและวงจรควอนตัมที่ตามมา
ตัวเลือก: ค่าในช่วงที่กำหนดโดย backend.rep_delay_range
ค่าเริ่มต้น: กำหนดโดย backend.default_rep_delay
execution.meas_type
ตัวเลือก: classified, kerneled, avg_kerneled
ค่าเริ่มต้น: classified
max_execution_time
จำกัดระยะเวลาที่งานสามารถรันได้ หน่วยเป็นวินาที ดูรายละเอียดเพิ่มเติมในคู่มือเวลาการรันสูงสุด
ตัวเลือก: จำนวนเต็มเป็นวินาทีในช่วง [1, 10800]
ค่าเริ่มต้น: 10800 (3 ชั่วโมง)
simulator
ตัวเลือกที่จะส่งเมื่อจำลอง backend
simulator.basis_gates
ตัวเลือก: รายการชื่อ basis gate ที่จะ unroll ไปยัง
ค่าเริ่มต้น: ชุด basis gate ทั้งหมดที่รองรับโดย Qiskit Aer simulator
simulator.coupling_map
ตัวเลือก: รายการปฏิสัมพันธ์สองควิบิตแบบมีทิศทาง
ค่าเริ่มต้น: None ซึ่งหมายความว่าไม่มีข้อจำกัดการเชื่อมต่อ (การเชื่อมต่อเต็มรูปแบบ)
simulator.noise_model
ตัวเลือก: Qiskit Aer NoiseModel หรือการแสดงผลของมัน
ค่าเริ่มต้น: None
simulator.seed_simulator
ตัวเลือก: จำนวนเต็ม
ค่าเริ่มต้น: None
twirling
ตัวเลือก twirling
twirling.enable_gates
ตัวเลือก: True, False
ค่าเริ่มต้น: False
twirling.enable_measure
ตัวเลือก: True, False
ค่าเริ่มต้น: False
twirling.num_randomizations
ตัวเลือก: auto, จำนวนเต็ม >= 1
ค่าเริ่มต้น: auto
twirling.shots_per_randomization
ตัวเลือก: auto, จำนวนเต็ม >= 1
ค่าเริ่มต้น: auto
twirling.strategy
ตัวเลือก: active, active-circuit, active-accum, all
ค่าเริ่มต้น: active-accum
experimental
ตัวเลือกทดลอง เมื่อมีให้ใช้
ความเข้ากันได้ของฟีเจอร์
ฟีเจอร์ runtime บางอย่างไม่สามารถใช้ร่วมกันในงานเดียว คลิกแท็บที่เหมาะสมเพื่อดูรายการฟีเจอร์ที่ไม่เข้ากันกับฟีเจอร์ที่เลือก:
Dynamic circuits
ไม่เข้ากันกับ:
- Dynamical decoupling
หมายเหตุอื่น ๆ:
- Gate twirling สามารถใช้กับวงจรไดนามิกได้ แต่ใช้ได้เฉพาะกับ gate ที่ไม่อยู่ใน conditional blocks เท่านั้น Measurement twirling ใช้ได้เฉพาะกับการวัดสุดท้ายเท่านั้น
- เข้ากันกับ fractional gate เมื่อใช้
qiskit-ibm-runtimev0.42.0 หรือใหม่กว่า
Dynamical decoupling
ไม่เข้ากันกับ:
- Dynamic circuits
Fractional gates
ไม่เข้ากันกับ:
- Gate twirling
เข้ากันกับวงจรไดนามิกเมื่อใช้ qiskit-ibm-runtime v0.42.0 หรือใหม่กว่า
Gate twirling
ไม่เข้ากันกับ:
- Fractional gates
- Stretches
หมายเหตุอื่น ๆ:
- Gate twirling สามารถใช้กับวงจรไดนามิกได้ แต่ใช้ได้เฉพาะกับ gate ที่ไม่อยู่ใน conditional blocks เท่านั้น
- Measurement twirling ใช้ได้เฉพาะกับการวัดสุดท้ายเท่านั้น
- Measurement twirling ไม่เข้ากันกับคำสั่ง
store - ไม่ทำงานกับ non-Clifford entangler
ขั้นตอนถัดไป
- ตรวจสอบคู่มือบทนำสู่ตัวเลือก
- ค้นหาข้อมูลเพิ่มเติมเกี่ยวกับเมธอด
SamplerV2ใน Sampler API reference - ตัดสินใจว่าจะรันงานในโหมดการรันใด
- เรียนรู้เกี่ยวกับการจัดการ noise ด้วย Sampler