チュートリアル Multi-Qubit Systems解説および解答例

Githubリンク
https://github.com/microsoft/QuantumKatas/tree/master/tutorials/MultiQubitSystems

(いきなりこのページに飛んできた人で最初から勉強されたい方はこちらをご参照ください)

前回は1Qubitの操作を学んできました、今回は複数Qubit(主に2Qubit)の操作を学習していきます。

ポイント

複数ビットになって数字の数が増えて複雑になっていますが、ここでのポイントは複数ビットの状態は単独ビットのテンソル積の状態に分割可能な場合があり、今回の学習では基本的に分割できる問題ばかりなので、まずは分割してどのような状態にすればよいかを考えていきます。(テンソル積はLinear Algebra Part 2で出てきていますのでお忘れの方はこちらで復習を。)

一般的に書くと下記のようになります。
\[ \begin{bmatrix} \alpha \color{red}\gamma \\ \alpha \color{red}\delta \\ \beta \color{red}\gamma \\ \beta \color{red}\delta \end{bmatrix} = \begin{bmatrix} \alpha \\ \beta \end{bmatrix} \otimes \begin{bmatrix} \color{red}\gamma \\ \color{red}\delta \end{bmatrix} \]


Exercise 1: Show that the state is separable

自分が悩んだポイントを補足しておきます。
\[ \frac{1}{2} \begin{bmatrix} 1 \\ i \\ -i \\ 1 \end{bmatrix} = \begin{bmatrix} ? \\ ? \end{bmatrix} \otimes \begin{bmatrix} ? \\ ? \end{bmatrix} \]
これを上記の一般式に当てはめると
\[ \begin{cases} \alpha\gamma = \frac{1}{2} \\ \alpha\delta = \frac{i}{2} \\ \beta \gamma = \frac{-i}{2} \\ \beta \delta = \frac{1}{2} \\ \end{cases} \]
となります。
さらにこれらを解いていくと \( \frac{\alpha}{\beta} = \frac{-1}{i} = i \) となります。
ここで \( |\alpha|^2 + |\beta|^2 = 1 \)を考慮すると
\[ \alpha = \frac{1}{\sqrt2}, \beta = \frac{-i}{\sqrt2}, \gamma = \frac{1}{\sqrt2}, \delta = \frac{i}{\sqrt2} \] となり解を導くことができます。 問題文には出てきませんが、Qubitの条件 \( |\alpha|^2 + |\beta|^2 = 1 \)を考慮することで解を導くことができます。

いろいろ計算が複雑ですが、ここではヒントもあるのでまずは下記の4つの活用を考えればよいと思います。
\[ \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \otimes \begin{bmatrix} 1 \\ 0 \end{bmatrix},   \begin{bmatrix} 0 \\ 1 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \otimes \begin{bmatrix} 0 \\ 1 \end{bmatrix},   \begin{bmatrix} 0 \\ 0 \\ 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix} \otimes \begin{bmatrix} 1 \\ 0 \end{bmatrix},  \begin{bmatrix} 0 \\ 0 \\ 0 \\ 1 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix} \otimes \begin{bmatrix} 0 \\ 1 \end{bmatrix} \]

Demo解説

解説を読んでるだけではわからないところも多いので、実際にDemoを動かしてみて理解を深めていきましょう。

量子ビットの配置

Qubitを配列で配置します。初期状態は|00>です。
    // This allocates an array of 2 qubits, each of them in state |0⟩.
    // The overall state of the system is |00⟩
    using (qs = Qubit[2]) {
つまり
\[ \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \otimes \begin{bmatrix} 1 \\ 0 \end{bmatrix} \]
という状態です。

1Qubit目の反転

qs[0]=1ビット目をXゲートで反転させます。
        // X gate changes the first qubit into state |1⟩
        // The entire system is now in state |10⟩
        X(qs[0]);
\[ \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \otimes \begin{bmatrix} 1 \\ 0 \end{bmatrix} \]
の状態の1ビット目を反転させるので
\[ \begin{bmatrix} 0 \\ 1 \end{bmatrix} \otimes \begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ 1\\ 0 \\ 0 \end{bmatrix}  \]
になります。
結果は
System in state |10⟩ = |1⟩:
# wave function for qubits with ids (least to most significant): 0;1
∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]                   
∣1❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]                   
∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]        
コメントが"System in state |10⟩ = |1⟩:"になっていますが、"System in state |10⟩ = |10⟩:"のほうが正確ですかね。

アダマールゲート適用

2ビット目にアダマールゲートを適用します。
        // This changes the second qubit into state |+⟩ = (1/sqrt(2))(|0⟩ + |1⟩).
        // The entire system is now in state (1/sqrt(2))(|10⟩ + |11⟩)
        H(qs[1]);
\[ \begin{bmatrix} 0 \\ 1 \end{bmatrix} \otimes \begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ 1 \\ 0 \end{bmatrix}  \]
の状態の2ビット目にHゲートを適用するので2ビット目が
\( H|1\rangle = |+\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle + |1\rangle\big) \)
となり
\[ \begin{bmatrix} 0 \\ 1 \end{bmatrix} \otimes \frac{1}{\sqrt{2}} \begin{bmatrix} 1 \\ 1 \end{bmatrix} = \frac{1}{\sqrt{2}}\begin{bmatrix} 0 \\ 1 \\ 0 \\ 1 \end{bmatrix}  \]
となります。
System in state (1/sqrt(2))(|10⟩ + |11⟩) = (1/sqrt(2))(|1⟩ + |3⟩):
# wave function for qubits with ids (least to most significant): 0;1
∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]                   
∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]                   
∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]

