Qubit Magic: Creating Mythical Creatures with Quantum Computing
TUTORIAL

What can you do with a qubit?
Think about the nature of a single qubit. It may not appear all that magnificent at first glance.
In fact, it may seem that there aren't many interesting things that just one qubit can be used for.
However, with a little creativity, we can do a lot of impressive feats. One of these includes the fascinating ability to generate images, music, and in this article— mythical creatures!
Generating amazing images at the quantum level
Visualizing a qubit may seem like a fairly abstract idea. After all, qubits are on the microscopic level, making them difficult to grasp.
However, we can leverage the amazing properties of qubits to visualize them as data in imaginative and beautiful ways.
One such method is by leveraging the unique properties of a qubit in order to generate descriptive attributes that can be used for the creation of images, sound, and much more.
Properties of superposition
Quantum computing provides the ability for a qubit to represent two values simultaneously. This is a property called superposition.
When a qubit is in superposition, it can represent both the values zero and one – at the same time. This allows for quadratic and even exponential increases in calculations.
When a qubit is in superposition, it holds distinct properties for its magnitude and phase. These refer to the spin on the qubit, which also corresponds to its likelihood of measuring as a 0 or 1.

We can extract these properties from the qubit and decode them into descriptive textual attributes, which can then be used to generate images through Large Language Models, such as StableDiffusion, Huggingface, or DALL-E.
Creating the quantum circuit
Let's begin by creating a quantum circuit using a single qubit. This is shown in the example below.
# Define the initial state vector.
initial_state = [1/np.sqrt(2), 1/np.sqrt(2)]
# Create a quantum circuit with one qubit.
qc = QuantumCircuit(1)
# Initialize the qubit with the initial state vector.
qc.initialize(initial_state, 0)
Next, we'll allow the user to select from a series of quantum gates (X, Y, Z, H, S, T) to apply to the qubit in order to transform its properties. Each gate performs a different operation on the qubit, modifying its magnitude and phase.
For example, the X-gate flips the state of a qubit from 0 to 1. By contrast, the Z, S, and T gates modify the phase of a qubit. This has the effect of rotating it around the Z-axis.
Each operation slightly changes the measurement properties of the qubit and it's this precise change that we can leverage for generating unique images!
Obtaining a state vector
Once the user has performed a series of quantum operations on the qubit, we can measure the result and obtain a state vector.
A qubit's state vector is similar to its fingerprint. It provides a unique view for the properties of magnitude and phase that the qubit currently holds.
# Simulate the circuit using the statevector simulator
simulator = Aer.get_backend("statevector_simulator")
result = execute(qc, simulator).result()
statevector = result.get_statevector()
An example of a state vector for a qubit is shown below.
[-0.70710678–4.44089210e-16j -0.70710678–3.33066907e-16j]

Extracting color, power, and magic
A state vector consists of two components, which we can refer to as alpha and beta.
Each component within the state vector can be broken down further into magnitude (r) and phase (theta). This results in obtaining four distinct values from a qubit (r1, theta1, r2, theta2). We can map these values directly to descriptive text attributes.
# Get the first and second components of the state vector.
alpha = state_vector[0]
beta = state_vector[1]
# Get the magnitude and phase of each component.
r1 = np.abs(alpha)
theta1 = np.angle(alpha)
r2 = np.abs(beta)
theta2 = np.angle(beta)
Since we want to generate images of amazing mythical creatures, the attributes that we use can include size, color, power, and magic.
# Define a dictionary of words for each attribute.
attribute_words = {
"size": ["tiny", "small", "medium", "large", "huge"],
"color": ["red", "green", "blue", "black", "rainbow"],
"power": ["feeble", "weak", "strong", "powerful", "mighty"],
"magic": ["mundane", "ordinary", "magical", "enchanting", "mystical"]
}
# Map the magnitude and phase values to indices
size_index = map_value_to_index(r1, 0, 1, len(attribute_words["size"]))
color_index = map_value_to_index(r2, 0, 1, len(attribute_words["color"]))
# ...
# Get the attribute words from the dictionary using the indices
size_word = attribute_words["size"][size_index]
color_word = attribute_words["color"][color_index]
# ...
# Concatenate the attribute words into a string separated by commas
attribute_string = f"{size_word}, {color_word}, {power_word}, {magic_word}"
In the above code example, we've defined a list of text attributes for our mythical creatures. Each attribute is mapped to the qubit's state vector.
The result is a sentence that can be used as a prompt for large language model image generation.
Generating an LLM prompt
Now that we've obtained the attributes for our mythical creature, we need to generate the Llm prompt.
Putting the code from above together into a single method, results in the following helper method to generate the required text.
Python">def generate_prompt(statevector):
# Generate an image from Huggingface using the prompt "A mythical creature with the quantum state vector [α β]".
alpha = statevector[0]
beta = statevector[1]
# Get list of attributes from the state vector.
attributes = generate_attribute_words(statevector)
# Create an LLM prompt with the quantum state vector [{alpha} {beta}].
prompt = f"A mythical monster that is " + attributes + " with the quantum state vector " + statevector
return prompt
The resulting state vector will now be converted into an LLM prompt.
A mythical monster that is large, blue, powerful, magical with the quantum state vector [α β].
Bringing qubits to life as amazing creatures
The final step is to breath some life into our qubit's state vectors by programmatically calling an LLM image generation service.
Amazingly, some large language models (Bing's DALL-E) understand how to directly interpret Quantum Computing state vectors as images. They can use the vectors directly in order to visualize them in creative ways.
For example, below is a response from Bing's DALL-E, after being asked to create an image based upon a quantum state vector.
The insect has two wings that are shaped like the quantum state vector [-0.70710678–4.44089210e-16j -0.70710678–3.33066907e-16j], with the real and imaginary parts represented by the length and angle of the wings respectively.
This powerful capability of LLMs is further demonstrated below through visualization of a qubit's state vector, in combination with the descriptive attributes from our program.

The full source code can be found here.
Potential of real-world applications
Generating content from qubits through large language models has the potential to go far beyond images. In fact, with a little creativity and practice, this technology holds real-world applications as well.
Consider the idea of generating more abstract products from quantum computing states. Examples may include:
- Poetry or written stories
- Music or speech
- Business ideas
- Diagrams and charts
- Software programs
LLMs excel at producing a variety of content and can do so in combination with the power of quantum computing.
The sky is the limit
I hope this article piques your excitement into quantum computing and opens the door to even more possibilities.
By combining two incredible emerging technologies of quantum computing and LLMs, and sprinkling in a bit of imagination, we can bring forward incredible possibilities.
Now, it's your turn!
About the Author
If you've enjoyed this article, please consider following me on Medium, Twitter, and my website to be notified of my future posts and research work.