2023年12月1日金曜日

Developing the most basic app to understand Qubit state (3)

Sometimes we need to go back to basics!
In the third article in this series, I'll compare my app's results with that of IBM Quantum Composer to confirm that it's working correctly. In my app I can use quantum gates Z, X, Y, T, H.  The T is a quantum gate that adds the phase of e^iφ to the qubit |1>. By default, φ=π/4. Also, H is a Hadamard gate. Here, as an example, H, T, and H are successively applied in this order to the quantum bit initial state |0>.

Fig.1 shows (a) the execution results of my app and (b) the execution results of IBM Quantum. In (a), the probability (area of the colored disk) and phase (the angle of the straight line coming out from the center of the circle) are shown for |0> and |1>. On the other hand, in (b), the results are displayed only for |1>. Although the way the disks are displayed is slightly different, it can be seen that the probabilities and phases of both are the same. However, the values of probability amplitude (amplitude in (a) and Output state in (b)) seem to be different. This will be explained in Fig.2.
Fig.2 explains that although the expressions of the probability amplitudes of the two are different, they are the same quantum state. In my app, the phase with respect to |0> is zero, and the phase of |1> is the relative phase to it. This does not seem to be the case with IBM Quantum. In fact, when I input IBM's probability amplitude numbers into my app's function state2relphase, the results I got matched my app's representation of probability amplitudes. This result confirms that my app is working perfectly correctly, at least for this example.

2023年11月27日月曜日

Developing the most basic app to understand Qubit state (2)

 Sometimes we need to go back to basics!

This is a major update to the previous app. The aim was to help students become familiar with the most basic elements of quantum computing using only their smartphones. The example below shows the results of (1) starting from the initial state, (2) applying the Pauli X gate, (3) then applying the Hadamard gate, and (4) applying the Hadamard gate again. 

The probability amplitude, probability, and relative phase of each basis |0>, |1> are shown numerically and on a disk. Additionally, the values of θ and φ can be set using text boxes and sliders, making it easy to understand the position of the quantum bit on the Bloch sphere.




2023年11月25日土曜日

Developing the most basic app to understand Qubit state (1)

Sometimes we need to go back to basics!

As I have already written several times, I was able to almost completely understand the basic concepts and ideas of quantum computing by reading the book [1]. Although this book does not explain the Bloch sphere or phases in detail, I would not have been able to write this article without the knowledge I gained from the book.

I developed an app to understand the state of qubits on the Bloch sphere. As shown in the figure below, set the two angular parameters θ and φ using the sliders for a single qubit on the Bloch sphere. This app uses it to calculate the probability amplitude and probability for each of the two basis (|0> and |1>). Probability and phase are also illustrated in the two disks at the top right. Note that since the global phase can be ignored, the phase of |0> is set to 0, and the phase of |1> is expressed as a relative phase to that.

As you can see, the current app specifies θ and φ manually. In the next version, it will also be possible to apply basic quantum gates (X, Y, Z, H, etc.).

References
[1] Chris Bernhardt: Quantum Computing for Everyone, The MIT Press, 2020.
https://www.chrisbernhardt.info/

2023年11月1日水曜日

Try solving 3-SAT using Qiskit's Quantum Algorithms Module

[Summary] Grover's algorithm circuit and its implementation have already been described in this article. One of the challenges was generating an oracle according to the search target. When the number of qubits was 2 or 3, it was possible to create it through trial and error, but as the number of qubits increases, it becomes difficult. Therefore, Qiskit provides the Quantum Algorithms Module[1]. This includes Grover. It consists of PhaseOracle, which generates oracles for phase inversion, and Amplification, which amplifies the probability amplitude. By using this, it becomes easy to create large-scale Grover circuits. Additionally, since PhaseOracle can generate oracles from logical expressions, it can be easily applied to 3-SAT problems, etc.[2] The implementation status will also be described.
There are various 3-SAT solvers that use classical computers. Although the content of this article cannot reach the performance of those systems, I would like to connect it to thinking about the potential possibilities for extremely large-scale problems. This is true for quantum computing in general.

