Skip to main content

Command Palette

Search for a command to run...

Quantum Power: Interference and Phase Flip

Updated
4 min read
Quantum Power: Interference and Phase Flip
T
TJ Gokken is an AI Systems Architect with a passion for bridging the gap between technology and practical application. Specializing in .NET frameworks and machine learning, TJ helps software teams operationalize AI to drive innovation and efficiency. With over two decades of experience in programming and technology integration, he is a trusted advisor and thought leader in the AI community.

Unlike stubborn classical bits that don’t know how to interfere with each other, qubits are like social butterflies; they mingle and mix up, cancelling or amplifying each other like waves at a rock concert.

Just like the classical world, we have gates in the world of quantum computing as well. Yet, you probably realized that the quantum gates have non-descriptive names, because, well, it is not that easy to describe what they do like the classical gates such as AND, OR, XOR, etc.

One of the simplest and yet intriguing of these gates is called Phase Flip, aka Z Gate. Z Gate is kind of like the mood swing for the qubits, one minute they are rocking, the next they are listening to romantic songs.

We have been working on our little project called QuantumDemo2, https://github.com/tjgokken/QuantumDemo2. So, let’s add the Z gate to it.

operation ApplyPhaseFlip() : Result {
    use qubit = Qubit();
    H(qubit);
    Z(qubit);
    H(qubit);
    return M(qubit);
}

Let’s go through this code line by line to see what is happening.

After we initialize our qubit, we apply Hadamard gate (H) to it and bam! it is in superposition.

Then we apply Z gate (Z) to our qubit. And our little qubit has changed its mood, flipped if you will.

Yes, great but what does this mean? How can a qubit have a mood swing?

Let’s go back to our coin analogy. Imagine you have a spinning coin. It's flipping between heads and tails as it spins, right? Now, let’s say that instead of looking at which side is up, you're only interested in whether it's spinning clockwise or counterclockwise.

Applying a phase flip to a qubit is a bit like telling that spinning coin to suddenly spin the opposite way without stopping it or flipping it over. It’s still a spinning coin, but now its spin direction is reversed. In terms of qubits, this "flip" doesn’t change the qubit from a 0 to a 1 or vice versa; instead, it changes how this qubit will interact with other qubits because it is spinning the other way.

I know this does not sound like much, but it allows us explore various scenarios simultaneously.

This unique capability of qubits to exist in multiple states at once (thanks to superposition) and then be manipulated with flips (like the phase flip using the Z gate) allows quantum computers to examine many possibilities all at once. When we measure the qubits, we can see the outcome of these combined possibilities, effectively allowing the quantum computer to consider multiple scenarios at the same time.

💡
For the movie buffs, the movie Next starring Nicholas Cage, kind of touches this concept, where his character can see into the future and explore different outcomes before deciding which outcome to take.

On the next line, we apply Hadamart gate again. Putting our superposition qubit into superposition again to remix things. Then we measure it.

This is what is going on behind the scenes:

When we initially apply the Hadamard gate (the first time), it puts the qubit into a state of superposition, where it's equally likely to be 0 or 1 — it's sort of like spreading the possibilities out. OK, this part we got. We have been doing this for a while now (at least past 2 articles) and we are comfortable with it.

After applying the Z gate, which flips the phase of the qubit, using another Hadamard gate recombines these probabilities in a different way. It’s like taking all those spread-out possibilities (which now include the phase flip) and mixing them back together to set up for how the qubit will eventually be observed (measured). This second superposition allows the qubit to interfere with itself, setting the stage for how it will finally collapse to a definite state (0 or 1) when measured.

So, yes, it's putting the qubit back into superposition, but this time with all the changes that the Z gate (phase flip) introduced. This is crucial for observing how those changes affect the final state of the qubit in quantum computations.

This exercise shows us that the qubits are more than just a supercharged bits. They are very different to classical bit and can behave in ways that can seem quite strange from a classical perspective. This is because qubits are made of superconducting circuits, trapped ions and photons. Yeah, that’s pretty different to physically implemented transistors with electrical voltages (low for 0, high for 1).

Let’s run our app and see what kind of result we get:

Phase flip result: One

Not too exciting, isn’t it?

However, we get this result by applying quantum computing to it. The interference pattern created by these gates resulted in a collapse to the 1 state when measured.

Once again, please remember that we are running these simulations on a classic computer. The real power and "earth-shattering" potential of quantum computing becomes apparent when these operations are performed on an actual quantum computer.

Once of these earth-shattering properties is true randomness. Quantum processes are fundamentally probabilistic. This means that the outcomes of operations (like measurements) are genuinely random, which is a valuable property for various cryptographic techniques.

💡
You can find the source code for QuantumDemo2 project here: https://github.com/tjgokken/QuantumDemo2