Skip to main content

Command Palette

Search for a command to run...

Quantum Power: Entanglement

Updated
6 min read
Quantum Power: Entanglement
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.

I wrote an article talking about Quantum Programming using Q# and C# - with C# mostly standing by and watching in awe (and probably trying to figure out what’s going on) while Q# worked its magic.

That was a simple example but it exposed us to the world of quantum programming.

Now that we can flip coins using quantum technology, I think we are ready for the next step.

Before we go on though, let’s remember that the biggest thing about qubits is that they can be 0 and 1 at the same time until we measure them. Classical bits can not do this as it is pretty much an inconceivable concept.

💡
Quantum programming takes it even further when it talks about qutrits, where you can have not 2 states all at once but 3. Kind of like 2D vs 3D if you will. Actually, it can go on to 4, 5, 6, n states. It is only limited by the stability and manageability of the hardware and the software. Mind blown yet? Let’s continue…

This article is going to be considerably different to the first one - a huge quantum-leap (pun intended) into the realm of multi-qubit operations, entanglement, and some algorithms that make our classical computers look like analog calculators.

What I mentioned above are not some fancy buzzwords, but the powerhouse concepts that give the quantum computers their edge.

If you are still with me, and I am hoping that you are, let’s have some quantum fun!

The Project: Quantum Demo 2

After all that hype, we will name our project Quantum Demo 2, only because the first one was called Quantum Demo 1. Yeah, I know.

Anyway, the first project was a combination of a console app in C# and some Q# code. For this second part, we will streamline our approach and focus entirely on Q#. We will eliminate the middle man (C#) and deal with the producer of magic directly.

So, first thing is first: Open Visual Studio Code Editor and make sure .NET Core SDK and Azure QDK are installed. After that open a new terminal window, switch to the folder you want to run this code in and run the following command:

dotnet new console -lang Q# --output .

This command sets up a new Q# application with a basic structure in the directory you are in.

Now, that is done, let’s add some code! First off, multi-qubit systems.

So, what are Multi-Qubit Systems?

In the last article, we played around with a single qubit, flipping it and putting it into superposition with a coin flip analogy where it was heads and tails at the same time.

While it was cool to see this concept in action, you see the real power of quantum computing when you start dealing with multiple qubits. This allows us to perform operations that are impossible with classical bits.

The first of these multiple qubit systems that we are going to look into is called entanglement.

Entanglement: Spooky Action at a Distance

Entanglement is what Einstein famously referred to as “spooky action at a distance” What it means is that when qubits become entangled, the state of one no matter how far it is, instantly affect its partner’s state.

Quantum entanglement is a quirky phenomenon where pairs or groups of particles interact in such a way that the quantum state of each particle cannot be described independently of the state of the others, even if they are separated by large distances. This comes from quantum mechanics.

Whoa, there are a lot of things to untangle here (see what I did there?).

How can qubits become entangled and grow closer or apart?

I told you this piece was going to be wild.

You see, qubits interact through quantum gates, which are the quantum equivalent of logical gates (AND, OR, XOR, etc.) in classical computing. These gates manipulate the states of qubits, creating entanglement. It is kind of like programming where specific instructions cause variable to become linked in certain ways that are dependent on each other.

In the quantum world, “closer” or “apart” does not necessarily mean physical distance. It can mean the degree of quantum connection or entanglement between qubits. “Closer” means they are more related, and vice versa.

Imagine you're programming two qubits to perform a calculation. You use a quantum gate to entangle them, which means you've linked their states in a way that a change to one affects the other, no matter where they are physically located within the computer. If these qubits are then separated—say, sent to different parts of a quantum network—they remain entangled, and their linked states can be used in computations that span the network.

So close no matter how far.

Untangling is called decoherence and it involves the loss of quantum properties (like superposition and entanglement) as the qubit interacts with its environment, which effectively makes them behave more like classical bits.

This wild concept is what makes quantum computers to perform calculations classic computers can’t. Think like one of them is thinking in 2D and the other in multi-dimensions.

Maybe some code will help us understand this better:

operation EntangleQubits() : (Result, Result) {
    use q1 = Qubit();
    use q2 = Qubit();
    H(q1); // Put q1 into superposition using Hadamard gate
    CNOT(q1, q2); // Entangle q1 with q2
    let result1 = M(q1);
    let result2 = M(q2);
    ResetAll([q1, q2]);
    return (result1, result2);
}

OK, we need to explain this code line by line:

  1. We initialize q1 and q2 as qubit

  2. H(q1); applies the Hadamard gate to qubit q1. The Hadamard gate puts q1 into a superposition, meaning it's now in a state where it has equal probabilities of being measured as 0 or 1.

  3. CNOT(q1, q2); performs a Controlled-NOT operation with q1 as the control qubit and q2 as the target. This gate entangles the two qubits, linking their states. The result is that if q1 is in state 1, q2 will flip to 1 (if it was 0), effectively syncing their states.

  4. let result1 = M(q1); and let result2 = M(q2); measure the states of q1 and q2, respectively. Because the qubits are entangled, the measurement of these qubits will be correlated. If one is measured as 1, the other will also be measured as 1.

  5. ResetAll([q1, q2]); is basically just cleaning up.

When we run our console app, we get a result like this

Entangled results: (One, One)

Both of these qubits return the value of 1, because as we have seen above (#4), they are related. Remember, we only put q1 into superposition. We did not do anything to q2, other than entangling it with q1.

So how does this help with the calculations that classical computers can’t?

Suppose you have 20 variables. Each can only hold 1 or 0.

If you have 20 qubits, then you can hold 220 states at once. Entanglement is what enhances the power of these superpositions. Then all of a sudden, you have a serious number of interactions. This is an enormous scale of calculations.

In practical terms, if you were using a quantum algorithm designed to solve a problem across 20 qubits:

  • Superposition allows you to set up a quantum state where every possible answer to the problem is represented simultaneously.

  • Entanglement ensures that when you measure the qubits, their states are correlated in a way that reflects a meaningful answer to the problem, rather than just random states.

Entanglement is still in its infancy and we are discovering best ways to use this technique. However, its potential applications, from cryptography to AI calculations is very exciting indeed.

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

Quantum Computing

Part 3 of 5

Exploring Microsoft's Q# and quantum computing concepts.

Up next

Flipping Qubits: C# in Quantum Computing

Q# Helped a Bit

Quantum Power: Entanglement