Repeat until success
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.
Setup
No output produced
Build problem
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:
Run in local testing mode
No output produced
Convert to ISA input
Output:
Run the job
Output:
>>> Simulator counts for mid: {'00': 804, '10': 71, '01': 63, '11': 86}
>>> Simulator counts for final: {'0': 696, '1': 328}
Run on IBM hardware
Output:
>>> Connected to ibm_kyiv backend.
Convert to ISA input
Output:
Run the job
Output:
'crh9kwzx30tg008kmm4g'
Output:
>>> Hardware counts for mid: {'00': 3165, '01': 322, '10': 296, '11': 313}
>>> Hardware counts for final: {'1': 1505, '0': 2591}
Output:
>>> Hardware merged data: {'00-1': 993, '01-0': 147, '00-0': 2172, '10-0': 127, '10-1': 169, '11-0': 145, '11-1': 168, '01-1': 175}
Analyze the results
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.773.
We can also test the post-selected output state:
Output:
Expected |1> probability: 0.2. Actual probability 0.314.
Output:
'0.22.0'
Output:
'1.0.2'
Was this page helpful?