.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/basics/example_superdense_coding.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_basics_example_superdense_coding.py: Superdense Coding ================== .. GENERATED FROM PYTHON SOURCE LINES 6-32 In classical communication, sending two bits of information requires transmitting two physical bits. But with the help of quantum entanglement, we can bend this rule. **Superdense coding** proposed by Bennet and Wiesner in 1992 :footcite:`Bennett_1992_Communication` lets Alice send two classical bits to Bob by transmitting just *one qubit*. The catch here is that they must share an entangled pair of qubits beforehand. We will explain this protocol in detail below: Superdense coding protocol ^^^^^^^^^^^^^^^^^^^^^^^^^^ 1. Before any communication begins, a third party prepares two qubits in *Bell state*: .. math:: \begin{equation} \begin{aligned} \ket{\psi} = \frac{\ket{00} + \ket{11}}{\sqrt{2}} \end{aligned} \end{equation} Alice takes the first qubit, Bob takes the second, and they both separate. This entangled pair is responsible for linking the qubits *non-locally*, allowing Alice's local operations to affect the global state. .. GENERATED FROM PYTHON SOURCE LINES 32-41 .. code-block:: Python :lineno-start: 32 import numpy as np from toqito.states import bell from toqito.matrices import pauli, cnot, hadamard np.set_printoptions(precision=8, suppress=True) bell_state = bell(0) print(f"Initial Bell state (|Φ⁺⟩): \n {bell_state}") .. rst-class:: sphx-glr-script-out .. code-block:: none Initial Bell state (|Φ⁺⟩): [[0.70710678] [0. ] [0. ] [0.70710678]] .. GENERATED FROM PYTHON SOURCE LINES 42-85 2. Alice holds two classical bits (:math:`a` and :math:`b`) that she wants to send. For the tutorial, she is choosing to send :math:`11`. Depending on the values of her classical bits, she applies one of the four *Pauli Gates* to her qubit for encoding: .. raw:: html
.. list-table:: :header-rows: 1 :widths: 20 20 40 60 100 * - :math:`a` - :math:`b` - *message* - *Gate applied* - *Final output (Bell state)* * - :math:`0` - :math:`0` - :math:`\ket{00}` - :math:`I` - :math:`\frac{|00\rangle + |11\rangle}{\sqrt{2}}` * - :math:`0` - :math:`1` - :math:`\ket{01}` - :math:`X` - :math:`\frac{|10\rangle + |01\rangle}{\sqrt{2}}` * - :math:`1` - :math:`0` - :math:`\ket{10}` - :math:`Z` - :math:`\frac{|00\rangle - |11\rangle}{\sqrt{2}}` * - :math:`1` - :math:`1` - :math:`\ket{11}` - :math:`XZ = iY` - :math:`\frac{|10\rangle - |01\rangle}{\sqrt{2}}` .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 85-103 .. code-block:: Python :lineno-start: 85 pauli_gate_operations = { # Identity gate. "00": pauli("I"), # Pauli-X gate. "01": pauli("X"), # Pauli-Z gate. "10": pauli("Z"), # X followed by Z (equivalent to iY). "11": 1j * pauli("Y"), } message_to_encode = "11" # Alice sends her encoded entangled state after this step. entangled_state_encoded = np.kron(pauli_gate_operations[message_to_encode], pauli("I")) @ bell_state print(f"Entangled state is: {entangled_state_encoded}") .. rst-class:: sphx-glr-script-out .. code-block:: none Entangled state is: [[ 0. +0.j] [ 0.70710678+0.j] [-0.70710678+0.j] [ 0. +0.j]] .. GENERATED FROM PYTHON SOURCE LINES 104-110 3. Bob performs operations to reverse the entanglement on encoded state sent by Alice and extract the bits. First, he applies a Controlled-NOT or :math:`CX` *(CNOT) Gate* with the qubit received from Alice as the *control qubit* and Bob's original qubit as the *target qubit*. After this, Bob moves ahead and applies a Hadamard or :math:`H` gate to Alice's qubit. .. GENERATED FROM PYTHON SOURCE LINES 110-114 .. code-block:: Python :lineno-start: 110 state_after_cnot = cnot() @ entangled_state_encoded decoded_state = np.kron(hadamard(1), pauli("I")) @ state_after_cnot print(f"Decoded state:\n {decoded_state}") .. rst-class:: sphx-glr-script-out .. code-block:: none Decoded state: [[0.+0.j] [0.+0.j] [0.+0.j] [1.+0.j]] .. GENERATED FROM PYTHON SOURCE LINES 115-119 4. Finally, Bob measures both qubits in the computational basis (:math:`\ket{0}, \ket{1}`). The result is guaranteed to be :math:`11`; the two bits that Alice sent. .. GENERATED FROM PYTHON SOURCE LINES 119-122 .. code-block:: Python :lineno-start: 119 measurement_probabilities = np.abs(decoded_state.flatten()) ** 2 print(f"Measurement probabilities for basis states |00>, |01>, |10>, |11>: \n {measurement_probabilities}") .. rst-class:: sphx-glr-script-out .. code-block:: none Measurement probabilities for basis states |00>, |01>, |10>, |11>: [0. 0. 0. 1.] .. GENERATED FROM PYTHON SOURCE LINES 123-127 References ---------- .. footbibliography:: .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.645 seconds) .. _sphx_glr_download_auto_examples_basics_example_superdense_coding.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_superdense_coding.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_superdense_coding.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_superdense_coding.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_