<jupyter_start><jupyter_text>Superdense Coding<jupyter_code>import qiskit as q
import numpy as np
import matplotlib as mpl
# preparation of the random message of be communicated
classical_bits = ['00', '01', '10', '11']

message = np.random.choice(classical_bits)

print(message)
# Preparation of iY gate to be used. Note that iY gate is simply X-Z gate. 
# But it's a good exercise to learn how any unitary matrix is converted to a quantum gate.
Y = np.array([
    [0, -1j],
    [1j, 0]
])

iY = 1j * Y

iY_op = q.quantum_info.Operator(iY)
print(iY_op)
qc = q.QuantumCircuit(2, 2)

# Preparation of entangled qubits to be shared by Alice and Bob
qc.h(0)
qc.cx(0, 1)
qc.barrier()

# Alice performs operations depending upon the message to be communicated
if message == '01':
    qc.z(0)
    qc.barrier()
    
elif message == '10':
    qc.x(0)
    qc.barrier()
    
elif message == '11':
    qc.unitary(iY_op, [0], label='iY')
    qc.barrier()
    
qc.draw(output='mpl')
# Alice send her qubit to Bob
# Bob performs operations on the entangled pair
qc.cx(0, 1)
qc.h(0)
qc.barrier()

# Bob measures the qubits to get the message
qc.measure([0, 1], [0, 1])
qc.draw(output='mpl')
# execute the circuit on a qasm simulator
backend = q.Aer.get_backend('qasm_simulator')
job = q.execute(qc, backend)
result = job.result()
counts = result.get_counts()

graph = q.visualization.plot_histogram(counts)
display(graph)

# The probability of getting the message = 1<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1241565452091768, 'fraction_numerical': 0.023616734143049933, 'mean_word_length': 4.078767123287672, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '450322', 'license': 'MIT', 'n_tokens_mistral': 585, 'n_tokens_neox': 529, 'n_words': 175, 'path': 'Superdense Coding.ipynb', 'repo_name': 'calm-cookie/superdense-coding', 'size': '1482'}