Superdense Coding, invented by Bennett & Wiesner in 1992, is a quantum communication protocol that uses a single quantum bit to transmit two-bit classical information, which cannot be achieved by classical information technology. Suppose we have two users, Alice and Bob, and they want to use Superdense Coding to transmit information between each other. First, they need to prepare an entangled Bell state
One can easily prepare a Bell state by applying this circuit on initial
Then he measured the whole system. Guess what he gets! He gets the
If Alice wants to send
Above is the main idea of superdense coding. Now let's implement this protocol using QCompute.
import sys
sys.path.append('../../..') # "from QCompute import *" requires this
from QCompute import *
matchSdkVersion('Python 3.3.3')
# Set the shot number for each quest
shots = 1024
# The message that Alice want to send to Bob.
# The user you can modify the massage to '00', '01' or '10' as you like
message = '11'
def main():
"""
main
"""
# Create environment
env = QEnv()
# Choose backend Baidu Local Quantum Simulator-Sim2
env.backend(BackendName.LocalBaiduSim2)
# Initialize the two-qubit circuit
q = env.Q.createList(2)
# Alice and Bob share a Bell state (|00>+|11>) / sqrt(2),
# where Alice holds q[0] and Bob holds q[1]
H(q[0])
CX(q[0], q[1])
# For different messages, Alice applies different gates on q[0],
# where she applies nothing to indicate the message '00'
if message == '01':
Z(q[0])
elif message == '10':
X(q[0])
elif message == '11':
# Here ZX = iY
Z(q[0])
X(q[0])
# Alice sends her qubit q[0] to Bob,
# and then Bob decodes the two qubits.
# Bob needs to measure the two qubits with Bell basis,
# or transforms the state to computational basis
# and measures it with the computational basis
CX(q[0], q[1])
H(q[0])
# Measure with the computational basis
MeasureZ(*env.Q.toListPair())
# Commit the quest
taskResult = env.commit(shots, fetchMeasure=True)
print(taskResult['counts'])
if __name__ == '__main__':
main()
Here is the measurement result:
{'11': 1024}
Note: You may change the message to '01', '10', or '00' as you wish.