LoginSignup
5
4

More than 3 years have passed since last update.

Qiskitで任意のユニタリー行列から量子ゲート(量子回路)を作る

Last updated at Posted at 2020-03-13

ここ数ヶ月何度か同じコードが必要になる(聞かれる)ケースがあったので、コードサンプルを載せておきます。
何かしようとすると意外と使いたい機能な気がします。

コードは2020/3/13現在のものです。
もし間違いがあったら教えてください。

from qiskit import QuantumCircuit
from qiskit.quantum_info.operators.operator import Operator
import numpy as np

# 任意の数の量子ビットと古典ビットを持つ量子回路を用意(今回は適当に2qubit)
qc = QuantumCircuit(2,2)

# ユニタリー行列を用意(今回は適当に単位行列)
unitary = np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]])

# ユニタリー行列からオペレーターを作成
operator = Operator(unitary)

# 量子回路(qubit0番と1番)にオペレーターを作用(ユニタリーでなかった場合はエラーが出る)
qc.append(operator, [0,1])

# 実行する部分は省略
5
4
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
5
4