Generate oracle from logical formula and amplify probability amplitude
As a simple 2-qubits example, let |10> be the state to be searched. Give a logical expression '(a&~b)' to PhaseOracle to generate an Oracle for it. Next, give the generated Oracle to AmplificationProblem, which has a probability amplitude amplification function. The generated Oracle circuit diagram is shown below. The two filled-in circles and their connections in the circuit diagram are the same as CZ (Controlled Pauli-Z).
Furthermore, draw the entire Grover circuit diagram as shown below. Here, the open circle means that the gate of the target bit is activated when the control bit is |0>.
The results of running this circuit with a simulator (ibmq_qasm) are shown below. As expected, '10' was observed with probability 1.0. In the display below, '01' is measured. This is because the order of the bits in the execution result on the actual machine is the reverse order compared to when they were given as input.

Solving 3-SAT problems using Grover's algorithm
Next, as an example, solve the 3-SAT shown below. If you give the logical formula of the problem to PhaseOracle as shown below, the corresponding Oracle will be generated. Furthermore, similar to the example above, you can create a circuit of the Grover algorithm that includes this Oracle. Below is the Oracle schematic and the entire algorithm schematic.

Next, as a backend, set up a quantum simulator or a real quantum computer, generate a Grover object, give the above Grover circuit to its method amplify, and run it. The number of repetitions was 1. In other words, iterations=1. The method for calculating the optimal value for Iterations has been clarified, and in this case (3 qubits and 3 solutions), 1 is optimal.
Finally, we show calculation results using a simulator (ibmq_qsam) and an actual quantum computer (brisbane with 127 qubits). Since a certain amount of errors occur on a real machine, the separation of solutions is a little less clear than in the case of a simulator, but it can be said that three correct solutions have been found. (Note) The bit order of the execution result is in the reverse order of the tensor product.
References
[1] James L. Weaver & Frank J. Harkins, “Qiskit Pocket Guide”, O’reilly, 2022.
[2] Grover's algorithm examples, 
https://github.com/Qiskit/qiskit-tutorials/blob/master/tutorials/algorithms/07_grover_examples.ipynb

2023年10月24日火曜日

Oracle and Amplitude Amplifier in Grover's Quantum Algorithm

[Summary] The Grover search algorithm, which is one of the famous quantum algorithms, has already been discussed in the articles below, so I will not explain its meaning or solution in detail here.
In this article, we will review flipping the sign of probability amplitude and inversion about the mean value. Also includes execution results on the latest IBM quantum computer (127 qubits). The following discussion is based on knowledge gained from reference [1].

Grover's algorithm quantum circuit
Here we consider the case of 2 qubits (number of qubits n = 2). In addition, one more qubit is used for control. The quantum circuit is shown in Fig.1. For all qubits, we apply a Hadamard gate to create a uniform superposition state as an initial state. Next, configure Oracle F for the target function f. The bit string xy with f(xy)=1 is what is searched. Now, the target is set to xy=10. The function of this Oracle F is to flip the sign of the probability amplitude of the basis |10> corresponding to this target. The probability amplitude of other basis is not changed.

The next gate A inverts the four basis probability amplitudes of the top 2 qubits system about the mean of their values. As a result, only the probability amplitude whose sign was flipped in the preceding Oracle is amplified, and the others are attenuated. By repeating Gate F and Gate A as a set, a specific basis can be measured with a high probability (approximately close to 1.0). That's what you're looking for. This repetition needs to be performed only once when n=2.


Amplitude Amplification Matrix
Now, if we multiply matrix A shown in the upper right corner of Fig. 1 (diagonal elements are -1 and other elements are 1) by the ket vector whose elements are probability amplitudes', the probability amplitudes will certainly be amplified. We can understand that. This is detailed in Chapter 9 of Reference [1]. But how did we derive this matrix? This is explained using Fig.2. Although we will deal with the case of n=2 here, it will be easier to understand if we consider the general case of n. In short, it takes advantage of the fact that the result of inverting the value p of an element around the average value m of all elements is 2m-p.

