Skip to main content

Generative Design and Quantum Computing - Part 3

·1253 words·6 mins

Blog Post: Exploring Phase and Amplitude in Quantum Circuits with Turtles
#

In our last post, we used turtles to visualize key quantum concepts such as superposition and entanglement, showing how populations of qubits can encode complex information like the direction of a turtle. Now, we’re going to take a step further by introducing phase and amplitude—two fundamental properties of qubits that allow us to perform meaningful computations and optimizations. We’ll continue using our turtles to explore these ideas interactively, as they help us visualize how quantum states evolve and interact.

What Are Phase and Amplitude, and Why Do They Matter?
#

In quantum computing, amplitude represents the probability associated with a qubit being in a particular state. Each quantum state is described by a complex number whose magnitude squared gives the probability of observing that state upon measurement. Manipulating the amplitude allows us to adjust the likelihood of measuring specific outcomes, which is critical for designing quantum algorithms. To adjust the amplitude, one might use quantum gates such as the Ry gate, which rotates the qubit around the Y-axis of the Bloch sphere. For example, applying an Ry(θ) gate to a qubit will rotate its state by an angle θ, effectively changing the amplitude of the qubit’s state. This rotation can increase or decrease the probability of the qubit being measured in a particular state, allowing precise control over the qubit’s behavior in a quantum algorithm.

Phase is manipulated by applying quantum gates that adjust the relative “angle” between the complex numbers describing different quantum states. This adjustment doesn’t directly change measurement probabilities but is crucial for quantum interference. By using gates like the Z gate or controlled phase gates, we can create constructive or destructive interference patterns, enhancing desired outcomes and suppressing undesired ones. This ability to manipulate phase, along with amplitude, provides powerful tools for encoding and processing information in quantum systems, essential for effective computation and optimization in quantum circuits.

For more information on gates and how they work please see this post: Quantum Gates

Phase and Amplitude: A Visual Overview
#

The 3D plot below shows how amplitude and phase influence the probability of measuring a quantum state as |0⟩.

3D Plot of State vs Amplitude vs Phase

  • The x-axis represents amplitude rotation in radians, which changes the likelihood of the qubit being in state |0⟩ or |1⟩.
  • The y-axis represents the phase shift, which modifies the relative phase of the quantum state.
  • The z-axis represents the probability of measuring the state |0⟩, highlighting how combinations of amplitude and phase create patterns of constructive and destructive interference.

This plot illustrates how we can manipulate qubits to control their probabilities using both amplitude and phase, which are fundamental to building quantum algorithms.

Exploring Phase and Amplitude with a Quantum Circuit
#

To understand how phase and amplitude work together, let’s dive into a simple quantum circuit. The code snippet below demonstrates how to create a circuit that leverages phase interference to manipulate qubit states:

class QuantumTurtle:
    def __init__(self):
        self.qubit = cirq.NamedQubit("Turtle")

    def create_quantum_circuit(self):
        """Create a quantum circuit using phase interference patterns."""
        circuit = cirq.Circuit()

        # Step 1: Create initial superposition with controlled amplitude
        # Ry(π/2) creates an equal superposition of |0⟩ and |1⟩
        # This gives each state an equal initial amplitude of 1/√2
        amplitude_angle = np.pi / 2  # Equal superposition
        circuit.append(cirq.ry(amplitude_angle)(self.qubit))

        # Step 2: Add phase rotation - this will affect the walking direction
        # Z-rotation adds a relative phase between |0⟩ and |1⟩ states
        # The \u27e8 values in the original were unicode escape sequences for ⟩
        # This phase difference will be converted to amplitude difference by the Hadamard
        phase_angle = random.uniform(0, 2 * np.pi)
        circuit.append(cirq.Z(self.qubit) ** (phase_angle / (2 * np.pi)))

        # Step 3: Convert phase to measurable amplitude
        # The Hadamard gate converts phase differences into amplitude differences
        # through quantum interference:
        # - When phases align: constructive interference increases amplitude
        # - When phases oppose: destructive interference decreases amplitude
        circuit.append(cirq.H(self.qubit))

        return circuit

Explanation of the Circuit
#

  1. Step 1: Superposition with Amplitude Rotation

    • The Ry(π/2) gate places the qubit in an equal superposition of states |0⟩ and |1⟩, with each state having an initial amplitude of 1/√2. This step ensures the qubit is ready to interact with phase changes.
  2. Step 2: Phase Rotation

    • The Z gate applies a phase shift to the qubit. The phase angle is randomly chosen, simulating the unpredictability of the turtle’s walking direction. This phase shift doesn’t affect the measurement probabilities directly but sets the stage for interference.
  3. Step 3: Interference via Hadamard Gate

    • The Hadamard gate translates the relative phase differences into measurable amplitude differences. Constructive interference (aligned phases) increases the probability of measuring |0⟩, while destructive interference (opposing phases) reduces it.

In a previous post, we explored how the Hadamard gate (H) creates a superposition by equally distributing the amplitude between |0⟩ and |1⟩, effectively preparing the qubit for subsequent operations. In this context Ry gives us more explicit control over the amplitude, we use the H gate differently: rather than initializing superposition, it now acts as a tool to translate phase differences—introduced earlier in the circuit—into measurable amplitude variations.

By combining amplitude rotation, phase manipulation, and interference, this circuit demonstrates how we can control a qubit’s behavior to perform specific computations.

Visualizing the Turtle’s Path
#

Let’s now visualize the impact of phase and amplitude within the quantum circuit using our trusty turtle. The GIF below shows how the turtle’s movement changes based on the interference patterns created by the quantum circuit.

The turtle’s movements in the visualization are guided by the quantum state’s amplitude and phase. The step length is proportional to the probability, which is determined by the amplitude. The rotation is dictated by the phase of the quantum state, mapped to a 360° angle, controlling the direction of movement. The color represents a combination of phase and probability, with the hue tied to the phase and the brightness reflecting the probability. This visualization beautifully captures the quantum interference patterns, transforming the abstract relationships of amplitude, phase, and probability into an intuitive and dynamic graphical display. One distinct feature of this movement is that when probability and therefore amplitude is low the turtle makes small and timid movements.

GIF of the Turtle

You can see the code for this example here.

The turtle’s path illustrates how phase shifts and amplitude rotations can combine to determine the direction and distance of its steps. For example, consider a specific quantum state measurement:

Amplitude |0⟩: 0.9708
Amplitude |1⟩: 0.2398
Phase |0⟩: 13.87°
Phase |1⟩: -76.13°
Measured State: |0⟩

This shows strong constructive interference for state |0⟩ with a high amplitude (0.9708), resulting in a measurement probability of approximately 94.2%. On the other hand, the amplitude for state |1⟩ is much lower (0.2398), leading to a measurement probability of only about 5.7%. The phase difference between states (approximately 90°) creates maximum interference, illustrating how phase and amplitude dictate the turtle’s movement and the resulting quantum behavior.

Conclusion
#

In this post, we introduced the concepts of phase and amplitude, exploring how they allow us to manipulate qubits for meaningful computations. Using a quantum circuit, we demonstrated how amplitude rotations, phase shifts, and interference work together to control quantum states. With the turtle as our guide, we saw how these abstract principles translate into intuitive, visual behaviors.

In the next post, we’ll build on these ideas as we dive into Grover’s algorithm, a powerful quantum search method. We’ll also explore how quantum computing can be applied to solve simple architectural design problems, demonstrating its potential for generative design. Stay tuned!