연습 - Q#를 사용하여 양자 얽힘을 이용한 텔레포테이션
이전 단원에서는 양자 텔레포트 프로토콜의 단계를 알아보았습니다. 이제 Alice와 Bob이 양자 텔레포트 실험을 구현하는 데 도움을 줄 차례입니다!
이 단원에서는 양자 텔레포트 프로토콜을 사용하여 Alice에서 Q# Bob으로 메시지 큐비트의 상태를 보내는 프로그램을 만듭니다. 이 프로그램에는 텔레포트를 수행하기 위해 함께 작동하는 네 가지 작업이 포함되어 있습니다.
Q#에서 양자 텔레포테이션 프로그램을 만듭니다.
텔레포테이션 프로그램을 시작하려면 다음 단계를 수행하십시오.
- VS Code(Visual Studio Code)를 엽니다.
- 파일 메뉴를 열고 새 텍스트 파일을 선택하여 새 파일을 만듭니다.
- 파일을 Main.qs로 저장합니다.
필요한 라이브러리를 가져옵니다.
프로그램을 작성하는 데 필요한 작업 및 함수가 포함된 Q# 라이브러리를 가져오려면 Main.qs 파일에 다음 코드를 복사합니다.
import Microsoft.Quantum.Diagnostics.*; // Aka Std.Diagnostics.*;
import Microsoft.Quantum.Intrinsic.*; // Aka Std.Intrinsic.*;
import Microsoft.Quantum.Measurement.*; // Aka Std.Measurement.*;
Teleport 작업 정의
양자 텔레포트 프로토콜을 구현하는 작업으로 Teleport를 생성합니다. 이 연산은 두 개의 큐비트를 입력으로 받습니다. message 큐비트에는 텔레포트된 상태가 포함되어 있으며, bob 큐비트는 텔레포트된 상태를 수신합니다.
operation Teleport(message : Qubit, bob : Qubit) : Unit {
// Allocate an alice qubit.
use alice = Qubit();
// Create some entanglement that we can use to send our message
H(alice);
CNOT(alice, bob);
// Encode the message into the entangled pair
CNOT(message, alice);
// Transform the Bell states into computational states for measurement
H(message);
// Measure the qubits to extract the classical data we need to decode
// the message by applying the corrections on the bob qubit
// accordingly.
if M(message) == One {
Z(bob);
}
if M(alice) == One {
X(bob);
}
// Reset alice qubit before releasing
Reset(alice);
}
우리의 Teleport 운영 단계들을 세분화해 보겠습니다.
큐비트를
alice만듭니다. 이제 양자 텔레포트를 수행하는 데 필요한 세 개의 큐비트가 있습니다.alicebobmessagealice와bob큐비트를 얽습니다. 우리는 일반적인 방법으로 이 작업을 수행합니다: Hadamard 게이트를 적용하여alice큐비트를 중첩 상태로 만듭니다.큐비트를
alice및bob얽힌 두 큐비트 쌍으로 인코딩합니다. 이를 위해message을(를) 컨트롤 큐비트로 하고alice을(를) target 큐비트로 하여 CNOT 게이트를 적용합니다.alice및message큐비트 상태는 이제 벨 기저에 있습니다.Bell 상태를 계산 상태로 변환합니다. 우리는 Q#에서는 벨 상태에서 직접 측정을 할 수 없기 때문에 이렇게 합니다. 큐비트에 Hadamard 게이트를
message적용하여 상태를 계산 기준으로 변환합니다. 다음 표에서는 Bell 상태를 해당 계산 상태와 관련합니다.벨 상태 계산 기반 상태 $\ket{\phi^+}$ $\ket{00}$ $\ket{\phi^-}$ $\ket{01}$ $\ket{\psi^+}$ $\ket{10}$ $\ket{\psi^-}$ $\ket{11}$ alice및message큐비트를 측정하고, 측정 결과에 따라bob큐비트에 적절한 게이트를 적용합니다. 우선M연산을 사용하여message를 측정합니다. 결과가 1이면 $Z$ 게이트를bob에 적용합니다. 다음으로M작업으로alice을/를 측정합니다. 결과가 1이면 $X$ 게이트를bob에 적용합니다.
이 프로토콜은 큐비트의 초기 상태를 message 큐비트로 텔레포트합니다 bob .
SetToPlus 및 SetToMinus 연산 정의
실제 원격 보고 프로토콜에서 메시지 큐비트는 중첩 상태에 있을 수 있습니다. Alice도 Bob도 메시지 큐비트의 상태를 알지 못합니다. 상태는 알 수 없는 경우에도 메시지 큐비트에서 Bob의 큐비트로 텔레포트됩니다. 그러나 여기서 Q#는 텔레포트 프로토콜보다 먼저 메시지 큐비트의 상태를 설정해야 합니다.
|0⟩, |1⟩, |+⟩, |−⟩와 같은 다양한 초기 상태에서 메시지 큐비트를 사용하여 텔레포테이션 프로토콜을 테스트하기 위해 SetToPlus 및 SetToMinus 연산을 만듭니다. 이러한 작업은 메시지 큐비트를 원격으로 전송하기 전에 원하는 초기 상태로 설정합니다.
SetToPlus 및 SetToMinus 작업에 대한 다음 코드를 Main.qs 파일에 복사합니다.
/// Sets a qubit in state |0⟩ to |+⟩.
operation SetToPlus(q : Qubit) : Unit is Adj + Ctl {
H(q);
}
/// Sets a qubit in state |0⟩ to |−⟩.
operation SetToMinus(q : Qubit) : Unit is Adj + Ctl {
X(q);
H(q);
}
Main 작업 정의
모든 Q# 프로그램에는 진입점 작업이 있어야 하며, 기본적으로 Main 작업이 됩니다. 여기서는 Main 작업이 메시지 큐비트의 다양한 초기 상태인 $\ket{{0}$, $\ket{1}$, $\ket{+}$, $\ket{-}$에 대해 텔레포테이션 프로토콜을 실행합니다. 프로토콜이 성공하면 Bob의 큐비트는 처음에 메시지 큐비트를 설정한 것과 동일한 상태로 끝납니다.
Main 양자 텔레포트 프로그램에 대한 작업은 다음과 같습니다.
operation Main() : Result[] {
// Allocate the message and bob qubits
use (message, bob) = (Qubit(), Qubit());
// Use the `Teleport` operation to send different quantum states
let stateInitializerBasisTuples = [
("|0〉", I, PauliZ),
("|1〉", X, PauliZ),
("|+〉", SetToPlus, PauliX),
("|-〉", SetToMinus, PauliX)
];
mutable results = [];
for (state, initializer, basis) in stateInitializerBasisTuples {
// Initialize the message and show its state using the `DumpMachine`
// function.
initializer(message);
Message($"Teleporting state {state}");
DumpMachine();
// Teleport the message and show the quantum state after
// teleportation.
Teleport(message, bob);
Message($"Received state {state}");
DumpMachine();
// Measure bob in the corresponding basis and reset the qubits to
// continue teleporting more messages.
let result = Measure([basis], [bob]);
set results += [result];
ResetAll([message, bob]);
}
return results;
}
작업의 구성 요소를 세분화해 보겠습니다.Main
- 두 개의 큐비트를 할당합니다
message.bob - 양자 상태, 큐비트를 원하는 상태로 초기화하는
message작업 및 측정의 기초가 포함된 튜플 목록을 만듭니다. 초기화 작업은 $\ket{0}$에 대한I, $\ket{1}$에 대한X, $\ket{ + }$에 대한SetToPlus, 그리고 $\ket{-}$에 대한SetToMinus입니다. - 튜플 목록을 반복하여 큐비트를 초기화
message하고 초기 상태를 표시합니다. 그런 다음,message작업을 호출하여Teleport큐비트의 상태를bob큐비트로 텔레포트합니다. -
bob해당 기준으로 큐비트를 측정하고 큐비트를 다시 설정하여 원격 전송에 다시 사용할 수 있습니다. - 각 텔레포트에 대한 측정 결과를 반환합니다.
프로토콜이 올바르게 작동하면 측정 결과가 bob 초기화된 상태와 일치합니다 message.
프로그램 실행
양자 텔레포테이션 프로그램이 준비되었습니다. 프로그램을 실행하여 메시지 큐비트의 여러 초기 상태에서 양자 텔레포트가 작동하는 방식을 확인합니다.
전체 프로그램에는 Teleport 작업, SetToPlus 작업, SetToMinus 작업, 및 Main 작업이 포함됩니다. 코드를 실행하고 결과를 분석하려면 다음 단계를 수행합니다.
Main.qs 파일의 내용을 다음 Q# 코드로 바꿉니다.
/// This Q# program implements quantum teleportation import Microsoft.Quantum.Diagnostics.*; import Microsoft.Quantum.Intrinsic.*; import Microsoft.Quantum.Measurement.*; operation Main() : Result[] { // Allocate the message and bob qubits. use (message, bob) = (Qubit(), Qubit()); // Use the `Teleport` operation to send different quantum states let stateInitializerBasisTuples = [ ("|0〉", I, PauliZ), ("|1〉", X, PauliZ), ("|+〉", SetToPlus, PauliX), ("|-〉", SetToMinus, PauliX) ]; mutable results = []; for (state, initializer, basis) in stateInitializerBasisTuples { // Initialize the message and show its state using the `DumpMachine` // function initializer(message); Message($"Teleporting state {state}"); DumpMachine(); // Teleport the message and show the quantum state after // teleportation Teleport(message, bob); Message($"Received state {state}"); DumpMachine(); // Measure bob in the corresponding basis and reset the qubits to // continue teleporting more messages let result = Measure([basis], [bob]); set results += [result]; ResetAll([message, bob]); } return results; } /// # Summary /// Sends the state of a message qubit to a bob qubit by teleportation /// /// Notice that after calling Teleport, the state of `message` is collapsed /// /// # Input /// ## message: A qubit whose state we wish to send /// ## bob: A qubit initially in the |0〉 state that we want to send /// the state of message to operation Teleport(message : Qubit, bob : Qubit) : Unit { // Allocate an alice qubit. use alice = Qubit(); // Create some entanglement that we can use to send our message H(alice); CNOT(alice, bob); // Encode the message into the entangled pair CNOT(message, alice); H(message); // Measure the qubits to extract the classical data we need to decode // the message by applying the corrections on the bob qubit // accordingly if M(message) == One { Z(bob); } if M(alice) == One { X(bob); } // Reset alice qubit before releasing. Reset(alice); } /// # Summary /// Sets a qubit in state |0⟩ to |+⟩ operation SetToPlus(q : Qubit) : Unit is Adj + Ctl { H(q); } /// # Summary /// Sets a qubit in state |0⟩ to |−⟩ operation SetToMinus(q : Qubit) : Unit is Adj + Ctl { X(q); H(q); }기본 제공 시뮬레이터에서 프로그램을 실행하려면 작업 위의 실행 코드 렌즈를 선택하세요. 또는 Ctrl+F5를 누릅니다. 출력이 디버그 콘솔에 표시됩니다.
수신된 상태가 텔레포트된 상태와 일치하는지 확인합니다. 예를 들면 다음과 같습니다.
Teleporting state |0〉 Basis | Amplitude | Probability | Phase ----------------------------------------------- |00⟩ | 1.0000+0.0000𝑖 | 100.0000% | 0.0000 Received state |0〉 Basis | Amplitude | Probability | Phase ----------------------------------------------- |00⟩ | 1.0000+0.0000𝑖 | 100.0000% | 0.0000
축하합니다! 양자 텔레포트 프로토콜을 통해 Alice의 큐비트 상태를 Bob의 큐비트로 성공적으로 원격 전송했습니다. 모든 것이 양자 얽힘 덕분입니다!