انتقل إلى المحتوى الرئيسي

دالة IBM Circuit

اطّلع على مرجع API

ملاحظة
  • دوال Qiskit ميزة تجريبية متاحة فقط لمستخدمي خطط IBM Quantum® Premium Plan وFlex Plan وOn-Prem (عبر IBM Quantum Platform API). وهي في مرحلة إصدار معاينة وقابلة للتغيير.

نظرة عامة

تأخذ دالة IBM® Circuit كمدخلات PUBs مجردة، وتُعيد قيم التوقع المخففة كمخرجات. تتضمن هذه الدالة خط أنابيب آلي ومخصص يُمكّن الباحثين من التركيز على اكتشاف الخوارزميات والتطبيقات.

الوصف

بعد إرسال PUB الخاص بك، يتم تحويل الدوائر والمراقِبات المجردة تلقائيًا، وتنفيذها على الجهاز الفعلي، ثم معالجتها لاحقًا لإعادة قيم التوقع المخففة. ولتحقيق ذلك، تجمع هذه الدالة بين الأدوات التالية:

دالة IBM Circuit

البدء

اتصل بالخدمة باستخدام مفتاح API واختر دالة Qiskit كما يلي. (يفترض هذا المقتطف أنك حفظت حسابك بالفعل في بيئتك المحلية.)

# Added by doQumentation — required packages for this notebook
!pip install -q qiskit qiskit-ibm-catalog qiskit-ibm-runtime
from qiskit_ibm_catalog import QiskitFunctionsCatalog

catalog = QiskitFunctionsCatalog(channel="ibm_quantum_platform")

function = catalog.load("ibm/circuit-function")

أمثلة

لتبدأ، جرّب هذا المثال الأساسي:

from qiskit.circuit.random import random_circuit
from qiskit_ibm_runtime import QiskitRuntimeService

# You can skip this step if you have a target backend, e.g.
# backend_name = "ibm_brisbane"
# You'll need to specify the credentials when initializing QiskitRuntimeService, if they were not previously saved.
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)

circuit = random_circuit(num_qubits=2, depth=2, seed=42)
observable = "Z" * circuit.num_qubits
pubs = [(circuit, observable)]

job = function.run(
# Use `backend_name=backend_name` if you didn't initialize a backend object
backend_name=backend.name,
pubs=pubs,
)

تحقق من حالة حِمل عمل دالة Qiskit أو استرجع النتائج كما يلي:

print(job.status())
result = job.result()
QUEUED

النتائج لها نفس صيغة نتيجة Estimator:

print(f"The result of the submitted job had {len(result)} PUB\n")
print(
f"The associated PubResult of this job has the following DataBins:\n {result[0].data}\n"
)
print(f"And this DataBin has attributes: {result[0].data.keys()}")
print(
f"The expectation values measured from this PUB are: \n{result[0].data.evs}"
)
The result of the submitted job had 1 PUB

The associated PubResult of this job has the following DataBins:
DataBin(evs=np.ndarray(<shape=(), dtype=float64>), stds=np.ndarray(<shape=(), dtype=float64>), ensemble_standard_error=np.ndarray(<shape=(), dtype=float64>))

And this DataBin has attributes: dict_keys(['evs', 'stds', 'ensemble_standard_error'])
The expectation values measured from this PUB are:
1.02116704805492

أمثلة على مستوى التخفيف

يوضح المثال التالي كيفية ضبط مستوى التخفيف:

options = {"mitigation_level": 2}

job = function.run(backend_name=backend.name, pubs=pubs, options=options)

في المثال التالي، يُوقف ضبط مستوى التخفيف على 1 تخفيف ZNE في البداية، لكن ضبط zne_mitigation على True يتجاوز الإعداد ذي الصلة من mitigation_level.

options = {"mitigation_level": 1, "resilience": {"zne_mitigation": True}}

مثال على المخرجات

يصف مقتطف الكود التالي صيغة PrimitiveResultPubResult المرتبط به).

print(f"The result of the submitted job had {len(result)} PUB")
print(
f"The expectation values measured from this PUB are: \n{result[0].data.evs}"
)
print(f"And the associated metadata is: \n{result[0].metadata}")
The result of the submitted job had 1 PUB
The expectation values measured from this PUB are:
1.02116704805492
And the associated metadata is:
{'shots': 4096, 'target_precision': 0.015625, 'circuit_metadata': {}, 'resilience': {}, 'num_randomizations': 32}

استرجاع رسائل الخطأ

إذا كانت حالة حِمل العمل ERROR، استخدم job.result() لاسترجاع رسالة الخطأ للمساعدة في تصحيح الأخطاء كما يلي:

job = function.run(
backend_name="bad_backend_name", pubs=pubs, options=options
)

print(job.result())

الحصول على الدعم

تواصل مع دعم IBM Quantum، وأرفق المعلومات التالية:

  • معرّف مهمة دالة Qiskit (qiskit-ibm-catalogjob.job_id
  • وصف مفصّل للمشكلة
  • أي رسائل خطأ أو رموز ذات صلة
  • خطوات إعادة إنتاج المشكلة

الخطوات التالية

توصيات