1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

量子回路の出力状態ベクトルを求めたい・・・手計算ではなく、パソコンで。

Last updated at Posted at 2022-04-26

量子回路の出力状態ベクトルを求めたい

量子計算について学習するとき、「今の量子回路の出力状態を求めたいなー」って思う時があります。
もちろん、手計算で求められます。
でも回路が複雑になってくると、思いのほか面倒です。
(あるいは単に面倒でやる気が出ない時)
そんな時に、パソコンを使って簡単に求める方法について解説します。

1. Qiskitをインストールする

ネットを探したら方法はいくらでも見つかりますので、省略します。

2.Qiskit textbookをインストールする

以下のコマンドを実行します。

pip install git+https://github.com/qiskit-community/qiskit-textbook.git#subdirectory=qiskit-textbook-src

3. 以下のプログラムを実行

from qiskit import *
from qiskit_textbook.tools import array_to_latex

# (1)出力状態を求めたい量子回路を作る。(ここでは例として、簡単な回路を作ります)
qc = QuantumCircuit(1)
qc.h(0)

# あとはコピペでOKです。
# (2)シミュレーションして、状態ベクトルを取得します。
backend = Aer.get_backend('statevector_simulator')
final_state = execute(qc,backend).result().get_statevector()

# (3)綺麗に表示します
array_to_latex(final_state, pretext="\\text{Statevector = }")

latexを使うので、Jupiter Notebook上で実行するのが良いと思います。

実行結果

image.png

具体例を紹介

$CNOT$ゲートと$H$ゲートで「もつれ状態」を作ることができます。
image.png

この回路の出力状態を見てみましょう。

from qiskit import *
from qiskit_textbook.tools import array_to_latex

# (1)出力状態を求めたい量子回路を作る。(ここでは例として、簡単な回路を作ります)
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1) # (control, target)

# あとはコピペでOKです。
# (2)シミュレーションして、状態ベクトルを取得します。
backend = Aer.get_backend('statevector_simulator')
final_state = execute(qc,backend).result().get_statevector()

# (3)綺麗に表示します
array_to_latex(final_state, pretext="\\text{Statevector = }")

実行結果

image.png

つまり、$CNOT|0+\rangle = \frac{1}{\sqrt{2}}(|00\rangle+|11\rangle)$ということですね。

(この記事は https://qiskit.org/textbook/ja/ch-gates/multiple-qubits-entangled-states.html を参考にしています。)

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?