Execution on the IBM Quantum 127 qubits real machine
After making the above preparations, execute the quantum circuit shown in Fig.3. The Oracle F circuit was configured for f(10)=1. Also, the amplitude amplification section (purple Amp gate) that inverts about the average value can be configured with Hadamard gates, X gates, and controlled X gates, but it is also possible to just give the unitary matrix A shown in Fig.2. The latter seems easier to think about.
The execution results are shown in Fig.4. These are the execution results of (a) ibm_lagos with a 7-qubits Falcon processor, (b) ibm_brisbane with a 127-qubits Eagle processor, and (c) ibmq_qsam simulator. First, by the simulator (c), the basis of the target was measured with a probability of 1.0, as in theory.

On the other hand, the error rate of the machine (a)lagos was relatively high, and the target basis was measured with a probability of 0.75, and other basis were also measured slightly. However, with the latest model (b) brisbane, the target basis probability has improved to 0.87. Enough information was obtained to find the desired solution.
Impressions
Until last year, IBM provided general users with real machines with 5-qubits and 7-qubits for free, but recently they have also made the latest machine with 127-qubits available for free. In fact, in April 2023, there was news [2] that "The University of Tokyo will be the first university outside of North America to install an IBM Eagle 127 quantum bits computer.'' Only half a year later, anyone could use this (presumably) same quantum computer over the web, as mentioned above. Amazing progress in quantum computers!

In principle, 127 qubits have the potential to simultaneously process a huge number of states: 2 to the 127th power (= 10 to the 38th power). Such a machine can now be used from home via the web, so although there are still many challenges to overcome, the dream is growing.

Words from Prof. Chris Bernhardt
==============================
Dear Fujio,
Another great post! Your site contains really useful information. 
I especially like the fact that you are showing how to do things on the IBM quantum computer.
Chris
==============================
Dear Chris
Thank you very much for reading my blog article.
My introductory quantum computing journey has come to an end.
I was able to achieve this by coming across your wonderful book and fully understanding its contents.
Based on this, I can move on to even higher levels of quantum computing.
Fujio
==============================

References
[1] Chris Bernhardt: Quantum Computing for Everyone, The MIT Press, 2020.
[2] News about the introduction of IBM's 127 qubit computer to the University of Tokyo

2023年10月23日月曜日

Groverの量子アルゴリズムにおけるOracleとAmplitude Amplifier

【要旨】著名な量子アルゴリズムの一つであるGrover search algorithmについては、すでに以下の記事で述べていますので、ここではその意味や解法の詳細説明は略します。
今回の記事では、確率振幅の反転と、平均値を中心とした折り返しに関して復習します。最新のIBM量子コンピュータ(127量子ビット)による実行結果も含みます。以下の考察は、参考文献[1]から得た知識に基づいています。

Groverのアルゴリズムの量子回路
 ここでは2qubits(量子ビット数n=2)の場合を考える。そのほかに、制御用の1qubitを使う。その量子回路をFig.1に示した。全てのqubitsについて、初期状態として均等な重ね合わせ状態を作るため、Hadamardゲートを適用する。次に、対象とする関数fに対してOracle Fを構成する。f(xy)=1となるビット列xyが探索するものである。今はそのターゲットを、xy=10と設定した。このOracleFの機能は、このターゲットに対応するbasis |10>の確率振幅の符号を反転させること(flipping the sign)である。それ以外のbasisの確率振幅は変更しない。

 次のゲートAは、上位の2qubitsシステムの4つのbasisの確率振幅を、それらの値の平均値を中心に反転(inversion about the mean)させる。これによって、前段のOracleで符号反転された確率振幅だけが増幅され、他は減衰することになる。ゲートFとゲートAをセットで繰り返すことによって、(ほぼ1.0に近い)高い確率で特定のbasisが測定されるようになる。それが求めるものである。この繰り返しは、n=2の場合は1回で済む。
