Learning Home Catalog Composer Lab
Learning
Home Catalog Composer Lab Return to tutorial
Learning
Repeat until success
BackgroundSetupBuild problemOptimize the circuitsRun on IBM hardwareAnalyze the results

Repeat until success

Category

How-to

Topics

Dynamic circuits
Download notebook Download notebook

Background

This tutorial demonstrates the current capabilities of IBM dynamic-circuit backends to use mid-circuit measurements to produce a circuit that repeatedly attempts its setup until a syndrome measurement reveals that it has been successful.

We will build an abstract circuit that uses the non-parametrized gate set {H,X,S,Toffoli}\{H,\,X,\,S,\,\text{Toffoli}\} to construct a heralded RX(θ)R_X(\theta) gate on a target qubit, where θ\theta satisfies cosθ=35\cos\theta = \frac35. Each iteration of the circuit only has a finite chance of success, but successes are heralded, so we will use our dynamic-circuit capabilities to repeat the setup until it succeeds.

Setup

Authenticate to run code cells
Reset Copy to clipboard

Output:

Authenticate to run code cells
Reset Copy to clipboard

Output:

<IBMBackend('ibm_rensselaer')>

Build problem

A single trial of the probabalistic gate has the following form:

Authenticate to run code cells
Reset Copy to clipboard

Output:

Authenticate to run code cells
Reset Copy to clipboard

Output:

If both measurements of the control bits return 00, the applied gate is RX(θ)R_X(\theta) with cosθ=35\cos\theta = \frac35. If any of the measurements are 11, then the applied gate is simply XX, which is a failure. This is our heralding; we can tell from the measurement whether we applied the correct gate, without disturbing the coherence of the target qubit. Without fully reproducing the mathematics, the success probability of this gate is:

Psuccess=3+i23+i2+31i2=58P_{\text{success}} = \frac{ {|3 + i|}^2 } { {|3 + i|}^2 + 3{|1 - i|}^2 } = \frac58

If there is a failure, we should reset the dirty state, and start again. Since we know what is applied in the case of a failure, we can use this knowledge to perform the reset efficiently, without using a general hardware reset. For the two auxiliary qubits, this is just an XX gate conditioned on its respective measurement being 11. 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 flow.

Authenticate to run code cells
Reset Copy to clipboard

Output:

Qiskit cannot directly represent an inequality condition, which is what we require. We only need to do the repeat if the mid-circuit measurement result was not the bitstring "00". Instead, we can create an if statement with the condition mid_measure == "00", pass an empty block, and then use the else branch to perform the logic we want.

Authenticate to run code cells
Reset Copy to clipboard

Output:

Optimize the circuits

To prepare the circuit to run on real hardware, we use Qiskit's transpile function. By not specifying an optimization_level argument to transpile, we implicitly use level 1, which has light quantum optimization. For now, levels 2 and 3 do not support the dynamic circuits path as some of the optimizations used at those levels are not fully control-flow-aware.

Authenticate to run code cells
Reset Copy to clipboard

Output: