#### Quantum Computing

# How to measure and reset a qubit in the middle of a circuit execution

February 11, 2021 | Written by: Paul Nation and Blake Johnson

Categorized: Quantum Computing

Share this post:

IBM Quantum is working to bring the full power of quantum computing into developers’ hands in the next two years via the introduction of dynamic circuits, as highlighted in our recently released Quantum Developer Roadmap. Dynamic circuits are those circuits that allow for a rich interplay between classical and quantum compute capabilities, all within the coherence time of the computation, and will be crucial for the development of error correction and thus fault tolerant quantum computation. However, there are many technical milestones along the way that track progress before we achieve this ultimate goal. Chief among these is the ability to measure and reset a qubit in the middle of a circuit execution, which we have now enabled across the fleet of IBM Quantum systems available via the IBM Cloud.

Measurement is at the very heart of quantum computing. Although often overlooked, high-fidelity measurements allow for classical systems (including us humans) to faithfully extract information from the realm in which quantum computers operate. Measurements typically take place at the end of a quantum circuit, allowing, with repeated executions, one to gather information about the final state of a quantum system in the form of a discrete probability distribution in the computational basis. However, there are distinct computational advantages to being able to measure a qubit in the middle of a computation.

Mid-circuit measurements play two primary roles in computations. First, they can be thought of as Boolean tests for a property of a quantum state before the final measurement takes place. For example, one can ask, mid-circuit, whether a register of qubits is in the plus or minus eigenstate of an operator formed by a tensor product of Pauli operators. Such “stabilizer” measurements form a core component of quantum error correction, signaling the presence of an error to be corrected. Likewise, mid-circuit measurements can be used to validate the state of a quantum computer in the presence of noise, allowing for post-selection of the final measurement outcomes based on the success of one or more sanity checks.

Measurements performed while a computation is in flight can have some other surprising functions, too — like directly influencing the dynamics of the quantum system. If the system is initially prepared in a highly entangled state, then a judicious choice of local measurements can “steer” a computation in a desired direction. For example, we can produce a three-qubit GHZ state and transform it into a Bell-state via an x-basis measurement on one of the three qubits; this would otherwise yield a mixed state if measured in the computational basis. More complex examples include cluster state computation, where the entire computation is imprinted onto the qubit’s state via a sequence of measurements.

### Resetting a qubit

Closely related to mid-circuit measurements is the ability to reset a qubit to its ground state at any point in a computation. Many critical applications, such as solving linear systems of equations, make use of auxiliary qubits as working space during a computation. A calculation requires significantly fewer qubits if, once used, we can return a qubit to the ground state with high-fidelity. With system sizes in the range of 100 qubits, space is at a premium in today’s nascent quantum systems, and on-demand reset is necessary for enabling complex applications on near-term hardware. In Figure 1, below, we highlight an example of the quality of the reset operations on IBM Quantum’s current generation of Falcon processors, on the Montreal system, by looking at the error associated with one or more reset operations applied to a random single-qubit initial state.

Internally, these reset instructions are composed of a mid-circuit measurement followed by an x-gate conditioned on the outcome of the measurement. These conditional reset operations therefore represent one of IBM Quantum’s first forays into dynamic quantum circuits, alongside our recent results demonstrating an implementation of an iterative phase estimation algorithm. However, while the control techniques necessary for iterative phase estimation are still a research prototype, you can use mid-circuit measurement and conditional resets, today.

We can incorporate both concepts illustrated here into simple examples. First, Figure 2 shows a circuit utilizing both mid-circuit measurements and conditional reset instructions for post-selection and qubit reuse.

This circuit first initializes all of the qubits into the ground state, and then prepares qubit 0 (q0) into an unknown state via the application of a random SU(2) unitary. Next, it projects q0 into the x-basis with eigenvalues 0 or 1 imprinted on q1 indicating if the qubit is left in the |+> (0) or |-> (1) x-basis states. We measure q1, and store the result for later use as a flag qubit for identifying which output states correspond to each eigenvalue. Step 3 of the circuit resets the already-measured q1 to the ground state, and then generates an entangled Bell pair between the two qubits. The Bell pair is either |00>+|11> or |00>-|11> depending on if q0 is in the |+> or |-> state prior to the CNOT gate, respectively. Finally, in order to distinguish these states, we use Hadamard gates to transform the state |00>-|11> to |01>+|10> before measuring.

Figure 3 shows the outcome of executing such a circuit on the seven-qubit IBM Quantum Casablanca system, where we see that that the measurement of the flag qubit value measured before (in bold) correctly tracks the expected Bell states generated at the output. Collecting marginal counts over the flag qubit value indicates the proportion of the initial random q0 state that was in the |+> or |-> state after the projection. For the example considered here, these values are ~16 percent and ~84 percent, respectively. The dominant source of the error in the result is dephasing due to the relatively long (~4㎲) duration of measurements on current generation systems. Future processor revisions will bring faster measurements, reducing the effect of this error.

Next, we consider the computational advantages of using reset to reduce the number of qubits needed in a 12-qubit Bernstein-Vazirani problem (Fig. 3). As written, this circuit cannot be implemented directly on an IBM Quantum system, but rather requires the introduction of SWAP gates in order to satisfy the limited connectivity in systems such as our heavy-hex based Falcon and Hummingbird processors. Indeed, compiling this circuit with Qiskit yields a circuit that requires 42 CNOT gates on a heavy-hex lattice. The fidelity of executing this compiled circuit on the IBM Quantum Kolkata system yields a disappointing 0.007; the output is essentially noise.

However, with the ability to measure and reset qubits mid-flight, we can transform any Berstein-Vazirani circuit into a circuit over just two qubits requiring no additional SWAP gates. For the previous example, the corresponding circuit is:

And execution on the same system gives a vastly improved fidelity of 0.31; a 400x improvement over the standard implementation. This highlights how, with mid-circuit measurement and reset, it is possible to write compact algorithms with markedly higher fidelity than would otherwise be possible without these dynamic circuit building blocks.

Mid-circuit measurement and conditional reset represent an important first step toward dynamic circuits — and one that you can begin implementing into your quantum circuits as we speak. We’re excited to see what our users can do with this new functionality, while we continue to expand the variety of circuits that our devices can run. We hope you’ll follow along as we implement our development roadmap; we’re working to make the power of dynamic circuits a regular part of quantum computation in just a few years.

## IBM Quantum

### Quantum starts here

**Paul Nation**

Research Staff Member, IBM Research

**Blake Johnson**

Quantum Platform Lead, IBM Quantum

### We’ve moved! The IBM Research blog has a new home

In an effort better integrate the IBM Research blog with the IBM Research web experience, we have migrated to a new landing page: https://research.ibm.com/blog

### Pushing the boundaries of human-AI interaction at IUI 2021

At the 2021 virtual edition of the ACM International Conference on Intelligent User Interfaces (IUI), researchers at IBM will present five full papers, two workshop papers, and two demos.

### From HPC Consortium’s success to National Strategic Computing Reserve

Founded in March 2020 just as the pandemic’s wave was starting to wash over the world, the Consortium has brought together 43 members with supercomputing resources. Private and public enterprises, academia, government and technology companies, many of whom are typically rivals. “It is simply unprecedented,” said Dario Gil, Senior Vice President and Director of IBM Research, one of the founding organizations. “The outcomes we’ve achieved, the lessons we’ve learned, and the next steps we have to pursue are all the result of the collective efforts of these Consortium’s community.” The next step? Creating the National Strategic Computing Reserve to help the world be better prepared for future global emergencies.