quantumcomputingbook icon indicating copy to clipboard operation
quantumcomputingbook copied to clipboard

Non-ideomatic teleportation algorithm, no `c_if` not used

Open MattePalte opened this issue 1 year ago • 1 comments

Environment

  • qiskit.version: 0.45.2
  • Python version: 3.10.12
  • Operating system: Ubuntu 20.04

What is happening?

In the Python file teleportation.py the circuit first measures and then applies another gate with a simple if condition, I would have expected a c_if instruction to be used instead. It is also unclear why the operations to create the entangled pair and the creation of the arbitary state to teleport are both applied to qubit 0.

https://github.com/JackHidary/quantumcomputingbook/blob/02f613b7c456c957697effec40ab5ddd5afa91c4/chapter07/qiskit/teleportation.py#L39

What should happen?

I would have expected the entangled pair and the arbitary state to be created on different qubits and the use of c_if instead of the simple if condition.

Any suggestions?

I would have followed this guide and created something like:

from qiskit import *

qc = QuantumCircuit(3)
c0 = ClassicalRegister(1)
c1 = ClassicalRegister(1)
c2 = ClassicalRegister(1)
qc.add_register(c0)
qc.add_register(c1)
qc.add_register(c2)

qc.barrier()
# arbitrary state creation
qc.u(0.3,0.2,0.1,0)
# entangled pair creation
qc.h(1)
qc.cx(1,2)
qc.barrier()

qc.cx(0,1)
qc.barrier()
qc.h(0)
qc.barrier()
qc.measure([0,1],[0,1])
qc.barrier()
qc.x(2).c_if(c1, 1)
qc.z(2).c_if(c0, 1)
qc.draw()

Output:

        ░            ░       ░ ┌───┐ ░ ┌─┐    ░
  q_0: ─░────────────░───■───░─┤ H ├─░─┤M├────░───────────────
        ░ ┌───┐      ░ ┌─┴─┐ ░ └───┘ ░ └╥┘┌─┐ ░
  q_1: ─░─┤ H ├──■───░─┤ X ├─░───────░──╫─┤M├─░───────────────
        ░ └───┘┌─┴─┐ ░ └───┘ ░       ░  ║ └╥┘ ░  ┌───┐  ┌───┐
  q_2: ─░──────┤ X ├─░───────░───────░──╫──╫──░──┤ X ├──┤ Z ├─
        ░      └───┘ ░       ░       ░  ║  ║  ░  └─╥─┘  └─╥─┘
                                        ║  ║       ║   ┌──╨──┐
c15: 1/═════════════════════════════════╩══╬═══════╬═══╡ 0x1 ╞
                                        0  ║    ┌──╨──┐└─────┘
c16: 1/════════════════════════════════════╩════╡ 0x1 ╞═══════
                                           0    └─────┘
c17: 1/═══════════════════════════════════════════════════════

Thanks in advance, I wish you a happy and productive day.

MattePalte avatar Feb 28 '24 10:02 MattePalte

This would affect also the korean version: https://github.com/JackHidary/quantumcomputingbook/blob/02f613b7c456c957697effec40ab5ddd5afa91c4/korean/chapter07/qiskit/teleportation.py#L39

MattePalte avatar Feb 28 '24 10:02 MattePalte