⬆️ ⬇️

Quantum teleportation in Q #

I will say right away: as much as I would like to, quantum teleportation will not allow my grandmother to be moved from the village to my apartment. Granny knows that I like all sorts of quantum things, and decided instead of money and socks to send me a quantum state for my birthday. Here we will talk about something else - the transfer of quantum information.



This is the second article in the series on quantum programming. It is assumed that the reader is already familiar with the first part .





')

Articles from the cycle:



  1. Quantum computing and Q # language for beginners
  2. Introduction to quantum computing
  3. Quantum circuits and valves - introductory course
  4. Fundamentals of quantum computing: pure and mixed states
  5. Quantum teleportation in Q #
  6. Quantum Computing: Reference Materials


Unfortunately, it is not possible to send a qubit by e-mail or by sending. They are transmitted through special quantum channels, and in the village and the Internet appeared quite recently.



But maybe grandma will be able to transmit quantum information over a classical communication channel (for example, via the Internet or a telephone line)? The problem is that the range of possible values ​​of a quantum state is continuous, so for its accurate description an infinite number of classical bits are required. My grandmother is a very busy person, and she doesn't have time to type so many bits.



She has already begun to lose all hope, and then I say: "Grandma, everything is in order." Remember, we made Bell's fortune over tea last Wednesday? You can transfer a quantum state through it! Such a transmission of a quantum state using classical communication channels is called quantum teleportation. We will try to figure out how it works - in theory and in the code.



We send grandma quantum mail



Stage 0, preparatory



In order for everything described below to work, my grandmother and I must prepare Bell's state: to translate her qubit | G⟩ and my qubit | F⟩ into a state of confusion. I am parting with my grandmother, but I take my qubit (half the state of Bell) with me. Our qubits will be in a state of entanglement, regardless of how far they are separated - several kilometers or several billion light years.



Remember, we discussed the remarkable property of entangled states - the connectedness of the measurement results of the corresponding qubits? If the grandmother measures the state of her qubit, it will affect my qubit (regardless of the distance). Below we will actively use this property.



Stage 1. Confusing Grandma's Qubit with | ψ⟩







The initial state will be described using the above diagram. In the upper left corner is the subject of all our efforts - the qubit that my grandmother wants me to send. It is in an unknown state, which can be represented as follows:







In addition, it has at its disposal a qubit | G⟩, which, as we have just discussed, is confused with my qubit, | F⟩ (this connection is shown by a wavy line). Now two qubits are in the Bell state, which is described by the formula







First we confuse grandma's qubit | G⟩ with the state | ψ⟩. Soon you will understand why. In the previous article, we learned that two qubits can be confused using a circuit consisting of a CNOT gate and a Hadamard gate. Let's see how this process is represented using a quantum circuit.



[In order to better understand these notations in the quantum circuit diagrams, I recommend briefly reading the article Quantum circuits and gates — an introductory course .]



CNOT valve application







If you add the gate CNOT, the scheme takes the following form. The state that goes to the CNOT input can be written as | ψ⟩ | G⟩, where the first input corresponds to the upper wire, the second to the middle one. If we substitute the definitions of | ψ⟩ and | G⟩, we get:







Open brackets:







Thus, the input is served . Each of these terms passes through the CNOT valve. In the first article, we saw how the CNOT valve acts and how it handles two qubits. The most attentive readers have already noticed that all our components - | 000〉, | 011〉, | 100 and | 111〉 - consist of three qubits. In this case, the first is used as the controlling qubit, and the second is managed (see below).







When the control qubit is | 1, the value of the controlled qubit changes to the opposite. Thus, CNOT turns the set of qubits | 100〉 into | 110〉, and | 111〉 into | 101〉. All other states remain the same.







This means that the state of the three qubits after the CNOT gate will be described by the following expression: .



Hadamard valve application



The second stage of entanglement of a qubit | G⟩ with a state | ψ⟩ is the application of the Hadamard gate to the first qubit. Here is what it looks like on a quantum circuit diagram:







Let me remind you that the Hadamard valve converts | 0 1 and | 1 into states







After the CNOT gate, the qubits were able to . Apply the Hadamard valve to the first qubit of each term. The result looks rather sloppy:







