2
2

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 3 years have passed since last update.

Qiskitで反復量子位相推定を勉強する

Posted at

反復量子位相推定とは

以前の記事で量子位相推定(QPE)をやりました。
https://qiita.com/notori48/items/6522389a7582a40d3f15

その発展版として反復量子位相推定(Iterative QPE : IQPE)があります。
https://dojo.qulacs.org/ja/latest/notebooks/7.1_quantum_phase_estimation_detailed.html
IQPEは、QPEよりも補助量子ビットを少なくして実行できますので、
量子ビット数や量子ビット間の接続が制限されている場合には有用といえます。

IQPEの入出力

QPEでは固有値の規格化位相を一気に$t$桁読み出していたので、補助量子ビットも$t$個必要でした。
IQPEでは、1桁ずつ読み出す操作を$t$回繰り返すことで、一度に必要な補助量子ビットは1個で済みます。
基本的にはQPEを逐次処理に分解しただけと思ってよいかと。

qiskitでIQPE

qiskitでやってみます。
問題に対して非常にスペシフィックなコードを書いていますが、、

問題は過去の記事
https://qiita.com/notori48/items/6522389a7582a40d3f15
に書いたとおりです。

固有ベクトルとして$|1 \rangle$ を入れます。出力の期待は001です。
末尾から読み出していきます。
初段は 1 が出れば正解。

pip install qiskit pylatexenc
# initialization
import matplotlib.pyplot as plt
import numpy as np
import math

# importing Qiskit
from qiskit import IBMQ, Aer
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute

# import basic plot tools
from qiskit.visualization import plot_histogram
# U = [1 0 ; 0 exp(pi/4)]
# eigen value is 2pi(0) for |0> , 2pi(0.001) for |1>
t = 3 # num of iteration
k = 3 # iteration
qpe = QuantumCircuit(2, 1) # 1 bit for eigen state and 1 ancilla bit for phase kick back
qpe.x(1) # 2nd bit becomes eigen state, |0>
qpe.h(0) # Hadamard for 1st ancilla bit

for i in range(2**(t-1)):
    qpe.cu1(math.pi/4, 0, 1); # This is Controlled-U , controll-qubit is 0 (ancilla) , target-qubit is 1 (eigen)

qpe.h(0) # Hadamard for 1st ancilla bit
qpe.measure(0,0)

backend = Aer.get_backend('qasm_simulator')
shots = 1
results = execute(qpe, backend=backend, shots=shots).result()
answer = results.get_counts()
print(answer)

とやると"1"と出ます。正解。

この結果も活用して1桁シフトして再度読み出します。

k = 2 # iteration
phi = math.pi/2; # pi * [0.1]_{2} = pi/2
qpe = QuantumCircuit(2, 1) # 1 bit for eigen state and 1 ancilla bit for phase kick back
qpe.x(1) # 2nd bit becomes eigen state, |0>
qpe.h(0) # Hadamard for 1st ancilla bit
qpe.rz(-1*phi,0)
for i in range(2**(k-1)):
    qpe.cu1(math.pi/4, 0, 1); # This is Controlled-U , controll-qubit is 0 (ancilla) , target-qubit is 1 (eigen)

qpe.h(0) # Hadamard for 1st ancilla bit
qpe.measure(0,0)
backend = Aer.get_backend('qasm_simulator')
shots = 1
results = execute(qpe, backend=backend, shots=shots).result()
answer = results.get_counts()

print(answer)

とやると、"0"と出ました。正解。
では最後の桁へ。

k = 1 # iteration
phi = phi/2 + math.pi*0; # pi * [0.1]_{2} = pi/2
qpe = QuantumCircuit(2, 1) # 1 bit for eigen state and 1 ancilla bit for phase kick back
qpe.x(1) # 2nd bit becomes eigen state, |0>
qpe.h(0) # Hadamard for 1st ancilla bit
qpe.rz(-1*phi,0)
for i in range(2**(k-1)):
    qpe.cu1(math.pi/4, 0, 1); # This is Controlled-U , controll-qubit is 0 (ancilla) , target-qubit is 1 (eigen)

qpe.h(0) # Hadamard for 1st ancilla bit
qpe.measure(0,0)

とやると、"0"が出ました。正解。

以上、3度の結果をつなげると "0""0""1" = "001" ということで、ちゃんと固有値の規格化位相が出ています。

ちょっと不満足なのは、うまいことfor文で書けていないところです。
まだpythonもqiskitも慣れていないので、、
まぁそこは本質的な部分ではないので、おいおい慣れていきます。

結論

QPEがわかっていれば、IQPEはそんなに難しくない。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?