---
title: Dynamic software visualization of quantum algorithms with rainbow boxes
authors:
  - Jean-Baptiste Lamy
abstract: Quantum computing has emerged recently as a new computational paradigm. It considers quantum bits (qubits) instead of classical bits. However, quantum algorithms are often very difficult to understand. In this paper, we propose a tool for quantum software visualization. It presents visually the state of multiple-qubits and its evolution at runtime during the execution of a quantum program. This tool allows a unique representation of a quantum state, contrary to the usual vector notation. We show how the problem of visualizing a quantum state can be reduced to a set visualization problem, and our tool uses rainbow boxes to visualize the resulting sets. We also present the application of the proposed tool to quantum teleportation, an algorithm of high importance in cryptography. Finally, we discuss the limit of this approach and its perspectives, in particular for teaching quantum computing.
summaryType: survey
sourceStatus: null
sources:
  - https://doi.org/10.5220/0007247801550163
---

# Dynamic software visualization of quantum algorithms with rainbow boxes

[Read the original paper](https://doi.org/10.5220/0007247801550163)

## Research context and motivation

Lamy presents a visualization of the joint quantum state during simulated execution of a quantum algorithm.
The aim is to help readers follow how gates and measurements change superposition, relative phase, and the grouping of entangled qubits.
The work addresses an existing problem, understanding quantum programs, through a new adaptation of the author's earlier rainbow-boxes technique for overlapping sets.
Its contribution is the conversion of a quantum-state description into sets with visual attributes, together with a working simulator-based implementation and two explanatory examples.

The background combines dynamic software visualization with quantum-state visualization.
Earlier software-visualization systems displayed runtime behavior in conventional programming languages, while the quantum representations discussed here each covered a narrower part of the task.
Circuit diagrams show operation order and the qubits to which gates are applied, but do not display the intervening joint states.
A Bloch sphere represents a single-qubit state, including its relative phase, but does not directly express an entangled multi-qubit state.
Probability bar charts show possible measurement outcomes but do not, by themselves, expose relative phases or tensor-product structure.
Figure 1 supplies the teleportation circuit used later in the paper, and Figure 2 illustrates the Bloch sphere; these are background representations rather than output from the proposed tool.

The motivation is therefore to supplement a circuit's local gate notation with a view of the complete state at each step.
When qubits are entangled, the relevant information includes correlations across qubits, which cannot be reconstructed by treating each wire as an independent pure state.
The proposed view exposes changes in that joint description without requiring the reader to compare long vectors of complex amplitudes.
Teaching quantum programming is an intended use, but the paper does not establish learning benefits through a student study.

## From amplitudes to a phase-normalized state description

A pure state of $n$ qubits is expressed in the computational basis as

$$
|\psi\rangle = \sum_{j=1}^{2^n} a_j |B_j\rangle,
\qquad \sum_j |a_j|^2 = 1.
$$

The coefficient $a_j$ determines both a basis outcome's probability and its phase.
The paper replaces its complex coordinates with $p_j=|a_j|^2$ and a relative phase.
Since $|\psi\rangle$ and $e^{i\theta}|\psi\rangle$ describe the same physical pure state, displaying their unnormalized coefficient phases could give different appearances to equivalent states.
To eliminate this global-phase freedom, Lamy chooses the phase of the lowest-valued computational-basis term with a nonzero amplitude as the reference.
The normalized phase is $\phi'_j=(\arg a_j-\phi_0)\bmod 2\pi$.
Zero-amplitude terms do not provide a phase reference.

The same procedure is applied separately to each factor when the state can be written as

$$
|\psi\rangle = \bigotimes_{k=1}^{m}|\psi_k\rangle,
\qquad |\psi_k\rangle = \sum_j a_{kj}|B_{kj}\rangle.
$$

Each factor is associated with a subset $q_k$ of the qubits, and each of its terms becomes a quadruplet $(q_k,|B_{kj}\rangle,p_{kj},\phi'_{kj})$.
This separates four questions: which qubits belong together, which bit pattern the term represents, how likely that pattern is within the factor, and what phase it has relative to the factor's reference.
For example, $|0\rangle\otimes (|00\rangle+|11\rangle)/\sqrt{2}$ yields one term involving only the first qubit and two equal-probability terms involving the second and third qubits together.

The paper describes this as a unique state representation because the reference convention removes the arbitrary global phase of each separable factor.
The distinction between that convention and the implementation's factor detection matters: consistent phase normalization assumes an appropriate factorization has been identified.
The prototype does not implement a complete test for every possible separable state.

## Set visualization and visual encoding

The reduction to a set problem uses qubits as elements and the qubit subset $q_k$ of each quadruplet as a set.
The remaining three entries become attributes of that set.
This is an adaptation of rainbow boxes, not a new invention of the underlying set-visualization technique.
The related-work discussion motivates rainbow boxes through automatic layout and the availability of height, color, and texture as additional channels.
Figure 3's amino-acid diagram explains the original set representation: columns are elements, horizontal boxes cover members of a set, and holes indicate intervening columns that are not members.
That example provides background for the quantum design rather than quantum-computing evaluation evidence.

In the quantum view, one column represents one qubit and one box represents one term of a factor.
Its horizontal extent covers the qubits involved in that factor, so a multi-column box denotes a jointly represented group and separate column stacks denote separated single-qubit factors.
Box height is proportional to $p_{kj}$, allowing the relative probabilities within a factor to be compared.
Boxes are ordered with lower binary values toward the bottom.
This ordering is based on the basis label, rather than a rule that the most probable box must always be lowest.
The bitstring is written inside the box, and diagonal hatching appears in each column whose bit is $1$.
Thus the hatching connects the bit pattern directly to its qubit columns while the label gives the full pattern explicitly.

Hue encodes relative phase on the cyclic scale shown in Figure 4.
Green represents zero phase relative to the chosen reference; a superposition with several green boxes therefore has equal phases, rather than an absence of superposition.
Gray instead marks a definite basis state for which there is no relative phase to display.
The teleportation example uses blue and orange to show opposite relative phases, making a phase correction visible even when the probabilities stay the same.
These are the paper's encoding choices and explanatory rationale; their perceptual superiority over other encodings is not experimentally compared.

The implemented interaction is a detail-on-demand popup when the pointer hovers over a box.
It displays the represented amplitude term, probability as a percentage, and phase angle in degrees.
Execution is presented through juxtaposed state views labeled with their step and operation, allowing readers to compare the state before and after a gate or measurement.
The paper shows these as a horizontal sequence for the Bell pair and a grid of consecutive steps for teleportation.
It does not report an animation comparison or an evaluation of alternative temporal layouts.

## Implementation and entanglement tracking

The implementation uses Python 3 and ProjectQ in simulation mode.
ProjectQ's `cheat()` method provides the internal complex amplitudes from which the displayed probabilities and phases are computed.
This is a visualization of a simulated state, rather than a system that reads a complete unknown quantum state nondestructively from a physical processor.
The gate labels in the example figures use ProjectQ syntax, such as `H | q1`.

To identify qubit groups, the prototype traces operations through the program.
It begins with separated qubits, keeps that grouping under single-qubit gates, groups qubits associated with multi-qubit gates, and separates a measured qubit after computational-basis measurement.
This is an operational heuristic, rather than a guarantee that every multi-qubit gate creates entanglement or that the current grouping is always irreducible.
The author explicitly notes that a later gate can undo earlier entanglement, which this tracking method can miss.

The examples keep columns in register order and do not use the column-order optimization normally associated with rainbow boxes.
The author reports that this is sufficient for the small examples, where jointly operated qubits are conveniently adjacent.
For nonadjacent members of a group, holes would be required in a spanning box.
This design decision should be read within the demonstrated two- and three-qubit cases; the paper does not provide a large-register performance or readability study.

## Bell-pair and teleportation walkthroughs

Figure 5 follows a Bell pair through five states.
Initially, two separate gray boxes show $|0\rangle$ for both qubits.
Applying a Hadamard to the first qubit creates two equal-height green boxes, showing equal probabilities and equal relative phases while the second qubit remains separate.
After CNOT, the $|00\rangle$ and $|11\rangle$ boxes span both columns, depicting $(|00\rangle+|11\rangle)/\sqrt{2}$.
The illustrated measurement of the first qubit returns $1$, leaving two separate gray, hatched boxes for $|1\rangle$.
Measuring the second qubit then leaves the picture unchanged because its outcome is already certain.
The sequence explains both correlation and the difference between a state-changing measurement and a subsequent measurement of a definite state.



Figure 6 shows the tool's teleportation output, with steps corresponding to the circuit in Figure 1.
The first qubit begins in a superposition with unequal outcome probabilities and a nonzero relative phase.
Hadamard and CNOT prepare a Bell pair on the other two qubits; a further CNOT joins the three-qubit description, and a Hadamard on the first qubit produces eight displayed basis terms.
Their heights are not all equal.
Rather, the figure's pattern balances the marginal probability of $0$ and $1$ for each qubit while retaining the input state's unequal amplitudes and phase relationships within pairs of terms.
Reading the eight boxes as four pairs exposes four possibilities for the receiver's state: the original pattern, swapped basis values, a phase flip, or both transformations.

The illustrated measurement branch returns $q_1=1$ and $q_2=0$.
The corresponding panels remove incompatible terms and leave the receiver's qubit with the appropriate conditional state.
The correction controlled by $q_2$ performs no bit flip for this branch, while the correction controlled by $q_1$ changes the receiver's phase.
The orange box becomes blue, and the receiver's final height and color pattern matches the sender's initial pattern.
The example therefore shows why the classical measurement results determine the required corrections and why probability alone would not show whether the phase correction succeeded.

## Evidence, limitations, and future work

The paper's evidence consists of the formal construction, implementation description, and two worked visualization examples.
It reports no controlled user study, quantitative task-accuracy comparison, usability experiment, or runtime benchmark.
The author describes personal gains in understanding and proposes that students could explore alternative initial states and operation sequences, but these observations do not establish educational effectiveness.
The major contribution is an integrated representation of factor membership, basis values, probabilities, and phases across an execution trace, rather than an empirically validated ranking of visualization techniques.

The principal acknowledged technical limitation is incomplete separability detection through operation tracing.
The paper proposes automatic tensor-product factorization as a more robust replacement and cites the hardness of the general quantum separability problem as background motivation.
It does not analyze the complexity or practical performance of a concrete replacement factorization algorithm for its simulated pure states.
The phase-normalization convention also does not remove the exponential number of possible basis terms: a fully populated $n$-qubit factor can still require $2^n$ boxes.
This follows from the representation, while the paper's demonstrations establish feasibility only for the small examples shown.

There is a numerical inconsistency in the teleportation description: the printed initial coefficient $0.776$ for $|1\rangle$ implies an approximately $60\%$ probability, whereas the accompanying prose and Figure 6 depict about $40\%$ for that outcome.
The qualitative account above follows the visible sequence without treating the printed coefficient and the plotted probability as mutually verified measurements.
This does not affect what the figure demonstrates about box span, relative height, phase hue, and conditional correction.

The stated future work is to evaluate the visualization with computer-science students, implement automatic tensor-product factorization, integrate more deeply with ProjectQ, and extend the approach beyond circuit-based computing to adiabatic and one-way quantum computation.
These are proposed extensions, not capabilities evaluated in the reported prototype.
