아래에서는 Quantum Amplitude Estimation (QAE) 알고리즘에 대해 수식, 회로도, 그리고 Qiskit 코드를 포함하여 자세히 설명하겠습니다.
1. 개요
QAE는 Grover 검색 알고리즘의 아이디어를 확장하여 특정 “좋은(good)” 상태의 진폭(확률)을 추정하는 알고리즘입니다.
즉, 어떤 양자 상태
[
A|0\rangle = \sqrt{1-a},|\Psi_0\rangle + \sqrt{a},|\Psi_1\rangle
]
가 있다고 했을 때, 여기서 (a)가 “좋은” 상태 (|\Psi_1\rangle)가 측정될 확률입니다. QAE는 이 (a)를 고정된 정확도로 추정할 수 있는 알고리즘입니다.
2. 수식으로 본 QAE
(1) 상태 준비 연산자 (A)
우리는 주어진 문제에 대해 상태 준비 연산자 (A)를 구성할 수 있다고 가정합니다.
즉,
[
A|0\rangle = \sqrt{1-a},|\Psi_0\rangle + \sqrt{a},|\Psi_1\rangle.
]
여기서 (a)는 우리가 추정하려는 확률(amplitude)입니다.
(2) Grover 오퍼레이터 (Q)
QAE는 Grover 오퍼레이터의 반복을 통해 진폭의 phase 정보를 추출합니다. 일반적으로 Grover 오퍼레이터는 다음과 같이 정의됩니다.
[
Q = A , S_0 , A^\dagger , S_{\psi_0},
]
여기서
(S_0 = 2|0\rangle\langle0| - I)는 초기 상태에 대한 반사 연산자이며,
(S_{\psi_0} = I - 2|\Psi_1\rangle\langle\Psi_1|)는 “좋은” 상태에 대한 위상 반전 연산자입니다.
Grover 오퍼레이터 (Q)는 두 고유상태 ( |\Psi_{\pm}\rangle )를 갖고, 이들의 고윳값은
[
e^{\pm2i\theta}, \quad \text{with } \sin^2(\theta) = a,
]
로 나타납니다.
(3) Phase Estimation을 통한 amplitude 추정
QAE에서는 위 (Q) 연산자의 위상 추정(Quantum Phase Estimation, QPE) 을 사용합니다.
즉, (Q)에 대한 QPE를 수행하면 (2\theta) (혹은 (\theta))에 해당하는 고윳값의 위상 추정 결과를 얻습니다.
최종적으로 amplitude (a)는 다음 관계에 의해 복원됩니다.
[
a = \sin^2(\theta).
]
즉, QAE 알고리즘은 상태 준비 연산자 (A), Grover 오퍼레이터 (Q), 그리고 QPE를 결합하여 amplitude (a)를 효율적으로 추정합니다.
Ancilla 레지스터: (m)개의 큐빗에 Hadamard 변환을 적용하여 균등한 중첩 상태를 생성합니다.
Controlled-(Q^{2^j}): 각 ancilla 큐빗에 대해 (Q)의 거듭제곱(2의 거듭제곱)을 제어하여 적용합니다.
역 QFT (Inverse QFT): phase estimation의 결과를 디코딩합니다.
마지막에 ancilla 큐빗을 측정하여 (2\theta) (혹은 (\theta))에 관련된 정보를 획득하고, 이를 통해 (a = \sin^2(\theta))를 계산합니다.
4. Qiskit 코드 예제
다음은 Qiskit을 사용하여 간단한 QAE 예제를 구현하는 코드입니다.
이 예제에서는 Amplitude Estimation 알고리즘을 이미 구현해놓은 Qiskit Aqua (또는 최신 Qiskit Machine Learning/Finance 등) 모듈을 활용합니다.
(참고: Qiskit Aer, Qiskit Algorithms 패키지의 버전에 따라 import 경로가 다를 수 있습니다.)
python
import numpy as np
from qiskit import Aer
from qiskit.utils import QuantumInstance
# Qiskit Algorithms의 Amplitude Estimation 라이브러리 임포트 (버전에 따라 다름)
from qiskit.algorithms import AmplitudeEstimation
from qiskit.circuit.library import ZFeatureMap
# 문제에 따라 A (state preparation operator)를 정의해야 합니다.
# 여기서는 간단하게 1큐빗 회로를 이용한 예제를 구성합니다.
# 예를 들어, 아래와 같이 |ψ〉 = A|0〉 = sin(θ)|1〉 + cos(θ)|0〉 인 상태를 생성한다고 가정합니다.
import math
from qiskit.circuit import QuantumCircuit
# 진짜 amplitude a = sin^2(θ)
theta = math.pi/6 # 예: θ = 30도 → a = sin^2(30°)=0.25
a_true = np.sin(theta)**2
print("True amplitude a =", a_true)
# 상태 준비 연산자 A: RY(2θ)를 사용하면,
# A|0⟩ = cos(θ)|0⟩ + sin(θ)|1⟩, 즉, a = sin^2(θ)
def state_preparation():
qc = QuantumCircuit(1)
qc.ry(2 * theta, 0) # A = RY(2θ)
return qc
# Q operator는 자동으로 내부에서 구성됩니다.
# Amplitude Estimation에 전달하기 위해서는 'oracle' 또는 'state_preparation'
# 회로가 필요합니다.
# Qiskit Amplitude Estimation에서는 'post_processing' 없이 직접 amplitude estimation을 시행합니다.
# n_eval_qubits: ancilla 큐빗 수 (정확도와 관련)
n_eval_qubits = 3
# 백엔드 설정
backend = Aer.get_backend('qasm_simulator')
quantum_instance = QuantumInstance(backend, shots=10000)
# Amplitude Estimation 객체 생성
ae = AmplitudeEstimation(num_eval_qubits=n_eval_qubits, state_preparation=state_preparation())
# 알고리즘 실행
result = ae.estimate(oracle=None) # oracle이 없는 경우, state_preparation으로만 추정
# 결과 출력
print("Estimated amplitude a =", result.estimation)
print("Standard deviation =", result.standard_deviation)
코드 설명
상태 준비:
state_preparation() 함수에서 한 큐빗에 대해 RY(2θ) 게이트를 적용합니다.
이때 (A|0\rangle = \cos(\theta)|0\rangle + \sin(\theta)|1\rangle)가 되어, “좋은” 상태 (|1\rangle)의 확률은 (a = \sin^2(\theta))입니다.