So we got







Remove excess



Let's tackle our formula a little. As you can see, in the first term There are two fractions with a denominator of √2. Multiply them:







If we apply a similar operation to other terms, we get , and . As you can see, each fraction has a factor of 1/2. If we take it out of the brackets, we get:







Looks better already. Now open the brackets (this will simplify our work in the next step). As an example, I will give the calculations for the addendum. .







The rest "the reader is invited to do as an exercise." To be honest, I usually ignore such attractive offers. Here's what the remaining terms look like if you open the brackets:







Their sum is equal to







Stage 2. Measurement



So, we confused grandma's qubit | G⟩ with a qubit | ψ⟩. Now we measure them. But before that, the results should be brought to a more convenient form for understanding.



Again, clean up the results



This is the last time, honestly. Here are all the possible results of measuring the first and second qubit: 00, 01, 10, 11. For the time being, we do not know what our third qubit will be in each of these cases. We group the terms in such a way as to understand what state the third qubit will be in, namely, my qubit | F.



While our result looks like this:







Select the first and second qubit of each term:







Consider the cases in which the first and second qubit are | 00. They correspond to the terms . They can be converted as follows:







The same can be done for the cases | 01〉, | 10 and | 11.







After conversion, the expression takes the following form:







Fine.



Measurement



This is our chain with added measurement symbols. Note the double lines after the measurement symbols. They correspond to the transfer of classical bits, which are the results of measurements.







My grandmother also measures her two qubits, | G⟩ and | ψ⟩. As we have said, there are only four possible measurement results: 00, 01, 10, or 11. When measuring a qubit, the superposition of its states collapses. Suppose we measured the state of the first qubit | ψ⟩ and got 0. The superposition collapses and we have only those terms that are consistent with this measurement result (0), that is, the following:







Suppose now that we have measured the state of the second qubit, | G⟩, and obtained 0. The superposition collapses. The only term that remains is consistent with both measurement results (0 and 0), that is, the following:







Now we know the state of the third qubit (that is, my qubit | F⟩): able .



What if we got 01 as a result of the measurement? Let's return to our given result:







Reasoning by analogy, we will understand that the only term that corresponds to the result of measurement 01 - , which means that my qubit should be able to . If, after measurements, the grandmother received a result of 10, then I know that the third qubit is able and if she got 11, then the third qubit is .



This result can be presented as a table:







Stage 3. Transferring my qubit (F) to the state | ψ⟩



We stopped at the fact that grandmother measured the state of her two qubits, called me and told me about the result, so I know the state of my qubit. Remember that the unknown state that we started with, | ψ⟩, was equal to . We need to apply certain operations to my qubit in order to bring it to this state - to the state that my grandmother wanted to send to me (otherwise I will get something completely different).



Now it will be easy to do. Take a look at the table above. If the measurement result is 00, and my qubit is in the state , then it is not necessary to perform any operations on it - it is already in the state |. This is the easiest case.



If the measurement result is 01, then my qubit is in the state . If we compare it with the state | ψ⟩, it becomes clear that we need to swap the coefficients at | 0〉 and | 1. To do this, just skip my qubit through the NOT gate, that is, the X gate, and get the desired result .



With a measurement result of 10, my qubit is in a state . Compare it with | ψ⟩. We have and need . To make the desired valid, apply the valve Z, which changes the sign.



And the last option is 11. In this case, my qubit is in the state . Here we need to swap the coefficients at | 0〉 and 1, as well as the sign at . Thus, my qubit needs to be passed through gate X, and then through Z. Then we will get the desired result, . We enter these operations in the table.







Please note: if the first bit of the measurement result is 1, then we use the Z gate, and if the second bit is 1, then we use the X gate. The final version of the circuit is shown below. We added valve Z, using the top wire as a control, and valve X, for which the second wire will be the control. Managed in this case will be my qubit (because it is he who needs to be processed with the help of gates).







So, we have shown that it is enough for the grandmother to transfer only two classical bits (namely, the results of measuring the qubit states | G⟩ and | ψ⟩) so that we can recognize the unknown state of the qubit. Due to the phenomenon of quantum entanglement, information from the grandmother helps to know the values ​​of the coefficients α and β. At the same time, we managed to do without the quantum communication channel. Therefore, this method is called quantum teleportation.