Amplitude Amplification Matrix
 さて、Fig.1の右上に示した行列A(対角要素が-1で他の要素は1)を、「確率振幅を要素とするケットベクトル」に掛ければ、確かに上記の通り、確率振幅が増幅されることが分かる。そのことは、参考文献[1]の第9章に詳しく書かれている。だが、どのようにこの行列を導出したのであろうか?それをFig.2で説明する。ここではn=2の場合を扱うのだが、一般のnに対して考察した方が分かり易い。要は、要素の値aを要素全体の平均値mの周りに反転させた結果は、2m-aとなることを利用しているのである。
Execution on the IBM Quantum 127 qubits real machine
 以上の準備をしてFig.3に示した量子回路を実行する。Oracle Fの回路は、f(10)=1に対して構成した。また、平均値で折り返す振幅増幅部(紫色のAmpというゲート)は、Hadamardゲート、Xゲート、制御付きXゲートで構成することもできるが、Fig.2で示したユニタリ行列Aをそのまま与えることもできる。後者の方が、考え易いように思われる。
 その実行結果をFig.4に示す。(a)7-qubits Falconプロセッサのibm_lagos、(b)127-qubits Eagleプロセッサのibm_brisbane、(c)ibmq_qsam simulatorの実行結果である。まず、(c)のシミュレータでは、ターゲットのbasisが理論通り、確率1.0で測定された。
 一方、実機(a)lagosのエラー発生率は比較的高く、ターゲットのbasisは確率0.75で測定され、他のbasisも若干測定された。だが、最新機(b)brisbaneでは、ターゲットのbasisの確率は0.87まで向上した。目的の解を求めるには十分な情報が得られた。
感想
 昨年までは、IBMは一般ユーザに5-qubitsおよび7-qubitsのリアルマシンを無償提供していたが、最近、実に127-qubitsという最新マシンも、無料で使えるようにした。実は、2023年4月に、「北米以外で初めて、東大にIBM Eagle 127量子ビットコンピュータを導入」のニュース[2]があった。それから僅か半年で、これと(恐らく)同じ量子コンピュータを、上記の通り、誰でもwebから使えるようになったのである。驚くべき、量子コンピュータの進歩である!
 127量子ビットは、原理的には、2の127乗(=10の38乗)個の状態を同時に処理できる可能性を秘めている。アルゴリズムの発案次第である。そんなマシンを、今や、自宅からweb経由で利用できるのであるから、まだまだ課題は山積ではあるが、夢は膨らむ。

