らんだむな記憶

blogというものを体験してみようか!的なー

<QT> H ゲートと T ゲートによる任意の回転

https://qiskit.org/textbook/ch-gates/more-circuit-identities.html#5.-Arbitrary-rotations-from-H-and-T-

書いていることが少し分かりにくいが、$R_z(\frac{\pi}{4}) R_x(\frac{\pi}{4})$ というゲートを $H$ ゲートと $T$ ゲートの組み合わせで作ることができて、これも回転になる*1。このセットのゲートが沿う大円上での回転角が $\pi$ の無理数倍であり、適当な整数回の適用で元の状態に戻ってこないことを言っている。一般論でこのケースでは回転の任意回の適用は大円を稠密に埋めるため、任意の $n$ に対して、うまい回数を選ぶと $\frac{2\pi}{n}$ の精度の回転数が原理的には求まることを述べている。

ただ、

Note that the discussion above was simply intended to prove that $T$ gates can be used in this way, and does not represent the most efficient method we know.

ということで、$T$ ゲートを使って、いい感じの回転を作り出すわけではなく、説明用にこういうことを述べたと補足されている。

svsim = Aer.get_backend('aer_simulator')
qc = QuantumCircuit(1)
qc.h(0)
qc.t(0)
qc.h(0)
qc.t(0)
qc.save_statevector()
qobj = assemble(qc)
results = svsim.run(qobj).result()
statevector = results.get_statevector()
print(statevector)

Statevector([0.85355339+0.35355339j, 0.35355339-0.14644661j],
dims=(2,))

であるが、$T$ ゲートと $Rz(\frac{\pi}{4})$ では定義上、グローバル位相の差があるので、$Rz(\frac{\pi}{4})$ を使う場合には計算結果を少し補正しないと同じ表現は得られない。

rx = np.array([
    [np.cos(np.pi/8), -np.sin(np.pi/8)*1.j],
    [-np.sin(np.pi/8)*1.j, np.cos(np.pi/8)]
])

rz = np.array([
    [np.exp(-np.pi/8*1.j), 0],
    [0, np.exp(np.pi/8*1.j)]
])

np.exp(np.pi/4*1.j) * rz @ rx @ np.array([1, 0])

array([0.85355339+0.35355339j, 0.35355339-0.14644661j])

という感じでグローバル位相の差を考慮すると直接計算と結果が一致する。
補正をかける前の部分については

$$
\begin{align*}
\begin{bmatrix}
\exp(-i \frac{\pi}{8}) \cos \frac{\pi}{8} \\
-i \exp(i \frac{\pi}{8}) \sin \frac{\pi}{8}
\end{bmatrix}
\end{align*}
$$

ということになる。

*1:回転群とその表現 - 岩波書店 などに書かれている