Repeat until success
Estimated QPU usage: 4 seconds (tested on IBM Canberra)
Background
This tutorial demonstrates how certain IBM Quantum™ systems (those that support dynamic circuits) use mid-circuit measurements to produce a circuit that repeatedly attempts its setup until a syndrome measurement reveals that it has been successful.
Build an abstract circuit that uses the non-parametrized gate set to construct a heralded gate on a target qubit, where satisfies . Each iteration of the circuit has a finite chance of success, but because successes are heralded, dynamic circuit capabilities are used to repeat the setup until it succeeds.
Requirements
Before starting this tutorial, ensure that you have the following installed:
- Qiskit SDK v1.0 or later, with visualization support (
pip install 'qiskit[visualization]' ) - Qiskit Runtime 0.22 or later (
pip install qiskit-ibm-runtime )
Step 1: Map classical inputs to a quantum problem
No output produced
A single trial of the probabalistic gate has the following form:
No output produced
Output:
If both control bit measurements return , the gate with is applied. If any of the measurements are , gate is applied, which is a failure. This is the heralding; you can tell from the measurement whether the correct gate was applied, without disturbing the coherence of the target qubit. Without fully reproducing the mathematics, the success probability of this gate is:
If there is a failure, reset the "dirty" state and start again. Because you know what is applied in the case of a failure, you can use this knowledge to perform the reset efficiently without using a general hardware reset. For the two auxiliary qubits, this is an gate conditioned on its respective measurement being . IBM® hardware has a special fast path for when qubits are conditioned on the result of their own measurement, so this is more efficient than most control flows.
No output produced
Qiskit cannot directly represent an inequality condition, which is required for this exercise. You only need to repeat if the mid-circuit measurement result was not the bitstring
Output:
Step 2. Optimize problem for quantum execution
To reduce the total job execution time, V2 primitives only accept circuits and observables that conforms to the instructions and connectivity supported by the target system (referred to as instruction set architecture (ISA) circuits and observables).
Convert to ISA input
Output:
>>> Connected to ibm_cairo backend.
Output:
Step 3. Execute using Qiskit primitives
Output:
'cs29tes965y000852sb0'
Output:
>>> Hardware counts for mid: {'10': 480, '00': 2852, '11': 313, '01': 451}
>>> Hardware counts for final: {'1': 1590, '0': 2506}
Output:
>>> Hardware merged data: {'10-1': 224, '00-1': 971, '10-0': 256, '11-1': 198, '00-0': 1881, '11-0': 115, '01-0': 254, '01-1': 197}
Step 4. Post-process, return result in classical format
A successful result is one in which the measurements on the two controls end in the
No output produced
Output:
Expected success rate 0.859. Actual rate 0.696.
We can also test the post-selected output state:
Output:
Expected |1> probability: 0.2. Actual probability 0.340.
Tutorial Survey
Tutorial Survey Please take one minute to provide feedback on this tutorial. Your insights will help us improve our content offerings and user experience. |
Was this page helpful?