1ビット目にもアダマールゲート適用

1ビット目は|1>なので|->になるので、
        // This changes the first qubit into state |-⟩ = (1/sqrt(2))(|0⟩ - |1⟩)
        // The entire system is now in state 0.5(|00⟩ + |01⟩ - |10⟩ - |11⟩)
        H(qs[0]);
\[ \frac{1}{\sqrt{2}} \begin{bmatrix} 1 \\ -1 \end{bmatrix} \otimes \frac{1}{\sqrt{2}} \begin{bmatrix} 1 \\ 1 \end{bmatrix} = \frac{1}{2}\begin{bmatrix} 1 \\ -1 \\ 1 \\ -1 \end{bmatrix}  \]
となります。
System in state 0.5(|00⟩ + |01⟩ - |10⟩ - |11⟩) = 0.5(|0⟩ + |2⟩ - |1⟩ - |3⟩):
# wave function for qubits with ids (least to most significant): 0;1
∣0❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
∣1❭:	-0.500000 +  0.000000 i	 == 	******               [ 0.250000 ] ---     [  3.14159 rad ]
∣2❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
∣3❭:	-0.500000 +  0.000000 i	 == 	******               [ 0.250000 ] ---     [  3.14159 rad ]  

量子もつれの生成

ここまではQubitを分解してそれぞれのQubitの状態を変化させテンソル積で複数Qubitの状態を表してきましたが、ここではEntangle状態(分割不可)の状態を作り出します。
1ビットずつの操作ではなく2ビットまとめて操作することでEntangle状態を作り出すことができます。
        // The next lines entangle the qubits.
        // Don't worry about what exactly they do for now
        H(qs[1]);
        CNOT(qs[0], qs[1]);
CNOTゲートはのちのチュートリアルで出てくるのでここでは細かい説明を省略しますが、1ビット目の状態を見て、2ビット目を反転させる処理になります。
Entangled state 0.5(|00⟩ - |11⟩):
# wave function for qubits with ids (least to most significant): 0;1
∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]                   
∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]                   
∣3❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
この状態はExercise 2で出てきた不可分な状態(量子もつれ状態)ですね。

Exercise 3: Prepare a basis state

デモの内容が理解できれば簡単だと思います。
初期状態は分解可能なので
\( \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix} =
\begin{bmatrix} 1 \\ 0 \end{bmatrix} \otimes \begin{bmatrix} 1 \\ 0 \end{bmatrix} \) から  \( \begin{bmatrix} 0 \\ 0 \\ 0 \\ 1 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix} \otimes \begin{bmatrix} 0 \\ 1 \end{bmatrix} \)
を作り出します。 それぞれのビットを反転させるだけですね。
%kata T1_PrepareState1_Test

operation PrepareState1 (qs : Qubit[]) : Unit is Adj+Ctl {
    X(qs[0]);
    X(qs[1]);
}

Exercise 4: Prepare a superposition of two basis states

ヒントをみて
\[ |0\rangle \otimes \frac{1}{\sqrt2}\big(|0\rangle - |1\rangle\big) = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \otimes \frac{1}{\sqrt2}\begin{bmatrix} 1 \\ -1 \end{bmatrix} \]
を作り出すことを理解すればそれほど難しくありません。
2ビット目を\(|-\rangle \)にすればよいので、Xゲート、Hゲートの順に適用します。
%kata T2_PrepareState2_Test

operation PrepareState2 (qs : Qubit[]) : Unit is Adj+Ctl {
    X(qs[1]);
    H(qs[1]);
}

Exercise 5: Prepare a superposition with real amplitudes

この問題もヒントをみて
\[ \frac{1}{\sqrt2}\big(|0\rangle + |1\rangle\big) \otimes \frac{1}{\sqrt2}\big(|0\rangle - |1\rangle\big) = \frac{1}{\sqrt2} \begin{bmatrix} 1 \\ 1 \end{bmatrix} \otimes \frac{1}{\sqrt2}\begin{bmatrix} 1 \\ -1 \end{bmatrix} \]
を作り出すことがわかれば簡単です。2ビット目は先ほどのExercise 4と同じなので1ビット目を \(|+\rangle \) にするためにHゲートを適用します。
%kata T3_PrepareState3_Test

operation PrepareState3 (qs : Qubit[]) : Unit is Adj+Ctl {
    H(qs[0]);
    X(qs[1]);
    H(qs[1]);
}

Exercise 6: Prepare a superposition with complex amplitudes

ヒントに書かれていることを導き出すのが難しいかもしれませんが、ヒントがあるのでヒントに書かれていることを実装すればよいです。それぞれ\(|+\rangle \)にSゲート、Tゲートを適用すればよいです。
%kata T4_PrepareState4_Test

operation PrepareState4 (qs : Qubit[]) : Unit is Adj+Ctl {
    H(qs[0]);
    S(qs[0]);
    H(qs[1]);
    T(qs[1]);
}