qiskit-documentation/docs/guides/get-qpu-information.ipynb

360 lines
11 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "cb8aed01-2218-4524-b769-94e3f481b25f",
"metadata": {},
"source": [
"# Get backend information with Qiskit"
]
},
{
"cell_type": "markdown",
"id": "3eccac60-3e0f-4f55-ad2d-f19620105ad3",
"metadata": {
"tags": [
"version-info"
]
},
"source": [
"<details>\n",
"<summary><b>Package versions</b></summary>\n",
"\n",
"The code on this page was developed using the following requirements.\n",
"We recommend using these versions or newer.\n",
"\n",
"```\n",
"qiskit[all]~=1.2.4\n",
"qiskit-aer~=0.15.1\n",
"qiskit-ibm-runtime~=0.31.0\n",
"qiskit-serverless~=0.17.1\n",
"qiskit-ibm-catalog~=0.1\n",
"```\n",
"</details>"
]
},
{
"cell_type": "markdown",
"id": "fb232c67-5b12-4125-b786-aca54bd734c2",
"metadata": {},
"source": [
"This page explains how to use Qiskit to find information about your available backends."
]
},
{
"cell_type": "markdown",
"id": "915e21a1-edd8-40a8-a230-2105a024b81c",
"metadata": {},
"source": [
"## List backends\n",
"\n",
"To view the backends you have access to, you can either view a list on the [Compute resources page,](https://quantum.ibm.com/services/resources?tab=yours) or you can use the [`QiskitRuntimeService.backends()`](../api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#backends) method. This method returns a list of [`IBMBackend`](../api/qiskit-ibm-runtime/qiskit_ibm_runtime.IBMBackend) instances:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1dfa3af8-686d-420c-8b58-b8e687816fec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<IBMBackend('ibm_sherbrooke')>,\n",
" <IBMBackend('ibm_kyiv')>,\n",
" <IBMBackend('ibm_brisbane')>]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Initialize your account\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"service = QiskitRuntimeService(instance=\"ibm-q/open/main\")\n",
"\n",
"service.backends()"
]
},
{
"cell_type": "markdown",
"id": "2e3a18e2-1130-4fb6-a57d-d7226b4268b7",
"metadata": {},
"source": [
"The [`QiskitRuntimeService.backend()`](../api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#backend) method (note that this is singular: *backend*) takes the name of the backend as the input parameter and returns an [`IBMBackend`](../api/qiskit-ibm-runtime/qiskit_ibm_runtime.IBMBackend) instance representing that particular backend:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "25a40e79-a494-40e6-9558-17f4418a0efc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<IBMBackend('ibm_brisbane')>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"service.backend(\"ibm_brisbane\")"
]
},
{
"cell_type": "markdown",
"id": "3ba97c22-330f-4eed-8e44-e538f94c2974",
"metadata": {},
"source": [
"## Filter backends\n",
"\n",
"You can also filter the available backends by their properties. For more general filters, set the `filters` argument to a function that accepts a backend object and returns `True` if it meets your criteria. Refer to the [API documentation](../api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#backends) for more details.\n",
"\n",
"The following code returns only backends that fit these criteria:\n",
"\n",
"* Are real quantum devices (`simulator=False`)\n",
"* Are currently operational (`operational=True`)\n",
"* Have at least 5 qubits (`min_num_qubits=5`)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dbadd7dd-1272-4973-9ad8-5fd5a40ea008",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<IBMBackend('ibm_sherbrooke')>,\n",
" <IBMBackend('ibm_kyiv')>,\n",
" <IBMBackend('ibm_brisbane')>]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"service.backends(simulator=False, operational=True, min_num_qubits=5)"
]
},
{
"cell_type": "markdown",
"id": "b2d15581-56d8-4719-8e35-a8cbf0abd0c3",
"metadata": {},
"source": [
"Use these keyword arguments to filter by any attribute in backend configuration ([JSON schema](https://github.com/Qiskit/ibm-quantum-schemas/blob/main/schemas/backend_configuration_schema.json)) or status ([JSON schema](https://github.com/Qiskit/ibm-quantum-schemas/blob/main/schemas/backend_status_schema.json)). A similar method is [`QiskitRuntimeService.least_busy()`](../api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#least_busy), which takes the same filters as `backends()` but returns the backend that matches the filters and has the least number of jobs pending in the queue:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "061ef5dc-cd72-4f7a-b4a0-c7cbaffd4169",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<IBMBackend('ibm_brisbane')>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"service.least_busy(operational=True, min_num_qubits=5)"
]
},
{
"cell_type": "markdown",
"id": "4dc42491-6a03-4e49-bd26-905187edd45b",
"metadata": {},
"source": [
"## Static backend information\n",
"\n",
"Some information about a backend does not change regularly, such as its name, version, the number of qubits it has, and the types of features it supports. This information is available as attributes of the `backend` object.\n",
"\n",
"The following cell builds a description of a backend."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "7c963d4f-9792-4d76-97c8-93aa95c6f791",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Name: ibm_sherbrooke\n",
"Version: 2\n",
"No. of qubits: 127\n",
"\n"
]
}
],
"source": [
"backend = service.backend(\"ibm_sherbrooke\")\n",
"\n",
"print(\n",
" f\"Name: {backend.name}\\n\"\n",
" f\"Version: {backend.version}\\n\"\n",
" f\"No. of qubits: {backend.num_qubits}\\n\"\n",
")"
]
},
{
"cell_type": "markdown",
"id": "cf5b994a-2434-43df-8e37-c063f1fbe3ce",
"metadata": {},
"source": [
"For a full list of attributes, see the [`IBMBackend` API documentation](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.IBMBackend)."
]
},
{
"cell_type": "markdown",
"id": "fe84b143-8a73-4bd9-b6a4-b3a023e72964",
"metadata": {},
"source": [
"## Dynamic backend information\n",
"\n",
"Backends can also have properties that change whenever the backed is calibrated, such as qubit frequency and operation error rates. Backends are usually calibrated every 24 hours, and their properties update after the calibration sequence completes. These properties can be used when optimizing quantum circuits or to construct noise models for a classical simulator.\n",
"\n",
"\n",
"### Qubit properties\n",
"\n",
"The `backend.qubit_properties` method returns information about the qubits' physical attributes. This includes the qubit frequency in GHz and decay times (`t1` and `t2`) in µs."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "f1a82580-cd98-4654-94d2-eec8ccc9f7ad",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"QubitProperties(t1=0.0004359191921774979, t2=9.098970775335616e-05, frequency=4635662846.425661)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"backend.qubit_properties(0) # properties of qubit 0"
]
},
{
"cell_type": "markdown",
"id": "f96efd0b-3d35-4ab5-b7b1-ef182c6eed31",
"metadata": {},
"source": [
"### Instruction properties\n",
"\n",
"The `backend.target` attribute is a `qiskit.transpiler.Target` object: an object that contains all the information needed to transpile a circuit for that backend. This includes instruction errors and durations. For example, the following cell gets the properties for an [`ecr` gate](/api/qiskit/qiskit.circuit.library.ECRGate) acting between qubits 1 and 0."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "582de91f-62b4-464c-b9c8-f84af948a06a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"InstructionProperties(duration=5.333333333333332e-07, error=0.013205165272520247, calibration=PulseQobj)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"backend.target[\"ecr\"][(1, 0)]"
]
},
{
"cell_type": "markdown",
"id": "d5da7085-163f-4cdc-930a-4fc00832480a",
"metadata": {},
"source": [
"The following cell shows the properties for a measurement operation (including the readout error) on qubit 0."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f6b9e34e-2ef7-4340-8e33-828dd18c8e9d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"InstructionProperties(duration=1.216e-06, error=0.007400000000000073, calibration=PulseQobj)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"backend.target[\"measure\"][(0,)]"
]
},
{
"cell_type": "markdown",
"id": "2385a454-d097-4f63-925f-8609433f3bd7",
"metadata": {},
"source": [
"## Next steps\n",
"\n",
"<Admonition type=\"tip\" title=\"Recommendations\">\n",
" - Try the [Grover's algorithm](https://learning.quantum.ibm.com/tutorial/grovers-algorithm) tutorial.\n",
" - Review the [QiskitRuntime backend API](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.QiskitRuntimeService#backend) reference.\n",
"</Admonition>"
]
}
],
"metadata": {
"description": "Find and filter available backends, get configuration and calibration data programmatically.",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3"
},
"title": "Get backend information with Qiskit"
},
"nbformat": 4,
"nbformat_minor": 4
}