Prof. Chris Bernhardtからのコメント
(英語版記事はこちら
==============================
Dear Fujio,
Another great post! Your site contains really useful information. 
I especially like the fact that you are showing how to do things on the IBM quantum computer.
Chris
==============================
Dear Chris
Thank you very much for reading my blog article.
My introductory quantum computing journey has come to an end.
I was able to achieve this by coming across your wonderful book and fully understanding its contents.
Based on this, I can move on to even higher levels of quantum computing.
Fujio
==============================

References
 [1] Chris Bernhardt: Quantum Computing for Everyone, The MIT Press, 2020.

[2] 東大にIBMの127量子ビットコンピュータ導入のニュース


2023年10月6日金曜日

Simonの量子アルゴリズムとHadamard行列のKronecker積

【要旨】量子コンピューティングでの重要な行列(ゲート機能)の一つに、アダマール行列があります。複数の量子ビットシステム(テンソル積)の各量子ビットにアダマール変換を施すための行列が、Kronecker Products of Hadamard Matrices(アダマール行列のクロネッカー積) です。記念碑的解法として有名なSimonの量子アルゴリズムにも有効に使われています。それは、参考文献[1]で丁寧に説明されているのですが、時間が経つと忘れてしまうので、私自身の理解をメモとして残して置きます。

Simon's Algorithm
 まず、ここで解くべき問題については既に本ブログ(2022-12-11の記事)に書いたので、以下に極く簡単に記す:

 長さnのbinary string x(0か1から成る文字列)を入力とし、出力も長さnのbinary stringとなる2対1関数fがあるとする。ここで、ある長さnの秘密のbinary string s があり、y=x or y=x⊕s の時に限りf(x)=f(y) である。ただし、sの全ての文字が0であることは無いとする。記号⊕は、bitwise addition of strings modulo 2を意味する。入力xに対する関数値f(x)を問い合わせることはできるが、関数fの定義は与えられていない。解くべきことは、秘密のsを特定することである。

 そのために、関数fを何回評価する必要があるかを問題とする。古典的アルゴリズムでは、最悪の場合、2のn乗のオーダーの関数呼び出し回数となるが、Simonの量子アルゴリズムではnの多項式オーダーとなる。しかし、この言い方はあまり正確ではない。計算量に関する、BQP(Bounded-error Quantum Polynomial-time)などの議論を、Prof. Bernhardtの書籍[1]のChapter 8 (pp.166-170)等でご覧いただく必要がある。

Simon's Algorithmを実装する量子回路
 Simonの問題は、上記の関数fと秘密のsを知っている人が作成した問題を解く、いわばリバースエンジニアリングである。実用的な問題ではないにも拘らず、これに対するSimonの解法は、量子アルゴリズムの威力を示すものとして広く認められている。そのための量子回路を、n=2とn=3の場合について検討するが、その方法は一般のnについても自然に当てはめることができる。この量子回路の出力であるいくつかのbinary string(長さn)から、秘密のsを特定するための連立一次方程式を作ることができる。なぜかと言うと、出力されたbinary string bと秘密のsとのdot product(後述)が0になるからである。以下に、このようなdot productがなぜ0になるかを中心に、図を使って詳しく述べる。

 Fig.1は、n=2とn=3の場合のSimonのアルゴリズムを実装した量子回路である。上述の通り、関数fに対するOracleが設定されている。すなわち、関数fの定義と秘密のsがこのように決められているのだが、回答する人はそれを知らずにsを特定するのである。


 一般のnに対してのSimonの量子回路は、Fig.2のように描ける。

 さて、Fig.3は、Fig.1でのn=2とn=3の場合の量子回路の実行結果である。2段になっているレジスタの1段目を測定した結果をFig.3に示した。n=2の問題では測定結果としてbinary string 00と10がそれぞれ1/2の確率で得られた。これらのbinary stringと秘密のsとのdot productsは0となる。そうすれば、それらから連立一次方程式を作ってsを特定できのだが、この部分に関しては既に述べたので、ここでは省略する。以降では、なぜ、このdot productsが0になるのかを考察する。
測定結果のbinary stringと秘密のsとのdot productsがなぜ0になるのか
 この質問の回答を、以下で検討する。Fig.4は、Fig.1 case(a)でのψaのフェーズ(2回目のHadamard変換後で測定を行う直前)の4量子ビットシステムの状態ベクトルである。いくつかの計算を経ているが、ここに示されているのは、4qubitsのうちの上段の2qubitsに着目して式を整理した結果である。
 テンソル積の左側が|10>(測定結果10に対応)である項の関数fの値に注目する。秘密sに関するペアのbit string(00と01、および10と11)に対する関数fの値は同一であるが、それらの符号(プラス、マイナス)も同一である。もう一つの測定結果|00>についても同様である。
 一方、測定結果に現れない|01>と|11>に関しては、これらのペアの間数値の符号が互いに反転している。そのため、最終的な計算結果として、|00>と|10>の確率振幅が増大され、|01>と|11>に関しては減衰(キャンセル)されて0となった。
 このような増幅と減衰が、「測定結果のbit stringと秘密のsとのdot podurct (・)」とどのように関係しているかを、Fig.5で明らかにしている。
 以上で説明を終わるのだが、最後に、Fig.6をご覧いただきたい。ここに、Hadamard行列のKronecker積がある。たとえば、n=2の場合の行列を見ると、その各要素の符号は、Fig.4で示した項の符号と完全に合致している。すなわち、Fig.4でのテンソル積の左側のqubitのペアを行ラベルとし、関数fの引数に与えるqubitの組みを列ラベルと考えれば、Hadamard行列の該当要素の符号が(マイナス1に対してのdot productの冪乗で)直ちに計算できるのである。むしろ、Fig.4でのテンソル積の右側に出現する項の符号は、このHadamard行列から決められるのである。ここに、Kronecker products of Hadamard matricesの重要性がある。
まとめ
 Prof. Bernhardtは [1]の中で、このSimon's algorithmにダブルスター⭐️⭐️(かなり難しい)を付している。確かにその通りだが、何度か読み返して検討して、上記のように理解できた。確率振幅の増幅と減衰に関しては、Groverのアルゴリズムではその操作を明示的に行なってるが、Simonでは「知らぬ間にそうなっている」感がある。ともかく、以下の文言を言えれば、Simonアルゴリズムは一応理解できたことになるのではないか。Fig.7参照。
「Simonの量子回路での全ての測定結果(行ラベル)について、秘密sでペアとなるbinary string(列ラベル)が示すHadamard行列の要素の符号は互いに一致する」
 Simonのアルゴリズムは、有名なShorの因数分解アルゴリズムに影響を与えたことが[1]に具体的に説明されている。その叙述から、Shor's algorithmの"こころ"をつかむことができると思う。ただし、もちろん、その詳細を知るには、量子フーリエ変換などの進んだ数学が必要になるので、改めてじっくり取り組みたいと思う。

 Reference
 [1] Chris Bernhardt: Quantum Computing for Everyone, The MIT Press, 2020.

2023年9月20日水曜日

生成AIに関するMIT App Inventor Workshopが神奈川工科大学で開催

 MIT App Inventorでは、いち早くChatBotImageBotなどの生成AIを組み込んで、生徒、学生、一般人が利用できる環境を提供している。それに関するワークショップが、日本では初めて、神奈川工科大学で5日間(2023/9/6〜12)に渡り開催された。生成AIのうちでも、自然言語からアプリを生成するAptlyは、まだ研究開発中のものであるが、今回(このようなワークショップとしては)初めて、受講生が試用できるよう設定していただいた。
 MIT AppInventorチームのソフトウェア開発者であるDavid Kimさん(in person)とAngie Zhouさん(online)が講師となり、情報、生命、電気、機械など多様な分野の学生が多数、熱心に受講した。最終日には、受講生が各自のアイディアをApp Inventorで実現したプレゼンも行われた。

 最終日の冒頭、MITの著名なComputer Science教授で、App Inventor創始者であるProf. Hal Abelsonから、受講生を激励するメッセージをライブ出演でいただいた。さらに同チームのDr. Evan Patton、Jeff Frilich、Dr. Natalie Laoの3名の専門家からも同様に貴重なメッセージがあった。これは、MIT App Inventorチーム全体として、本Workshopに強い関心を持って対応していただいた証であり、特筆すべきことであった。

 講師のDavidさんのTweetはこちらにあります。また、MIT App Inventor Facebookにも同様の投稿があります。神奈川工科大学の日本語ニュース英語版ニュースにもこのWorkshopの模様が載っています。

 このワークショップの詳細レポート(8ページ)は、ここには掲載していないが、特にご関心のある方はご連絡いただきたく。

MIT App Inventor Generative AI workshop at 神奈川工科大学

2023年9月8日金曜日

量子ビットの反転エラーの訂正(Quantum Bit-Flip Correction)

 量子テレポーテーションを利用した量子ビットのbit-flipエラー訂正については、下記に詳しく述べた。

 その際は、量子ビット反転エラーの検出(どのビットが反転したのかの)量子回路を説明した。だが、訂正の仕方は説明しただけで、その回路は示していなかった。今回は主にそれを説明する。エラー検出とその訂正の原理については上記URLを参照いただきたく、本記事では省略する。量子回路シミュレータQiskitのComposerを使って検討した。

AliceからBobへ転送する量子ビットの状態
 量子テレポーテーションの場合と同じく、物理的に量子ビットを送信するのではなく、その状態を転送するのである。その途中でエラー(ここではbit-flipに限る)が発生した場合、それを検出し、かつそれを自動的に訂正したい。

 まず、図1にAliceから転送したい量子ビット状態を示す。ここでは一例として、(a)のように、|0>にRYとRZゲートを適用した。エラーの検出は、古典ビットの世界で使われるパリティチェックに基づく。そのために元の量子ビットの複製を2つ作りたいのだが、それは量子複製不可定理により、できない。そこで、(b)に示すように、ancillaビットを2つ用意して、entangledな状態を作る。それをBobへ送り出す。もしも、途中でbit-flipエラーが発生しなければ、Bobは、0.75|000> + 0.25|111>という重ね合わせ状態を、そのまま受け取るはずである。

bit-flipエラーの訂正(ancillaビットの測定による)
 エラーの検出方法は、上記の如くすでに述べたので略す。発生したエラーを訂正する回路を図2の赤枠に示す。ここでは、上に述べた2つのancillaビットの測定を行い、その結果に基づいて、該当する量子ビットをパウリXゲートで反転させ、元通りしている。
 この例では、2番目のancillaビットq[2]がbit-flipを起こしたとした。それが正しく訂正されていることは、図1に示した元の3量子ビットシステムの状態が、図2の実行結果として、そのまま保たれていることから分かる。他のq[0]とq[1]に発生するエラーも同様に訂正される。

bit-flipエラーの訂正(Toffoliゲートの利用)
 上記のように、明示的にancillaビットを測定せずに、エラー訂正することもできる。図3に示すように、CNOTとCCNOTを組み合わせている。CCNOTはToffoliゲートとも呼ばれる。Toffoliは2つの制御ビットが共に|1>の時だけNOTが働く。どんな時に使うのだろうかと思っていたが、今回がその好例となったので記録しておきたい。

古典ビットレジスタと量子ビット状態ベクトルを表す円盤
 上の図2では、古典ビットレジスタに測定結果を格納したが、初めての人にはその使い方が分かりにくい。そこで、図4に要点をまとめた。
 また、右端にある円盤は、測定結果が|1>となる確率(青部面積)とPhase angleを示す。さらに、実線の円はentanglementの有無を意味する。これによれば、送信された3量子ビットはentangledの状態が維持されているが、2つのancillaビットとはもつれ関係がない。それゆえに、このentanglementに影響を与えずに、ancillaビットを測定できるのである。
 図5は、エラーが起こってもそれが訂正され、Aliceの送信時の量子状態ベクトルがそのままBobに伝わったことを説明している。
bit-flipイメージ(Bing)

Qiskit Quantum Labの Noise Modelの利用
 ここまでは、[1]に基づき、Bit-Flipエラーを起こしたいqubitの後ろに、Xゲートを置いてエラーを起こし、テストを行った。だが、Qiskit Quantum Labでプログラミングする場合は、NoiseModelクラス利用して、柔軟に、確率的にエラーを発生させることもできる。もっと複雑な量子回路でのエラー発生の影響を調べるのに有用であろう。その具体的な利用法は、[2]や[3]に掲載されている。また、[2]には、bit-flipの他にphase-flipも説明されていて参考になる。

参考文献
[1] Chris Bernhardt: Quantum Computing for Everyone, The MIT Press, 2020.
https://www.chrisbernhardt.info/
[2] 束野仁政, 量子コンピュータの頭の中、技術評論社、2023年6月
[3] J. L. Weaver & F. J. Harkins, Qiskit Pocket Guide, O'Reilly, 2022-06-15.

-----------
Private Info
Qiskit: Composer files: ErrorCorrec1 & ErrorCorre2, 2023-09-08
Quantum Lab: Chris_Book/Bit_Flipxxxxxx.ipynb

2023年9月3日日曜日

量子テレポーテーションをQiskitでもやってみる

 量子テレポーテーションに関しては、これまでに何度か記事を書きました。例えば次のようなものです:
 これらの記事では、主に量子回路シミュレータQniを使って、説明してきました。内容はほぼ同じなのですが、今回は、Qiskitを使ってみました。新たに分かったこともあるので、記録しておきたいと思った次第です。
地球と月の間の量子テレポーテーション

量子ビットと古典ビットの並び順の相違
 これは(Qiskitに限らず)混乱しやすいので、改めて図1にまとめた。(本図は、私のオリジナル作品)まず、複数の量子ビットシステムのテンソル積での並び順であるが、量子回路図では、これを右側に起こして直立させたものになる。次に、これらの量子ビットの測定結果(古典ビット列)の並び順は、これを右側へ倒して水平にしたものと対応する。すなわち、テンソル積と古典ビット列では、上位と下位が逆転する。これは、慣例となっているので、注意する必要がある。図3にもこれが表れる。

量子テレポーテーションで転送したい量子ビット状態の設定
 任意の量子ビット状態を転送できるのだが、ここでは、一例として、図2に示す量子状態とする。すなわち、量子ビット|0>に対して、Y軸周りに60°回転、さらにZ軸周りに60°回転させた状態を設定した。
 QiskitではComposerとQuantum Labの2つが使える。どちらでも、量子状態ベクトルを表示できる。何か詳細な設定が必要であれば、上図のように、Quantum Labでコーディングすることができる。もちろん、次の図3と同じ量子回路図も、Quantum Labで書くこともできる。

量子テレポーテーションをQiskit Composerでシミュレートする
 さて、ここからが本論なのであるが、原理的なことはすでに上記ブログ記事に十分書いているので、重複する部分は省略する。図3は、図2で設定した量子ビット状態を、AlcieからBobへ転送する様子である。下段には、Aliceの測定結果としての古典2ビット情報の発生確率と、AliceとBobの3量子ビットシステムの確率振幅が表示されている。
 この図で最も重要な点は、Aliceの量子ビット状態①が、Bobの量子ビットに設定されることである。つまり、①と⑥は全く同一の状態である。しかし、①の状態はすでに消滅して⑦のようになっている。これは量子複製不可定理に則っていることなのである。

 すでに既報では、Aliceが②で測定を行う直前の状態は、4通りあり、それぞれ1/4の確率で発生することを示した。図下段の③からそのことが確認できる。これは、Composerが自動的に②の測定を1024回実行(shot)した結果なのである。つまり、測定結果の古典ビット列000、001、010、011の出現確率がそれぞれほぼ等しく、25%程度となっており、それらの合計は100%であることが実証された。なお、3ビットの並びの最上位は0となっているが、これは、Bobの量子ビットがこの時点では測定されていないことによる。また、②の測定の直前に、Aliceが自分の2量子ビットに逆Bell回路を適用していることにも注意する。

 最後に、右端の3量子ビットシステムの状態をみてみよう。この例では、②の測定結果が10であり、|q[2]>|1>|0>という状態になっている。測定結果によらず、q[2]の状態は必ず⑥(すなわち①)となる。そうなるように、Bobによる④の操作(制御付き量子ゲート)が設定されているのである。q[2]が|1>となる確率が0.25(|0>となる確率は0.75)であることは図2に示したので、⑤の確率振幅の分布は納得できるであろう。

Qiskit Composerのその他の機能
 図3の②での一回の測定結果として、特定の2ビットパタンが必要な場合は、図4上部のVisualizations seedを変更して試すことができる。また、図中の量子ビット状態を示す円盤には、量子ビットのpurity(量子もつれの有無)を示す情報も含まれるので、量子回路の検証に利用することができるだろう。