Static analysis for quantum programs

Explore how a quantum program actually fits together.

This project is designed to help visualize how quantum programs work, and to assist in debugging their code. Using code taken from a file or text input, it generates an interactive dependence graph showing relationships between quantum instructions.

The map details the individual steps of a quantum circuit and maps out the connections between each step, approximating entanglement relationships and illustrating dependencies between qubits.

q0 q1 h q0 #0 cx q0,1 #1 z q0 #2 cx q0,1 #3 h q0 #4 measure q0 #5 measure q1 #6
Superdense coding. A backward slice from the measurement of q1 (orange) reaches five of the seven instructions. The two grayed-out instructions only touch q0, after the last operation that could still reach q1 — so neither of them can have affected the result being measured.

Classical programming is deterministic

The normal assumption of programming is that given a chosen input, a specific set of instructions will be executed to produce a certain outcome. This is what is known as deterministic classical programming, whose foundation is built upon bits, pieces of data that store either 0 or 1.

Although a classical program may have conditional branches and produce different results for different inputs, each individual execution follows a defined sequence of operations. One can be certain that given x, y will occur.

Quantum programming is not

Quantum programming runs against this type of deterministic programming by working with the probabilistic behavior of quantum systems. Instead of representing information exclusively as definite 0 or 1 values in bits, quantum programs operate on qubits.

These fundamental units of quantum information can be in a superposition, a quantum state whose measurement outcomes have probabilities determined by its amplitudes. Rather than representing several classical values as separate pieces of data, a quantum state can encode a combination of possible outcomes that is manipulated by quantum operations.

You read probabilities, not answers

A quantum program does not try every answer at once and hand back the right one. Each run ends in a single measured result, so instead, quantum operations modify the probabilities associated with possible outcomes. Quantum algorithms are designed so that useful outcomes can be amplified while undesirable outcomes are reduced or canceled through the behavior of quantum states.

When a qubit is measured, its quantum state produces a classical result. Repeated executions of a quantum program can therefore be used to observe the distribution of possible results and estimate their probabilities.

Programs are circuits, and circuits entangle

Quantum programs are commonly represented as quantum circuits, which consist of a sequence of quantum instructions, or gates, that operate on one or more qubits. Measurements convert quantum information into classical information, and classical information can subsequently influence other operations.

The qubits in these circuits can become entangled. Entanglement occurs when the states of multiple qubits become related in a way that cannot be described by considering each qubit independently. What happens to one qubit in an entangled group is therefore vital to understanding the others.

The map: a Quantum Dependence Graph

The visualization used in this project is known as a Quantum Program Dependence Graph, or QDG. A regular dependence graph represents relationships between instructions in a classical program; a QDG extends this to represent quantum programs.

In it, each quantum instruction becomes a node, and edges between nodes represent dependencies between operations. Measurements can also create dependencies, when their classical results are used to determine later operations.

Slicing: the part that matters

Representing the ways each qubit affects the others, especially in entanglement, is made easier via program slicing. Program slicing identifies the portions of a program that are relevant to a particular instruction or result, a method used in both classical and quantum programming.

Backward slice

Starts with an instruction and traces back to the earlier instructions that influence it.

Forward slice

Does the opposite, working from a starting instruction to the last portion affected by it.

Why visualize it at all

Quantum programs can become difficult to understand as the number of qubits and operations increases. A circuit may contain many gates that interact indirectly through shared qubits, measurements, classical conditions, and entanglement. Reading the source code alone does not necessarily make these relationships obvious.

Visualization can simplify the process of viewing the various processes at play, which makes it easier to debug, to optimize, and to understand quantum programming generally.

What you can do with it

Slice from a gate

Pick any instruction and follow its dependencies backward to everything that feeds it, or forward to everything it can still affect.

Filter by dependency

Follow only data dependencies on qubits, only measurement dependencies, or any combination — each kind is a separate rule in the graph.

See what each gate does

Hover a gate for what it does, its matrix, and which wires are controls and which are targets. Tags mark phase-only gates, phase kickback and measurements whose result is fixed; a slice from a measurement marks the qubits it may be correlated with.

Catch mistakes early

Static checks read your file alongside the parser and flag issues such as out-of-range qubits, a circuit with no measurement, classical bits written twice, and removed Qiskit APIs.

Ready to look at a circuit?

Load one of the bundled examples, or bring your own — a Qiskit .py file or an OpenQASM .qasm file, pasted in or uploaded.

Open the slicer