Staring into the soul of a Quantum program

How I made a visualization tool for Q# programs during my Microsoft Quantum internship

This article is part of the Q# Advent Calendar 2020. Stay tuned for new posts on quantum computing each day of this Christmas month!

Photo by ProductionPerig on Dreamstime.com

Quantum development tools

With the growing interest in quantum algorithms and the influx of budding quantum enthusiasts, there is a need for development tools geared towards quantum programming. One such tool is a quantum program visualizer, which was the focus of the internship project I worked on at Microsoft Quantum over the past summer.

How can we visualize quantum programs?

When thinking about how to represent quantum programs or algorithms visually, you might think of quantum circuits. Quantum circuits are the most common way that quantum algorithms are presented in textbooks and other literature. They function like musical scores; you read from left to right, beginning with an input qubit state, followed by a series of gates or operations that act on the qubits.

Quantum teleportation circuit with 3 qubits (one on each line).
Solution for Q# contest question.

Our solution

To overcome the difficulty of representing non-determinism, we can modify the concept of a quantum circuit to visualize a single branch that the quantum program can take. This inherently removes the problem as we are only representing one out of the program’s possible execution paths.

An overview of my internship project

We now have a solution, but how do we implement this visualization?

Example usage of the `%trace` command.

Implementing the %trace command

Let’s take a look at how I implemented the %trace command. It can be broken down into the following main steps:

  1. The Q# operation is passed through a Quantum Simulator.
  2. We attach an ExecutionPathTracer listener onto the Quantum Simulator which keeps track of all operations picked up by the simulator in the program’s execution.
  3. Once the simulation is complete, we retrieve the list of traced-out operations from the ExecutionPathTracer and send it to the Jupyter notebook client as a JSON object.
  4. The client renders the JSON as an HTML string using the circuit visualizer I created.
  5. Finally, the resulting HTML string is displayed in Jupyter notebook.
A quantum circuit with zoomed-in operations.

My internship experience at Microsoft Quantum

In this bonus section, I’ll spend some time to shed some light on my (virtual) internship at Microsoft Quantum since many students might be interested in applying for this internship.

My Quantum care package

⟨ Software Engineer | Quantum Physicist ⟩

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store