qiskit-documentation/docs/guides/qedma-qesem.ipynb

406 lines
25 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "markdown",
"id": "dde95705",
"metadata": {},
"source": [
"# QESEM: A Qiskit Function by Qedma\n",
"\n",
"<Admonition type=\"note\">\n",
"Qiskit Functions are an experimental feature available only to IBM Quantum&trade; Premium Plan users. They are in preview release status and subject to change.\n",
"</Admonition>\n",
"\n",
"## Overview\n",
"\n",
"While quantum processing units have vastly improved in recent years, errors due to noise and imperfections in existing hardware remain a central challenge for quantum algorithm developers. As the field approaches utility-scale quantum computations that cannot be verified classically, solutions for canceling noise with guaranteed accuracy are becoming increasingly important. To overcome this challenge, Qedma has developed Quantum Error Suppression and Error Mitigation (QESEM), seamlessly integrated on IBM Quantum Platform as a [Qiskit Function](/guides/functions).\n",
"\n",
"With QESEM, users can run their quantum circuits on noisy QPUs to obtain highly accurate error-free results with highly efficient QPU-time overheads, close to fundamental bounds. To achieve this, QESEM leverages a suite of propriety methods developed by Qedma, for the characterization and reduction of errors. Error reduction techniques include gate optimization, noise-aware transpilation, error suppression (ES), and unbiased error mitigation (EM). With this combination of these characterization-based methods, users can achieve reliable, error-free results for generic large-volume quantum circuits, unlocking applications that cannot be accomplished otherwise."
]
},
{
"cell_type": "markdown",
"id": "5f761442",
"metadata": {},
"source": [
"## Description\n",
"\n",
"You can use the QESEM function by Qedma to easily estimate and execute your circuits with error suppression and mitigation, achieving larger circuit volumes and higher accuracies. To use QESEM, you provide a quantum circuit, a set of observables to measure, a target statistical accuracy for each observable, and a chosen QPU. Before you run the circuit to the target accuracy, you can estimate the required QPU time based on an analytical calculation that does not require circuit execution. Once you are satisfied with the QPU time estimation, you can execute the circuit with QESEM.\n",
"\n",
"When you execute a circuit, QESEM runs a device characterization protocol tailored to your circuit, yielding a reliable noise model for the errors occurring in the circuit. Based on the characterization, QESEM first implements noise-aware transpilation to map the input circuit onto a set of physical qubits and gates, which minimizes the noise affecting the target observable. These include the natively available gates (CX/CZ on IBM&reg; devices), as well as additional gates optimized by QESEM, forming QESEMs extended gate set. QESEM then runs a set of characterization-based ES and EM circuits on the QPU and collects their measurement outcomes. These are then classically post-processed to provide an unbiased expectation value and an error bar for each observable, corresponding to the requested accuracy.\n",
"\n",
"![Qedma QESEM overview](/images/guides/qedma-qesem/overview.svg)"
]
},
{
"cell_type": "markdown",
"id": "74823696",
"metadata": {},
"source": [
"QESEM has been demonstrated to provide high-accuracy results for a variety of quantum applications and on the largest circuit volumes achievable today. QESEM offers the following user-facing features, demonstrated in the benchmarks section below:\n",
"-\t**Guaranteed accuracy:** QESEM outputs unbiased estimations for expectation values of observables. Its EM method is equipped with theoretical guarantees, which - together with Qedmas cutting-edge characterization - ensure the mitigation converges to the noiseless circuit output up to the user-specified accuracy. In contrast to many heuristic EM methods that are prone to systematic errors or biases, QESEMs guaranteed accuracy is essential for ensuring reliable results in generic quantum circuits and observables.\n",
"-\t**Scalability to large QPUs:** QESEMs QPU time depends on circuit volumes, but is otherwise independent of the number of qubits. Qedma has demonstrated QESEM on the largest quantum devices available today, including the IBM Quantum 127-qubit Eagle and 133-qubit Heron devices.\n",
"-\t**Application-agnostic:** QESEM has been demonstrated on a variety of applications, including Hamiltonian simulation, VQE, QAOA, and amplitude estimation. Users can input any quantum circuit and observable to be measured, and obtain accurate error-free results. The only limitations are dictated by the hardware specifications and allocated QPU time, which determine the accessible circuit volumes and output accuracies. In contrast, many error reduction solutions are application-specific or involve uncontrolled heuristics, rendering them inapplicable for generic quantum circuits and applications.\n",
"- **Extended gate set:** QESEM supports fractional-angle gates, and provides Qedma-optimized fractional-angle $Rzz(\\theta)$ gates on IBM Quantum Eagle devices. This extended gate set enables more efficient compilation and unlocks circuit volumes larger by a factor of up to 2 compared to default CX/CZ compilation.\n",
"-\t**Multibase observables:** QESEM supports input observables composed of many non-commuting Pauli strings, such as generic Hamiltonians. The choice of measurement bases and the optimization of QPU resource allocation (shots and circuits) is then performed automatically by QESEM to minimize the required QPU time for the requested accuracy. This optimization, which takes into account hardware fidelities and execution rates, enables you to run deeper circuits and obtain higher accuracies."
]
},
{
"cell_type": "markdown",
"id": "57b41ab0",
"metadata": {},
"source": [
"## Benchmarks\n",
"\n",
"QESEM has been tested on a wide variety of use cases and applications. The following examples can assist you with assessing which types of workloads you can run with QESEM.\n",
"\n",
"A key figure of merit for quantifying the hardness of both error mitigation and classical simulation for a given circuit and observable is **active volume**: the number of CNOT gates affecting the observable in the circuit. The active volume depends on the circuit depth and width, on the observable weight, and on the circuit structure, which determines the light cone of the observable. For further details, see the talk from the [2024 IBM Quantum Summit](https://www.youtube.com/watch?v=Hd-IGvuARfE&t=1730s). QESEM provides particularly large value in the high-volume regime, giving reliable results for generic circuits and observables.\n",
"\n",
"![Active volume](/images/guides/qedma-qesem/active_volume.svg)\n",
"\n",
"\n",
"| Application | Number of qubits | Device | Circuit description | Accuracy | Total time | Runtime usage |\n",
"| --------- | ---------------- | ----- | -------------------------- | -------- | ---------- | ------------- |\n",
"| VQE circuit | 8 | Eagle (r3) | 21 total layers, 9 measurement bases, 1D chain | 98% | 35 min | 14 min |\n",
"| Kicked Ising | 28 | Eagle (r3) | 3 unique layers x 3 steps, 2D heavy-hex topology | 97% | 22 min | 4 min |\n",
"| Kicked Ising | 28 | Eagle (r3) | 3 unique layers x 8 steps, 2D heavy-hex topology | 97% | 116 min | 23 min |\n",
"| Trotterized Hamiltonian simulation | 40 | Eagle (r3) | 2 unique layers x 10 Trotter steps, 1D chain | 97% | 3 hours | 25 min |\n",
"| Trotterized Hamiltonian simulation | 119 | Eagle (r3) | 3 unique layers x 9 Trotter steps, 2D heavy-hex topology | 95% | 6.5 hours | 45 min |\n",
"| Kicked Ising | 136 | Heron (r2) | 3 unique layers x 15 steps, 2D heavy-hex topology | 99% | 52 min | 9 min |\n",
"\n",
"Accuracy is measured here relative to the ideal value of the observable: $\\frac{\\langle O \\rangle_{ideal} - \\epsilon}{\\langle O \\rangle_{ideal}}$, where '$\\epsilon$' is the absolute precision of the mitigation (set by the user input), and $\\langle O \\rangle_{ideal}$ is the observable at the noiseless circuit.\n",
"'Runtime usage' measures the usage of the benchmark in batch mode (sum over usage of individual jobs), whereas 'total time' measures usage in session mode (experiment wall time), which includes additional classical and communication times. QESEM is available for execution in both modes, so that users can make the best use of their available resources.\n",
"\n",
"The 28-qubit Kicked Ising circuits simulate the Discrete Time Quasicrystal studied by Shinjo et al. (see [arXiv 2403.16718](https://arxiv.org/abs/2403.16718) and [Q2B24 Tokyo](https://www.youtube.com/watch?v=tQW6FdLc6zo)) on three connected loops of ibm_kawasaki. The circuit parameters taken here are $(\\theta_x, \\theta_z) = (0.9 \\pi, 0)$, with a ferromagnetic initial state $| \\psi_0 \\rangle = | 0 \\rangle ^{\\otimes n}$. The measured observable is the absolute value of the magnetization $M = |\\frac{1}{28} \\sum_{i=0}^{27} \\langle Z_i \\rangle|$. The utility-scale Kicked Ising experiment was run on the 136 best qubits of ibm_fez; this particular benchmark was run at the Clifford angle $(\\theta_x, \\theta_z) = (\\pi, 0)$, at which the active volume grows slowly with circuit depth, which - together with the high device fidelities - enables high accuracy at a short runtime.\n",
"\n",
"Trotterized Hamiltonian simulation circuits are for a Transverse-Field Ising model at fractional angles: $(\\theta_{zz}, \\theta_x) = (\\pi / 4, \\pi /8)$ and $(\\theta_{zz}, \\theta_x) = (\\pi / 6, \\pi / 8)$ correspondingly (see [Q2B24 Tokyo](https://www.youtube.com/watch?v=tQW6FdLc6zo)). The utility-scale circuit was run on the 119 best qubits of ibm_brisbane, whereas the 40-qubit experiment was run on the best available chain. The accuracy is reported for the magnetization; high-accuracy results were obtained for higher-weight observables as well.\n",
"\n",
"The VQE circuit was developed together with researchers from the Center for Quantum Technology and Applications at the Deutsches Elektronen-Synchrotron (DESY). The target observable here was a Hamiltonian consisting of a large number of non-commuting Pauli strings, emphasizing QESEM's optimized performance for multi-basis observables. Mitigation was applied to a classically-optimized ansatz; although these results are still unpublished, results of the same quality will be obtained for different circuits with similar structural properties."
]
},
{
"cell_type": "markdown",
"id": "d6fb65de",
"metadata": {},
"source": [
"## Get started\n",
"\n",
"Authenticate using your [IBM Quantum Platform API token](http://quantum.ibm.com/), and select the QESEM Qiskit Function as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "95a715d2",
"metadata": {},
"outputs": [],
"source": [
"import qiskit\n",
"\n",
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
"catalog = QiskitFunctionsCatalog(token=\"<YOUR_IQP_API_TOKEN>\")\n",
"\n",
"qesem_function = catalog.load(\"qedma/qesem\")"
]
},
{
"cell_type": "markdown",
"id": "5f0120d8",
"metadata": {},
"source": [
"## Example\n",
"\n",
"To get started, try this basic example of estimating the required QPU time to run the QESEM for a given `pub`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d56e1440",
"metadata": {},
"outputs": [],
"source": [
"circ = qiskit.QuantumCircuit(5)\n",
"circ.cx(0, 1)\n",
"circ.cx(2, 3)\n",
"circ.cx(1, 2)\n",
"circ.cx(3, 4)\n",
"\n",
"avg_magnetization = qiskit.quantum_info.SparsePauliOp.from_sparse_list(\n",
" [(\"Z\", [q], 1 / 5) for q in range(5)], num_qubits=5\n",
")\n",
"other_observable = qiskit.quantum_info.SparsePauliOp.from_sparse_list(\n",
" [(\"ZZ\", [0, 1], 1.0), (\"XZ\", [1, 4], 0.5)], num_qubits=5\n",
")\n",
"\n",
"job = qesem_function.run(\n",
" instance=\"hub1/group1/project1\",\n",
" pubs=[(circ, [avg_magnetization, other_observable])],\n",
" options={\n",
" \"estimate_time_only\": True,\n",
" },\n",
" backend_name=\"ibm_brisbane\",\n",
")"
]
},
{
"cell_type": "markdown",
"id": "ae10a4c8",
"metadata": {},
"source": [
"The following example executes a QESEM job:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e7351d6b",
"metadata": {},
"outputs": [],
"source": [
"job = qesem_function.run(\n",
" instance=\"hub1/group1/project1\",\n",
" pubs=[(circ, [avg_magnetization, other_observable])],\n",
" backend_name=\"ibm_brisbane\",\n",
")"
]
},
{
"cell_type": "markdown",
"id": "dfe99043",
"metadata": {},
"source": [
"You can use the familiar Qiskit Serverless APIs to check your Qiskit Function workload's status or return results:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "856fe992",
"metadata": {},
"outputs": [],
"source": [
"print(job.status())\n",
"result = job.result()"
]
},
{
"cell_type": "markdown",
"id": "8b901258",
"metadata": {},
"source": [
"## Function parameters\n",
"\n",
"\n",
"| Name | Type | Description | Required | Default | Example |\n",
"| -----| ------| ------------| -------- | ------- | -------- |\n",
"| `pubs` | [EstimatorPubLike](https://docs.quantum.ibm.com/guides/primitive-input-output) |This is the main input. The `Pub` contains 2-4 elements: a circuit, one or more observables, 0 or a single set of parameter values, and an optional precision. If a precision was not specified, then the `default_precision` from `options` will be used| Yes| N/A | `[(circuit, [obs1,obs2,obs3], parameter_values, 0.03)]` |\n",
"| `backend_name`| string|Name of the backend to use |No | QESEM will get least busy device reported by IBM| `\"ibm_fez\"`|\n",
"| `instance` | string| The hub/group/project to use in that format | No | N/A | `“hub1/group1/project1”` |\n",
"| `options` | dictionary |Input options. See **Options** section for more details. | No | See the **Options** section for details. | `{ default_precision = 0.03, \"max_execution_time\" = 3600, \"transpilation_level\" = 0, \"estimate_time_only\" = False}` |\n",
"\n",
"\n",
"\n",
"### Options\n",
"\n",
"\n",
"| Option | Choices | Description | Default |\n",
"| -----| -----------| -------- | ------- |\n",
"| `estimate_time_only` | True / False | Specifies whether to execute the mitigation process or only get QPU time estimation. Please note that the QPU time estimation process does not consume QPU time.| False|\n",
"|`default_precision` | 0 < float | Will apply to `pubs` that don't have presicion. The precision signifies the acceptable error on the expectation values of the observables in absolute value. Namely, the QPU runtime for mitigation will be determined to provide output values for all the observables of interest that fall within a `1σ` confidence interval of the target precision. If multiple observables are provided, the mitigation will run until the target precision is reached for each of the input observables. | 0.02|\n",
"|`max_execution_time` | 0 < integer < 28,800 (8 hours)| Allows you to limit the QPU time, specified in seconds, to be used for the entire QESEM process. Please find additional details below.| 3,600 (one hour)|\n",
"| `transpilation_level` | 0 / 1 | See description below | 1|\n",
"\n",
"<Admonition type=\"caution\">The QPU time estimation changes from one backend to another. Therefore, when executing the QESEM function, make sure to run it on the same backend that was selected when obtaining the QPU time estimation. </Admonition>\n",
"\n",
"<Admonition type=\"note\">QESEM will end its run when it reaches the target precision or when it reaches `max_execution_time`, whichever comes first. </Admonition>\n",
"\n",
"- `max_execution_time`: Allows you to limit the QPU time, specified in seconds, to be used for the entire QESEM process. Since the final QPU time required to reach the target accuracy is determined dynamically during the QESEM job, this parameter enables you to limit the cost of the experiment. If the dynamically-determined QPU time is shorter than the time allocated by the user, this parameter will not affect the experiment. The `max_execution_time` parameter is particularly useful in cases where the analytical time estimate provided by QESEM before the job starts is too pessimistic and the user wants to initiate a mitigation job anyway. After the time limit it reached, QESEM stops sending new circuits. Circuits that have already been sent continue running (so the total time may surpass the limit by up to 30 minutes), and the user receives the processed results from the circuits that ran up to that point. If you want to apply a QPU time limit shorter than the analytical time estimate, consult with Qedma to obtain an estimate for the accuracy achievable within the time limit.\n",
"\n",
"\n",
"- `transpilation_level`: After a circuit is submitted to QESEM, it automatically prepares several alternative circuit transpilations and chooses the one that minimizes QPU time. For instance, alternative transpilations might utilize Qedma-optimized fractional RZZ gates to reduce the circuit depth. Of course, all transpilations are equivalent to the input circuit, in terms of their ideal output. To exert more control over the circuit transpilation, set the transpilation level in the `options`. While `\"transpilation_level\": 1 ` corresponds to the default behavior described above, `\"transpilation_level\": 0 ` includes only minimal modifications required for high-accuracy output; for example, layerification - the organization of circuit operations into layers of simultaneous two-qubit gates. Note that automatic hardware-mapping onto high-fidelity qubits is applied in any case.\n",
"\n",
"| `transpilation_level` | description |\n",
"|:-:|:--|\n",
"| `1` | Default QESEM transpilation. Prepares several alternative transpilations and chooses the one that minimizes QPU time. Barriers may be modified in the layerification step. |\n",
"| `0` | Minimal transpilation: the mitigated circuit will closely resemble the input circuit structurally. Circuits provided in level 0 should match the device connectivity and should be specified in terms of the following gates: CX, Rzz(α), and standard single-qubit gates (U, x, sx, rz, and so on). Barriers will be respected in the layerification step. |\n",
"\n",
"<Admonition type=\"note\">\n",
"Barriers operations are typically used to specify the layers of two-qubit gates in quantum circuits. In level 0, QESEM preserves the layers specified by the barriers. In level 1, the layers specified by the barriers are considered as one transpilation alternative when minimizing QPU time.\n",
"</Admonition>"
]
},
{
"cell_type": "markdown",
"id": "5ec8053b",
"metadata": {},
"source": [
"### Outputs\n",
"The output of a Circuit function is a [PrimitiveResult](/api/qiskit/qiskit.primitives.PrimitiveResult), which contains two fields:\n",
"\n",
"- One [PubResult](/api/qiskit/qiskit.primitives.PubResult) object. It can be indexed directly from the `PrimitiveResult`.\n",
"\n",
"- Job-level metadata.\n",
"\n",
"Each `PubResult` contains a `data` and a `metadata` field.\n",
"\n",
"- The `data` field contains at least an array of expectation values (`PubResult.data.evs`) and an array of standard errors (`PubResult.data.stds`). It can also contain more data, depending on the options used.\n",
"\n",
"- The `metadata` field contains PUB-level metadata (`PubResult.metadata`).\n",
"\n",
"The following code snippet describes how to retrieve the QPU time estimation (i.e., `estimate_time_only` is True):"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "48821756",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The estimated QPU time for this PUB is: \n",
"{'time_estimation_sec': 3600}\n"
]
}
],
"source": [
"print(f\"The estimated QPU time for this PUB is: \\n{result[0].metadata}\")"
]
},
{
"cell_type": "markdown",
"id": "a9e51542",
"metadata": {},
"source": [
"The following code snippet describes how to retrieve the mitigation results (i.e., `estimate_time_only` is False)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fda5f739",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The result of the submitted job had 1 PUB\n",
"The expectation values measured from this PUB are: \n",
"[0.98, 1.01]\n",
"The error-bar values are: \n",
"[0.028, 0.015]\n",
"And the associated metadata contains the original observables, making the results easier to interpret: \n",
"{\n",
" 'observables': [\n",
" SparsePauliOp(\n",
" ['IIIIZ', 'IIIZI', 'IIZII', 'IZIII', 'ZIIII'],\n",
" coeffs=[0.2 + 0.0j, 0.2 + 0.0j, 0.2 + 0.0j, 0.2 + 0.0j, 0.2 + 0.0j]\n",
" ),\n",
" SparsePauliOp(\n",
" ['IIIZZ', 'ZIXII'],\n",
" coeffs=[1.0 + 0.0j, 0.5 + 0.0j]\n",
" )\n",
" ]\n",
"}\n"
]
}
],
"source": [
"print(f\"The result of the submitted job had {len(result)} PUB\")\n",
"print(\n",
" f\"The expectation values measured from this PUB are: \\n{result[0].data.evs}\"\n",
")\n",
"print(f\"The error-bar values are: \\n{result[0].data.stds}\")\n",
"print(\n",
" f\"And the associated metadata contains the original observables, making the results easier to interpret: \\n{result[0].metadata}\"\n",
")"
]
},
{
"cell_type": "markdown",
"id": "35aed54a",
"metadata": {},
"source": [
"## Fetch error messages\n",
"\n",
"If your workload status is ERROR, use job.result() to fetch the error message to fetch the error message as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d95a3f30",
"metadata": {},
"outputs": [],
"source": [
"print(job.result())"
]
},
{
"cell_type": "markdown",
"id": "e9ec2e67",
"metadata": {},
"source": [
"## Get support\n",
"\n",
"The Qedma support team is here to help! If you encounter any issues or have questions about using the QESEM Qiskit Function, please don't hesitate to reach out. Our knowledgeable and friendly support staff are ready to assist you with any technical concerns or inquiries you may have.\n",
"\n",
"You can email us at support@qedma.com for assistance. Please include as much detail as possible about the issue you're experiencing to help us provide a swift and accurate response. You can also contact your dedicated Qedma POC representative via email or phone.\n",
"\n",
"To help us assist you more efficiently, please provide the following information when you contact us:\n",
"\n",
"- A detailed description of the issue\n",
"- The job ID\n",
"- Any relevant error messages or codes\n",
"\n",
"\n",
"We are committed to providing you with prompt and effective support to ensure you have the best possible experience with our Qiskit Function.\n",
"\n",
"We are always looking to improve our product and we welcome your suggestions! If you have ideas on how we can enhance our services or features you'd like to see, please send us your thoughts at support@qedma.com"
]
},
{
"cell_type": "markdown",
"id": "5a6a25c8",
"metadata": {},
"source": [
"## Next steps\n",
"\n",
"<Admonition type=\"tip\" title=\"Recommendations\">\n",
"\n",
"- [Request access to Qedma QESEM](https://quantum.ibm.com/functions?id=7636f111-b7b8-4a00-b22d-5fcc5c5cb3d0)\n",
"\n",
"</Admonition>"
]
}
],
"metadata": {
"description": "Run quantum circuits on noisy QPUs to obtain highly accurate error-free results with highly efficient QPU-time overheads, close to fundamental bounds.",
"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": "QESEM - A Qiskit Function by Qedma"
},
"nbformat": 4,
"nbformat_minor": 5
}