Creating Fractal Art With Qiskit

Qiskit
Qiskit
Published in
6 min readJun 1, 2022

--

By Wiktor Mazin, Principal Data Scientist and IBM Quantum Ambassador

Two fractals produced with Qiskit running on real quantum hardware (Image credit: Wiktor Mazin. CC-BY)

New students to quantum computing will tell you that it’s hard to visualize the complex mathematics of qubits. Typically, we rely on the Bloch sphere and Q-sphere. However, given the richness of the field of complex numbers, there are plenty of more visually interesting ways to represent quantum information.

One such way is through fractals. Fractals have long been a field of interest and exploration among mathematicians, artists, psychologists, neuroscientists, and authors. They comprise some amazing shapes: the Mandelbrot set, Romanesco broccoli, snow flakes, tree branches, copper crystals, and more. They’re visually stunning, yet, mathematically simple, and we can use them to visualize various things in our universe — including qubit states. In this blog post, I’ll demonstrate how to generate your own fractals using both quantum simulators and real quantum computers.

My own fascination for fractals started when I was in university, taking several courses with my late professor Erik Mosekilde — this project is in his honor — at the Technical University of Denmark. Mosekilde held captivating lectures on chaos theory, fractals, and nonlinear dynamics. He used to tell us how exciting it was to see seemingly complicated systems described using relatively simple mathematics. For about a year now, I’ve been very fascinated by quantum computing too, and earlier this year I certified as a quantum developer covering e.g. visualizations.

Recently, I’ve worked to show how we can visualize the inner workings of quantum computation using fractals. I created two notebooks, available on GitHub. The first notebook demonstrates this with one qubit using both a noise-free quantum simulator and running on a real quantum computer. The second notebook devises a way to use fractals to visualize two-qubit quantum circuits. This project is a proof-of-concept, and, for now, the current translation necessarily loses quantum information when we combine all of the amplitudes into a single complex number. However, they are a beautiful demonstration of the complex numbers underlying quantum more generally.

Complex numbers and fractals

As a quick review: quantum computing leverages the properties of quantum superposition, interference, and entanglement to perform calculations. We use the mathematics of vectors, matrices, and complex numbers to write down what qubit states look like, where complex numbers are those of the form a + bi, i being equal to the square root of negative 1. Complex numbers find use across physics, and are a necessity in order for quantum theory to accurately describe nature,

Meanwhile, fractals are mathematical objects that exhibit similar patterns at all scales, so they can represent systems that display self-similarity across both space and time. There are different iterative techniques for generating fractals, one of them being escape-time fractals like the Julia set. We compute these fractals by assigning a complex number to every point on the complex plane — we would plot the complex number z = (x + yi) at (x,y). We iteratively apply a function to each point. If the function converges for the point, it’s part of the fractal and we chose a color for it. If it diverges, it is not and it remains uncolored.

Julia set fractals are a simple kind of escape-time fractal where iteratively update the value of z using the formula z = z² + c, with c being a complex constant. If the absolute value of z stays below 2 after a finite number of iterations, that point is said to be in the Julia set and is colored accordingly. Since the power of quantum states comes from their complex coefficients, we can use these coefficients as the c of a Julia set.

As I work at IBM, I think it’s a fun fact that the closely related Mandelbrot set is named after the former IBMer, Benoit Mandelbrot. In particular, the Mandelbrot set is just one of many maps from the complex plane to itself, showing where the Julia sets are within that plane. By changing c and thus zooming in on a particular point in the Mandelbrot set, we may obtain the related Julia set.

The notebooks

I have created 1-qubit and 2-qubit notebooks to create fractals based on generated quantum circuits.

You can create a 1-qubit quantum circuit by using the Circuit Composer widget, or code one directly in python using Qiskit. The Circuit Composer widget allows you to create a 1-qubit quantum circuit by simply dragging nodes into the canvas. Best fractal results are achieved when the resulting circuit is not on the Bloch sphere’s diagonals. You may need to experiment with different gates, phases and circuits in order to produce a circuit that generates an interesting fractal. A default circuit is provided that yields the 1-qubit fractals at the start of the blog.

A 1-qubit quantum circuit results in a statevector with two complex amplitudes, i.e. two complex numbers. For this proof-of-concept, I obtain the single Julia set complex number c, by dividing the first complex amplitude by the second — though in future iterations of this project, I hope to find ways to more meaningfully convey quantum information. The Julia set function is constructed with inspiration from another github project, resulting in the corresponding fractal. This notebook also shows how to leverage a real quantum computer by using a simple algorithm to modify the previous statevector to obtain the corresponding noise-reflecting statevector. As each run will provide slightly different measurement counts, replicating the process may lead to different fractals each time.

Circuits for creating fractals

The 2-qubit notebook allows you to create a 2-qubit entangled quantum circuit with the Circuit Composer widget like the default provided that represents a Bell state followed by a U-gate rotation (resulting in a nonmaximally entangled state). The resulting fractals are at the top of this blog. Best fractal results are achieved when all four basis states come into play. Again, you may need to experiment with different gates, phases and circuits in order to have a circuit that generates a beautiful fractal.

With two qubits you have 4 complex amplitudes. In order to get the single complex number c for the Julia set, I once again perform divisions of the complex amplitudes. This also means that if you create a 1-qubit circuit that results in the same complex number, you’ll see the same fractal as in the 2-qubit case; again, I leave it to future exploration to see how to meaningfully combine this data. As previously stated, this notebook also shows how you can leverage a real quantum computer by using the counts obtained to modify the ideal statevector. As each run will provide slight different counts, you’ll see a new fractal each time.

Quantum Computing generated fractals and fractal art

Fractal art has been around since the mid ’80s, and talented fractal artists include Desmond Paul Henry, Hamid Naderi Yeganeh, Carlos Ginzburg, Vicky Brago-Mitchell, Scott Draves, Kerry Mitchell and Jackson Pollock. With quantum computing the aesthetics of fractal patterns are taken into another realm, for me.

Fractals have the potential to be an exciting way to visualize quantum information that bridges art, science, and nature. Fractals generated by quantum computers reflect the complexity of quantum computing while providing a new lens through which to think about it. I hope to advance this project so that fractal art generated on a quantum computer can help elucidate the connection between abstract computer-generated mathematical structures and natural, physical processes. At the same time, I see this project as part of a broader movement of artists using quantum computing and quantum mechanical principles to create art.

Science, technology, and art have a long history of merging in ways that surprise and delight. Consider fractals, nature’s patterns formed by repeating simple mathematical rules over and over. The current work is exploring how fractal patterns can be used to visualize quantum information, both on fault-tolerant quantum computers and on today’s noisy quantum computers.

Head to the notebooks and start creating your own beautiful fractals.

--

--

Qiskit
Qiskit

An open source quantum computing framework for writing quantum experiments and applications