QUANTUM COMPUTING ON MACOS WITH QDK
A series of Quantum Computing hands-on tutorial with Q#
If you haven’t read the other two articles of mine on Q#, I strongly suggest you have a look at them: Setup Q# and Superposition. Because they are related and provide the background to this article.
The definition of the entanglement is when two, or more, quantum particles cannot have their states described independently regardless of distance. In another word, the quantum particles are inextricably linked, when we make a measurement of one entangled qubit, our knowledge of the state of the other(s) is updated as well.
For example, there are two entangled quantum particles, A and B. A and B travel light-year in the opposite direction. When measuring particle A, even though B is far far away, the entanglement is still held. So if the A is one states, you know the B should have the same state regardless of the order and time of the measurements. Both particles somehow are able to let each other know what state they should be when they are measured.
I cannot seriously believe in it because the theory cannot be reconciled with the idea that physics should present a reality in time and space, free from spooky actions at a distance.
(Einstein to Max Born)
This was deeply troubled Einstein because nothing can travel faster than light and somehow these two particles can communicate faster than light. If you are interested, please read more on Bell’s Theorem.
- odd parity: two quantum particles have the opposite values
- Even parity: two quantum particles have the same values
Both odd and even parity are possible in entanglement.
The importance of entanglement comes from the fact that if we apply action on one QuBit, then it is the same as we apply the same action on all of the rest of QuBit that entangled with the one. Therefore, it speeds up in the “process” step, instead of the
for loop to touch on every QuBit, you can only apply on one and one only.
2. Using Artificial Intelligence to detect COVID-19
3. Real vs Fake Tweet Detection using a BERT Transformer Model in few lines of code
4. Machine Learning System Design
Is entanglement necessary for quantum computing? Please look at CHSH Game.
Line 6 — Line 20: Entanglement
- Line 6:
operationis the way to define a function in Q#, but we need to provide return type, which are
:(Result, Result). In this code, we will return two quantum states of the two entangled Qubits. Also
Resultis the data type of the basic state after superposition collapses.
- Line 7–8: create two
mutablevariables that capture the results.
- Line 9: the
usingblock that used to create QuBits. We need to create two,
(Q1, Q2) = (Qubit(), Qubit())
- Line 10:
H()the function that excites the QuBit to the superposition. Here we only excite ONE, since we can use entanglement operation to excite and entangle the other.
- Line 11:
CNOT()is short for “Control Not”, which is one way to entangle particles.
- Line 13–14: assigned the measurements (via
M()) to the variables, which are two states.
- Line 16–17: need to reset the QuBit to avoid compiler throw exceptions.
- Line 19: return two states.
Line 22 — Line 41: Quantum Simulation code
- Line 22: like Line 6, define operation called
QuantumSimulatorwith an argument
countwhich is the time we want to run the simulations.
- Line 23–24: see lines 7–8.
- Line 26-27: creates temperate variable to contain return values.
onesis the variable that contains the value of how many times the basic states collapse at 1.
equalis the variable that contains the value of how many times both of the QuBits are equal.
- Line 29–39:
forloop with conditions.
- Line 30: assigned basic states from the
Line 43— Line 51: Driver code similar to the
main() function in C++.
Please refer to Superposition, for the detailed walk-through. The purpose of this block of the code is to create entry point for the whole file and print out the results of our simulation. experiment.
The output of the Full Code
The output should be as following. Like the previous tutorial, we know that the collapsed state from the superposition should be 50–50 change between 1 and 0, so we have 517:483, which are correct. And since we are applied one of the entangle operations, the two QuBit should be equal, so we have 1000 out of 1000 equal pairs of quantum particles.
$ dotnet run
You have learned to entanglement operation on the two quantum particles and found out they are indeed entangled 100% of the time. You also understand the potential usage of the entanglement. Happy learning!