Using a Quantum Computer to Create 3D Art With Blender

Iskandar Sitdikov
Qiskit
Published in
4 min readJul 14, 2021

In my opinion, some of the most interesting things happen at the intersection of different disciplines. For example, computational art uses a computer power to create digital paintings — and that’s what we’re going to do today, with a quantum computer. While perhaps not art on its own, this post introduces a way to incorporate measurements from quantum computation into 3D renderings. We will use the Qiskit quantum software development kit for calculations, and we will be using Blender, the VFX development environment, as the digital canvas.

Generative art

Generative art refers to art that in whole or in part has been created with the use of an autonomous system. One of the most-used techniques in generative art is exploiting different distributions generated by random processes. You can read about previous quantum generative art projects on the Qiskit Medium here and here.

Qiskit

Keeping the above in mind, we will try to use the output of Qiskit programs to generate interesting visualizations.

We can start with simple measurements. Today’s quantum processors are noisy, which — as in past quantum generative art exercises — proves useful for this exercise. We can run the calculations on a real quantum backend or use a simulator. Qiskit provides both, and we’ll use a simulator for this example:

from qiskit.providers.aer import AerSimulator
from qiskit.test.mock import FakeYorktown
device_backend = FakeYorktown()
sim_yorktown = AerSimulator.from_backend(device_backend)

We need a circuit to execute. The below four-qubit circuit places qubit 0 into an equal superposition of |0> and |1>, and then entangles it with the other three qubits:

from qiskit import QuantumCircuitN_QUBITS = 4circ = QuantumCircuit(N_QUBITS, N_QUBITS)
circ.h(0)
for idx in range(N_QUBITS - 1):
circ.cx(idx, idx + 1)
circ.measure_all()
circ.draw()

We should get something like this.

Yes, I like consoles :)

We can run circuit and check the outputs, in the form of four-bit strings:

from qiskit import transpiletcirc = transpile(circ, sim_yorktown)
result_noise = sim_yorktown.run(tcirc, shots=1024).result()
counts_noise = result_noise.get_counts(0)
print(counts_noise)

Result:

[{'1100 0000': 4, '0010 0000': 4, '1101 0000': 21, '0100 0000': 47, '0101 0000': 5, '0011 0000': 7, '0111 0000': 24, '1011 0000': 64, '1001 0000': 5, '1111 0000': 366, '0001 0000': 29, '1000 0000': 1, '1110 0000': 27, '1010 0000': 3, '0000 0000': 417}]

Now, we can jump into Blender.

From the Blender website: “Blender is the free and open source 3D creation suite. It supports the entirety of the 3D pipeline — modeling, rigging, animation, simulation, rendering, compositing and motion tracking, video editing and 2D animation pipeline.” It’s really easy to start with, since it has a great community and tons of tutorials.

Everything starts with the cube in Blender. To make it easier to follow, we will keep working with cubes. You can view the entire code example in a GitHub gist here.

The cube!

Blender provides an ability to handle everything through Python, which is extremely useful as we can execute our Qiskit programs right inside Blender.

Useful tab

We can create and move cubes using one line of code:

bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 0))

We can use the output of four-bit strings that resulted from executing the job as the locations of cubes in 3d space.

MARGIN = 0.01
CUBE_SIZE = 0.2
#all_measures comes from the results of our quantum circuit
for row, measures in enumerate(all_measures):
for col, measure in enumerate(measures):
height = measure * 0.003
location = (row * (CUBE_SIZE + MARGIN), col * (CUBE_SIZE +
MARGIN), height)
bpy.ops.mesh.primitive_cube_add(size=CUBE_SIZE,
enter_editmode = False, align='WORLD', location=location,
scale=(1, 1, 1))
cube = bpy.context.active_object
Looks exactly like graph that we can get from qiskit.visualizations.plot_histogram

Let’s run more circuits and stack the results together:

Interesting patterns already begin to emerge from the data:

Solid state preview

Then, of course, we can take artistic license in order to make the scene more dynamic:

Let’s throw in a couple more little details and finish our render!

TA-DA!

I hope you enjoyed quick 3d art overview with Qiskit and Blender. This time, we introduced only the basics, using the noisy outputs of a simple quanutm circuit. However, there’s plenty of room to create more interesting visualizations from the outputs of more complex circuits and algorithms. Next time we will do something much more hardcore from both quantum computing and rendering points of view; I was thinking about Q sphere or artful animation for algorithms. If you have something in mind, let me know!

Something like that :)

Get started with Qiskit here, and for more Qiskit tips and tricks, follow the Qiskit Medium!

--

--