Unitary Fund

Because evolution is unitary.

Meet the UF Ambassadors – Misty Wahl

Misty Wahl

I was introduced to the Unitary Fund through their inaugural hackathon, unitaryHACK 2021. My journey in quantum formally began in January 2021 with the MITxPro quantum computing course series. At the end of the course, I was looking for practical experience to continue my learning project, and one of the instructors suggested joining a quantum-themed hackathon. A quick search revealed that unitaryHACK was scheduled for the following month. I registered immediately and browsed the list of issues tagged for the hackathon, ultimately selecting one on applying error mitigation to a variational problem.

Hackathon project

One of the projects supported by the Unitary Fund is Mitiq, a Python toolkit for applying quantum error mitigation techniques. Noise in quantum computers can arise from a variety of sources, such as errors in state preparation, gate applications, and measurement, as well as interactions with the environment. Mitiq compiles quantum programs in intelligent ways to reduce the effect of noise on the output. At the time of writing, Mitiq supports the error mitigation techniques Zero Noise Extrapolation, Probabilistic Error Cancellation, and Clifford Data Regression. Mitiq is designed to wrap a user-defined function, which is referred to in the documentation as an “executor.” An executor takes a quantum program as input, executes it on a backend, and returns expectation values.

The challenge presented in the hackathon was to create a tutorial example demonstrating the application of one of the error mitigation techniques in Mitiq to a variational problem. Without error mitigation, noise from the quantum computer would result in poor convergence or non-convergence of the algorithm. Adding error mitigation would then allow convergence or improve convergence. Part of what interested me about the problem was that it was more research-oriented, since there was no guarantee that the desired behavior was actually achievable, although previous demonstrations indicated a solution was likely to exist.

Github issue from unitaryHACK

Creating the tutorial example

I chose a simple Variational Quantum Eigensolver (VQE) problem for the tutorial example, since it is a well-known algorithm with broad practical applications. VQE is a hybrid quantum-classical algorithm used to solve eigenvalue and optimization problems. The VQE algorithm consists of a quantum subroutine run inside of a classical optimization loop. In the example, the goal of the optimization was to find the smallest eigenvalue of a matrix H, which is the Hamiltonian of a simple quantum system. I used Rigetti’s pyQuil frontend to address the need for a full-length Mitiq - pyQuil tutorial (beyond executor setup) and to use the VQE implementation and the VQE example in Grove, another Python library that is related to pyQuil.

In the example, the ansatz consists of a rotation by an angle theta and a layer of static gates. For simplicity, the quantum program is run on a noiseless backend and a depolarizing noise model is added to the static gates. The example is somewhat artificial, but it was kept simple to focus on demonstrating the benefits of error mitigation. The circuit was also kept small to avoid a long execution time on a quantum simulator.

I selected the Zero Noise Extrapolation (ZNE) technique since it is relatively simple to apply, while still yielding interesting results. ZNE computes the observable of interest at several controlled noise levels, beyond the minimum noise strength in the computer, and then extrapolates back to the zero-noise limit. The two main components of ZNE are noise scaling by unitary folding and extrapolation. For more information about ZNE, see the corresponding section in the Mitiq Users Guide.

In developing the tutorial, I encountered some interesting challenges; some I addressed by modifying the problem setup, while others prompted small improvements to Mitiq itself. Initially I kept the circuit in my example short to avoid a long execution time and executed it on a noisy QVM. After experimenting with different extrapolation techniques and scale factors, I saw a negligible mitigation at best. On some runs I found that the extrapolation failed, or that it performed worse than the noisy circuit without mitigation. Eventually I learned that the cause was in the particular noise model of the pyQuil QVM. For short circuits such as the one I initially tested, errors are modeled primarily as measurement errors, which are not mitigated by unitary folding.

The next step was to increase the length of the circuit, but I found the execution time could take 30 minutes or longer, which was impractical for a tutorial example and doubly impractical for execution during the Mitiq documentation build. As a new user of pyQuil, I was unaware that the pyQuil compiler reduced the length of the circuit in very clever ways, so when I added more static gates, the compiled circuit passed to Mitiq still did not have enough gate operations for a valid extrapolation. The compilation step was also costly in execution time.

While investigating how to make the optimization efficient on longer circuits, I learned that pyQuil supports parametric compilation. For parametric programs, the compilation is done outside the optimization loop, and the parameters are updated via a memory map (in v2) or the method program.write_memory (in v3). When I attempted to pass a parametric program to Mitiq and apply ZNE, I discovered that Mitiq would not accept the memory map. I filed an issue to that effect, and it was fixed within a few days! Later I found that support for parametric programs was not entirely necessary for the VQE example, once the compilation step was removed to allow use of custom gates. Instead, I repurposed the demonstration of ZNE with pyQuil and parametric compilation as a separate tutorial.

Energy landscape plot from “ZNE with pyQuil and parametric compilation” tutorial

Even after adding more gates, the desired behavior of ZNE enhancing convergence to the minimum energy was still elusive on the noisy QVM. That was mainly because the circuits were still relatively short, and therefore the errors were still primarily measurement errors. Rather than continuing to add gates to the circuit and increasing the execution time, I decided to use a noiseless QVM and then manually build a depolarizing noise model on the static gates. In pyQuil, noise models can be added by defining custom gates with the Kraus operators representing the desired noise model at a given noise level. It should be noted that Mitiq does not fold custom gates, and therefore custom gates must be defined in the executor function, which is then wrapped by the function applying the chosen error mitigation technique.

In the end, once I defined an appropriate circuit and noise model, I was able to show that applying ZNE enhanced convergence to the minimum energy. While the VQE algorithm is generally considered to be robust to noise (see the VQE tutorial in pyQuil / Grove), I observed that without mitigation, the accumulation of errors still resulted in loss of accuracy and additional iterations required to reach convergence. While there was some variation from run to run, applying ZNE generally improved convergence to the minimum energy in terms of accuracy, number of iterations, or both. The performance increase from ZNE was most evident in the energy landscape plot, where the noisy landscape was noticeably flatter than the landscape generated with ZNE.

Energy landscape plot from “Variational Quantum Eigensolver improved with Zero Noise Extrapolation” tutorial

Community impact

I expect the quantum OSS community can benefit from this project and similar projects in a variety of ways. Of course, continuing to expand the collection of Mitiq examples will help educate the community on using Mitiq and the supported error mitigation techniques. Furthermore, I hope the results demonstrated in the example will encourage users to apply error mitigation to other problems of interest. For instance, it would be interesting to see Clifford Data Regression applied to more use cases, as it is a relatively new technique. Also, more extensive use of error mitigation is likely to motivate refinement of existing methods and the development of new ones.

Finally, I wish to emphasize that as a Mitiq contributor, I have been able to connect directly with the development team and raise improvement suggestions. In response, the team added support for pyQuil parametric programs as mentioned earlier, as well as some improvements to facilitate contributing to Mitiq for Windows users. The Mitiq team also provided many helpful suggestions during the development of the example, and I am grateful for their support. It is my hope that this iterative and collaborative approach will encourage more contributors to join the quantum OSS community and help build the ecosystem.

Stay up to date with what Misty is working on by following her on Twitter, GitHub, and LinkedIn!

This website is hosted on github, and our community follows this code of conduct.

If you have suggestions for changes then please open up a pull request!

©2020 Unitary Fund