จัดระเบียบและค้นหาด้วย job tags
เวอร์ชันของ packages
โค้ดในหน้านี้พัฒนาโดยใช้ requirements ต่อไปนี้ แนะนำให้ใช้เวอร์ชันเหล่านี้หรือใหม่กว่า
qiskit[all]~=2.5.2
qiskit-ibm-runtime~=0.49.0
คู่มือนี้เน้นวิธีเพิ่มและอัปเดต job tags รวมถึงวิธีค้นหาตาม job tags เพื่อให้จัดระเบียบ ติดตาม และทำความเข้าใจการทดลองได้ดียิ่งขึ้น
กำหนด tags
สามารถกำหนด tags หนึ่งรายการหรือมากกว่าให้กับ jobs ตอนที่รัน เพื่อกรองตาม tag ในภายหลัง อาจใช้ job tags เพื่อระบุการตั้งค่า error mitigation เฉพาะ พารามิเตอร์ Circuit และอื่นๆ
# Added by doQumentation — installs the packages this notebook needs if they are missing
import importlib.util
_needed = {"qiskit": "qiskit", "qiskit_ibm_runtime": "qiskit-ibm-runtime"}
_missing = [pip for module, pip in _needed.items()
if importlib.util.find_spec(module) is None]
# One at a time, so a package that fails to install does not block the others
for _pip in _missing:
%pip install -q {_pip}
if not _missing:
print("\u2713 All required packages are installed")
from qiskit_ibm_runtime import QiskitRuntimeService, Sampler
from qiskit import QuantumCircuit
from qiskit.transpiler import generate_preset_pass_manager
service = QiskitRuntimeService()
backend = service.least_busy(simulator=False, operational=True)
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
sampler = Sampler(backend)
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
isa_circuit = pm.run(qc)
# Assign tags before executing
sampler.options.environment.job_tags = ["experiment-2025", "sampler-example"]
# Submit
job = sampler.run([isa_circuit])
print(service.job(job.job_id()).tags)
['experiment-2025', 'sampler-example']
เพิ่มและอัปเดต tags
สามารถเพิ่ม tags หลังจาก submit job แล้วด้วยเมธอด update_tags() เมธอดนี้จะเขียนทับ tags ปัจจุบัน ดังนั้นถ้ากำหนด tags ให้ job แล้วและต้องการเพิ่ม tags อื่น ต้องกำหนด tags เดิมซ้ำด้วย
# Add a new tag while keeping the previously assigned tags
job.update_tags(["experiment-2025", "sampler-example", "127-qubit"])
# Confirm updated tags
print(job.tags)
['sampler-example', 'experiment-2025', '127-qubit']
ดึง jobs ตาม tag
แสดงรายการ jobs ที่มี tags บางอย่างได้ดังนี้:
# List jobs with a specific tag or set of tags
service.jobs(job_tags=["experiment-2025", "sampler-example"])
[<RuntimeJobV2('db87r36il99s73fpgl80', 'sampler')>,
<RuntimeJobV2('db21r4c7f06c73ap7jtg', 'sampler')>,
<RuntimeJobV2('dav0ijbg95ks73ej7ku0', 'sampler')>,
<RuntimeJobV2('dakf378mhr3c73ea4ljg', 'sampler')>,
<RuntimeJobV2('dab7ljj4clkc73fijsm0', 'sampler')>,
<RuntimeJobV2('da0147no3ppc73akuf3g', 'sampler')>,
<RuntimeJobV2('d9mqa2eh4e6s738viav0', 'sampler')>,
<RuntimeJobV2('d9bjj0mg26ic73dg2520', 'sampler')>,
<RuntimeJobV2('d92d08vccmks73d6j8ng', 'sampler')>,
<RuntimeJobV2('d8286jg0bvlc73d1vnhg', 'sampler')>]