Superdense Coding quantum kata is a series of exercises designed to get you familiar with programming in Q#.
It covers the superdense coding protocol which allows us to transmit two bits of classical information by sending just one qubit using previously shared quantum entanglement.
Each task is wrapped in one operation preceded by the description of the task. Your goal is to fill in the blank (marked with // ...
comment) with some Q# code that solves the task. To verify your answer, run the cell using Ctrl+Enter (⌘+Enter on macOS).
Each task defines an operation that can be used in subsequent tasks to simplify implementations and build on existing code. We split the superdense coding protocol into several steps, following the description in the Wikipedia article:
Input: Two qubits, each in the $|0\rangle$ state.
Goal: Prepare a Bell state $|\Phi^{+}\rangle = \frac{1}{\sqrt{2}} (|00\rangle + |11\rangle)$ on these qubits.
%kata T1_CreateEntangledPair
operation CreateEntangledPair (q1 : Qubit, q2 : Qubit) : Unit is Adj {
// ...
}
Encode the message (two classical bits) in the state of Alice's qubit.
Inputs:
Goal: Transform the input qubit to encode the two classical bits.
ProtocolMessage
is a custom type that represents the message to be transmitted. It includes two items of typeBool
calledBit1
andBit2
.
%kata T2_EncodeMessageInQubit
open Quantum.Kata.SuperdenseCoding;
operation EncodeMessageInQubit (qAlice : Qubit, message : ProtocolMessage) : Unit {
if message::Bit1 { // accesses the item 'Bit1' of 'message'
// ...
}
// ...
}
Decode the message using the qubit received from Alice and reset both qubits to a $|00\rangle$ state.
Inputs:
Goal : Retrieve two bits of classic data from the qubits and return them as ProtocolMessage
. The state of the qubits in the end of the operation should be $|00\rangle$.
You can create an instance of
ProtocolMessage
asProtocolMessage(bit1value, bit2value)
.
%kata T3_DecodeMessageFromQubits
open Quantum.Kata.SuperdenseCoding;
operation DecodeMessageFromQubits (qAlice : Qubit, qBob : Qubit) : ProtocolMessage {
// ...
}
Put together the steps performed in tasks 1-3 to implement the full superdense coding protocol.
Input: Two classical bits to be transmitted.
Goal: Prepare an EPR Pair, encode the two classical bits in the state of the pair by applying quantum gates to one member of the pair, and decode the two classical bits from the state of the pair. Return the result of decoding.
%kata T4_SuperdenseCodingProtocol
open Quantum.Kata.SuperdenseCoding;
operation SuperdenseCodingProtocol (message : ProtocolMessage) : ProtocolMessage {
// ...
}