teleportation実装の補足

以下のpageに掲載されてあるteleportationの実装に関する少し補足です。

https://learning.quantum.ibm.com/course/basics-of-quantum-information/entanglement-in-action

# 当teleportationの実装
transmit one qubit using two classical bits

# Simple Version(qubit-Qの値: 0)
- Code
<details><summary>Codeを見る(変数名少し修正した)</summary>

```python
qubit = QuantumRegister(1, "Q")
ebit0 = QuantumRegister(1, "A")
ebit1 = QuantumRegister(1, "B")
m_A = ClassicalRegister(1, "m_A")
m_Q = ClassicalRegister(1, "m_Q")

protocol = QuantumCircuit(qubit, ebit0, ebit1,  m_Q, m_A)

# protocol.x(qubit)
# Prepare ebit used for teleportation
protocol.h(ebit0)
protocol.cx(ebit0, ebit1)
protocol.barrier()

# Alice's operations
protocol.cx(qubit, ebit0)
protocol.h(qubit)
protocol.barrier()

# Alice measures and sends classical bits to Bob
protocol.measure(ebit0, m_A)
protocol.measure(qubit, m_Q)
protocol.barrier()

# Bob uses the classical bits to conditionally apply gates
with protocol.if_test((m_A, 1)):
    protocol.x(ebit1)
with protocol.if_test((m_Q, 1)):
    protocol.z(ebit1)


m_B = ClassicalRegister(1, "m_B")
protocol.add_register(m_B)
protocol.measure(ebit1, m_B)

display(protocol.draw("mpl"))

result = AerSimulator().run(protocol).result()
statistics = result.get_counts()
display(plot_histogram(statistics, title="Fig-1: Transportation for qubit-Q(value: 0)", legend =['measure result(B A Q)']))

```

</details>

- Circuit
 ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3470230/0c119cc7-133f-ed02-2711-19ea01d1c423.png)

- Result
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3470230/83191cb3-b2fa-49cb-1afa-a0ea4e03d97e.png)

- analysis
  - qubit-Qの初期値が**0**
  - 上記のResult図から、qubit-Bの計測結果が**0**であることを分かった

  
要は、qubit-Qがqubit-Bに"伝送"できたという意味

# Simple Version(qubit-Qの値: 1)
- Code(All)
<details><summary>Codeを見る</summary>

```python
qubit = QuantumRegister(1, "Q")
ebit0 = QuantumRegister(1, "A")
ebit1 = QuantumRegister(1, "B")
m_A = ClassicalRegister(1, "m_A")
m_Q = ClassicalRegister(1, "m_Q")

protocol = QuantumCircuit(qubit, ebit0, ebit1,  m_Q, m_A)
# set qubit-q: 1
protocol.x(qubit)
# Prepare ebit used for teleportation
protocol.h(ebit0)
protocol.cx(ebit0, ebit1)
protocol.barrier()

# Alice's operations
protocol.cx(qubit, ebit0)
protocol.h(qubit)
protocol.barrier()

# Alice measures and sends classical bits to Bob
protocol.measure(ebit0, m_A)
protocol.measure(qubit, m_Q)
protocol.barrier()

# Bob uses the classical bits to conditionally apply gates
with protocol.if_test((m_A, 1)):
    protocol.x(ebit1)
with protocol.if_test((m_Q, 1)):
    protocol.z(ebit1)


m_B = ClassicalRegister(1, "m_B")
protocol.add_register(m_B)
protocol.measure(ebit1, m_B)

display(protocol.draw("mpl"))

result = AerSimulator().run(protocol).result()
statistics = result.get_counts()
display(plot_histogram(statistics, title="Fig-2: Transportation for qubit-Q(value: 1)", legend =['measure result(B A Q)']))

```


</details>

- Code(diff)
```diff_python
protocol = QuantumCircuit(qubit, ebit0, ebit1,  m_Q, m_A)
+ # set qubit-q: 1
+ protocol.x(qubit)
# Prepare ebit used for teleportation
```

- Circuit
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3470230/6cf6196c-2110-63ce-1e57-5b04240a85bd.png)

- Result
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3470230/045952ff-b7cb-48c5-1a9d-dcbc745d3b4a.png)


- analysis
  - qubit-Qの初期値が**1**
  - 上記のResult図から、qubit-Bの計測結果が**1**であることを分かった

  
要は、qubit-Qがqubit-Bに"伝送"できたという意味