Prepare and run the code



So, we have a little understanding of the theory of quantum teleportation. It's time to go to the code!

If you need help at any step, ready-made code is available here (just clone or download the repository, open the QuantumTeleportation.sln file in Visual Studio and go to step 5).



Stage 1. Create a project



Create a new project like “Application Q #” in Visual Studio and assign it some simple and clear name - for example, QuantumTeleportation.



Step 2. Download a copy of the code



Download a copy of the code with examples of quantum computing on your computer. To do this, clone or download the repository .



Step 3. Modify the Operation.qs file



Now you need to replace all the code in the Operation.qs file with the code from the TeleportationSample.qs file, which is in the Quantum> Samples> Teleportation section here .



Step 4. Modify the Driver.cs File



Replace all the code in the Driver.cs file with the contents of the Program.cs file.



Step 5. Save and run the project.



Click on the "start" button to run the code. Results for iterations 0–8 will be displayed. They should look something like this:







Understanding how this code works



In fact, you can figure it out without my help - the code is remarkably commented. We simply compare it with the theory discussed above - it will be easy.



Stage 1. Teleportation



In the first part of the article, we talked about three qubits: a qubit in an unknown state | ψ⟩ and two qubits in the state of Bell (one for my grandmother, one for me). These Telebons in the Teleport operation correspond to the msg qubits (an unknown state that my grandmother sends me), here (my grandmother’s qubit) and there (my qubit F, where | ψ⟩ is the forwarded state).



As already discussed, my grandmother and I prepared in advance a couple of qubits in the state of Bella. One of them is with my grandmother, the second - with me. Therefore, at the very beginning we need to confuse her qubit, which is called here , with mine, there . The code uses the Hadamard valve and the CNOT valve for this:







We use our circuit diagram. I will add symbols to it as they appear in the code.







By repeating the operations described at the beginning of the article, we confuse the grandma's qubit here with the unknown quantum state msg . The CNOT valve and Hadamard valve on the diagram correspond to the following lines of code:







Then we measured the first and second qubits, msg and here. The results of these measurements, the grandmother told me by phone. These events correspond to the conditions of the if statement:







As we discussed at the end of the first part of this publication, after receiving the measurement results, it is necessary to change the state of my qubit so that it corresponds to the qubit | ψ⟩, that is, msg . As we said, if the measurement result of the first qubit is 1, then my qubit ( there ) needs to be passed through the Z gate. This operation is shown above. If the measurement result of the second qubit is 1, then my qubit must be passed through the gate X.



Done! Now my qubit is exactly in the state that my grandmother wanted to give me.



Stage 2. TeleportClassicalMessage



Let's think about how you can send a message using the Teleport operation just discussed. Grandma was already quite comfortable with quantum teleportation, and now she sends me, not an unknown quantum state, but a known one — a message with a length of one bit. Suppose I asked my grandmother if she turned on the kettle. The answer will be one of two possible messages - yes or no.



First we allocate the register into two qubits, a boolean message that we will send ( msg ), and my qubit, ( there ), with which grandma will transmit the message. Remember that the numbering of register elements starts with 0 (just like in arrays). The result looks like this:







The msg qubit that we have selected is initially in the state | 0 (this is the default state for all allocated qubits). The message of the grandmother about whether the kettle is on can be one of two values ​​- yes or no. If the answer is no, then nothing else needs to be done - this message corresponds to the state | 0, in which the msg qubit is initially. If the answer is yes, that is | 1, then we need to skip the qubit msg through the quantum gate NOT to transfer it to the state shown below.







Next, Grandma sends the state to me using Teleport.







Then we measure the state of my qubit, there.







As a result, I get a 1 bit message and see if I can count on hot tea. So dozens of years of research in the fields of quantum mechanics and computing have found very important applications.



If you run the code, the results of the transmission of various Boolean states, which are contained in the Driver.cs file, will be displayed .







On it we will finish.







Resources



Source: https://habr.com/ru/post/351632/



All Articles