2024年1月13日土曜日

Running quantum Fourier transform on my mobile simulator

I have developed a 3-qubit quantum circuit simulator that runs on a mobile phone. As shown in the top row of Fig. 1, a large number of basic quantum gates can be used. This time, I was able to demonstrate quantum Fourier transform (QFT) and inverse quantum Fourier transform (IQFT) using these quantum gates. QFT and IQFT each consist of six quantum gates, which are registered to buttons.

In Fig1.(a), when the button QFT is pressed for the quantum bit state |101>, a wave with the phase shown at the bottom is generated. Next, in Fig2.(b), the original qubit state could be restored by pressing the button IQFT. This means that we were able to determine the periodicity of the waves, as shown in Fig.2.

As mentioned above, QFT and IQFT were constructed by combining individual quantum gates, but alternatively, a unitary matrix can be used as shown in Fig. 3. I won't go into details, but these unitary matrices are actually built into my simulator. Note that when using this method, it was necessary to perform swap processing according to the simulator's policy. Swap means reversing the direction in which three qubits are arranged.

2024年1月10日水曜日

スマホのアプリで量子フーリエ変換をデモする

要旨:スマホ1台で稼働する量子回路シミュレータを開発している。現在、3-Qubitまでのアプリを動かすことができる。今回、これを用いて、量子フーリエ変換(QFT)、及びその逆変換(IQFT)の簡単なデモを実現できた。

●量子フーリエ変換(隠れた周期性の発見)
 ショアの因数分解アルゴリズムなどで重要な量子フーリエ変換(QFT)は、量子計算の代表例の一つである。QFTは、ある量子状態を入力すると、それに応じた周期性を有する量子状態(位相変化の波)を作り出す。また、逆量子フーリエ変換(IQFT)は、周期性を有する量子状態の隠れた周期を見つけることができる。

 ここでは、既存のシミュレータでQFTとIQFTを試すのではなく、量子回路シミュレータ自体をスマホ上に独自に構築した上で、QFTとIQFTを実験することに意義がある。そのため、以下の図にあるように、かなり多くの量子ゲートを実装することになった。

 IQFTでは、QFTを構成する量子ゲートを逆順に適用して行けば良いのであるが、実はその際、位相の回転方向を逆向き変更する必要があり、これが理由で実装量子ゲートが増えた面もある。

●QFTとIQFTの実行例
 詳しいことは略すが、実行例をいくつか示す。図1は、3量子ビットの状態ベクトル|100>を量子フーリエ変換に入力した場合である。

(注)本質的なことではないが、回路図上の量子ビットは上から下へ、q0q1q2と並んでいるが、図の下方にある円盤に付した状態ベクトルでは、慣例上、量子ビットは左から右へ、q2q1q0の順になっている。これ以降、状態ベクトルはこの「慣例」で表現する。

 図1では、(a)に示した量子ビット状態|100>を入力としてQFTを実行すると、(b)に示すような位相の波が得られた。すなわち、基底ベクトル|000>、|001>、... |111>の順に、位相が反時計回りに45度づつ変化し、8個の基底ベクトルで1周期の位相の波となる。
 続けて、IQFTを適用した結果を図2に示す。結果として、確率100%(円盤が全面塗り潰し)で|100>が測定された。これは元の入力そのものであり、回路図に戻って考えると古典ビットで"001"を得たことになる。すなわち、"1"周期の波であることが分かる。
 同様にして、入力量子状態|010>をQFTに与えると、今度は、2周期の位相の波(半時計周りに90度づつ進む)となり、さらにIQFTを実行すると元の入力量子状態が復元された。
 さらにもう一例、入力量子状態|001>をQFTに与えると、今度は、4周期の位相の波(半時計周りに180度づつ進む)となり、さらにIQFTを実行すると元の入力量子状態が復元された。
 図5に、逆量子フーリエ変換で位相の周期が分かる様子を再度掲載した。
●感想
 スマホで、電卓みたいな感覚で、簡単な量子回路シミュレータを作ろうとして始めたが、段々膨らんできて、3量子ビットの量子フーリエ変換ができるまでになった。まだまだ、初級レベルに留まるが、ちょっと嬉しくなる。ただ、スマホでは(性能上というよりも、画面設計やコード作成する上で)この位の規模が限界かもしれない。さらに高度なことは、QiskitやIBM Quantumで実行ということになろう。

 本記事内容を何かに生かすとしたら... 簡単なゲームが考えられる。3量子ビットで、何らかの周期性をもつビット列をプレイヤーに与えて、その周期を当ててもらう。あまり面白くないか。でも、量子アプリ作成の練習にはなるだろう。

 本記事内容を、整数の素因数分解に結びつけることは(たとえ15など小さな整数でも)非常に困難です。これを実現する量子回路を構成するには、より多くの知識と技術が必要です。私はまだその域に達していないようだ。特に、モジュラー指数関数を量子回路で実現する部分などです。

2024年1月7日日曜日

Yet another mobile quantum circuit simulator

In the previous article, I described the development of a quantum circuit simulator that allocates one qubit to one mobile phone. I also placed emphasis on graphical interfaces, including display on the Bloch sphere. This time, I have developed a new quantum circuit simulator that can run applications using three-qubit on a single mobile phone.

Simulate quantum circuits with a mobile phone that fits in the palm of your hand!
Without internet connection!
It's as fun as using a scientific calculator!

As shown in the figure below, I used this to implement Grover's algorithm. The same results were obtained with the IBM Quantum Computer, which had already been carried out.




Acknowledgment
In developing this quantum circuit simulator, the explanations and examples in the following reference [1] were very helpful to me.

References
[1]中山茂、"量子アプリQni量子プログラミング初歩",Gaia教育シリーズ52, 2022.

2024年1月2日火曜日

Happy New Year!

Happy New Year!

Naturally, I also replaced the planner (手帳 in Japanese) I use every year for the new year.

I want to get through this year somehow!

This year is the year of the dragon (辰年)

2023年12月25日月曜日

Try Deutsch's and Grover's algorithms in my quantum circuit simulator

I wrote about the quantum circuit application (simulator) that I created using three mobile phones in previous articles. This time, I confirmed that Deutsch's and Grover's algorithms work correctly with this simulator. Note that in the diagram below, Alice's qubit (q0) and Bob's qubit (q1) are assigned to different mobile phones. The effects of each quantum gate are sent via CloudBD to a mobile phone for control.

●Deutsch's algorithm

Many explanations regarding this have already been published, so I will omit the details. The Deutsch algorithm determines whether a function whose inputs are all 0 or 1 and whose function value also takes 0 or 1 is a constant function or a balanced function. Its feature is that by creating a special mechanism called Oracle, the judgment can be made with only one function evaluation.

Fig.1 and Fig.2 show that the Deutsch algorithm works correctly when the input is one variable using my quantum circuit simulator.

●Grover's algorithm

Grover's algorithm searches for specific data in an unstructured data set. In the first stage of this algorithm, the data to be searched is first marked. In a quantum bit system, this means inverting the phase of the probability amplitude of the corresponding basis vector. This is achieved by creating a circuit called Oracle, just as in the case of Deutsch. Next, in the subsequent stage, a quantum circuit for amplifying the probability amplitude is assembled and executed. As a result, only the probability of the corresponding basis vector becomes 100%, so a search result can be obtained.

Figures 3 to 6 show that, using my quantum circuit simulator, the Grover algorithm works correctly in the case of classical 2-bit information (4 pieces of data) and obtains the desired results.

2023年12月19日火曜日

Superdense coding using my mobile quantum simulator

Japanese abstract
前のポストにおいて、2量子ビットシステムを3台のモバイルフォンで探究するためのアプリ(量子回路シミュレータ)を開発した。今回これを利用して、Superdense codingを実装してみた。Superdense codingは、少ない量子ビットを送ることでたくさんの古典ビット情報を送ることができるアルゴリズムである。このアルゴリズムは、量子重ね合わせと量子もつれを巧みに利用しており、これによって、私の開発したモバイルフォンアプリが正しく動作することを確認できた。

English abstract
In the previous post, I developed an app (quantum circuit simulator) to explore a two-qubit system using three mobile phones. This time I used this to implement Superdense coding. Superdense coding is an algorithm that can send many classical bits of information by sending fewer qubits. This algorithm makes clever use of quantum superposition and entanglement, and I was able to confirm that the mobile phone app I developed worked correctly. 

●Superdense coding that sends classical 2-bit information with 1 qubit
Here, we will deal with Superdense coding, which allows you to send classical 2-bit information (any of 00, 01, 10, 11) by just sending one qubit. The details of the theory are carefully described in reference [1]. I implemented this algorithm with reference to that description. This will be explained specifically using Fig.1 and Fig.2.

Fig.1 shows the preparation phase. In the left column of Fig.1, Alice and Bob each have one qubit. Each is assigned to one mobile phone. The various quantum gates shown in the figure can be applied to freely change the qubit state. Here, (1) Alice applies Hadamard gate H to the initial state |0> to create a superposition state. On the other hand, (2) Bob applied the Pauli X gate to the initial state |1> and changed the state to |0>. These quantum states are transmitted to the control mobile phone on the right side via the real-time database CloudBD. Then, (3) tensor product is calculated to consider these two qubits as one system. Next, (4) Applying the CNOT gate creates a quantum entangled state. In other words, notice that the ”Entangled?” label has changed from false to true.

In Fig.2, (5)Alice applies  Pauli gate Y. As we will see later, applying this Y gate actually means selecting the classical 2-bit information "11". It then sends this qubit to Bob. On the other hand, at this point,  (6) Bob does not take any new action. The control mobile device on the right side of the figure (7)updates the tensor product to reflect Alice's application of the Y gate, but the entangled state is maintained. At this point, Bob will have a total of two qubits: the qubit sent by Alice and the qubit he originally had. Next, Bob has the control mobile device (8)apply the reverse Bell circuit. As a result, the quantum entanglement disappears ("Entangled?" false), and the probability of the basis vector |11> becomes 100%. In other words, if Bob makes a measurement here, he will get the classical bit information "11".

The most important point here is that Bob has no idea what Alice sent him before taking the measurements. Nevertheless, no matter which classical 2-bit information Alice sends, Bob can always simply apply the reverse Bell circuit. That way, Bob can get the information that Alice sent! This is the great thing about Superdense coding.

When sending classical bit information other than "11", it is shown in Fig.3. If Alice would like to send "00", she applies the I gate (no action). If she sends "01" she applies the X gate, and if she sends "10" she applies the Z gate. In any of these cases, as mentioned above, Bob only needs to perform the measurement after applying the reverse Bell circuit.

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

2023年12月15日金曜日

Quantum entanglement experiment using multiple mobile phones

Japanese abstract
今回は、量子コンピューティングで最も神秘的な原理である「量子もつれ」を、自作モバイルアプリで探究する。その特徴は、1量子ビットを1台のモバイルフォンに割り当て、2つの量子間のもつれ関係を、(リアルタイム性を持つ)クラウドデータベースを経由して作り出すことである。遠く離れた2台のモバイルフォン間でこれを実験することにより、遠隔量子間のもつれ現象を模倣し、理解を深めることができる。これこそが、このアプリを開発した理由なのである。このような高度な機能の実現を容易にしてくれるMIT App Inventorに改めて感謝したい!

English abstract
I would like to explore the most mysterious principle in quantum computing, "quantum entanglement", using a mobile app I created. Its major feature is that one qubit (quantum bit) is assigned to one mobile phone, and the entanglement relationship between two qubits is created via a cloud database (with real-time capabilities). By experimenting with this between two mobile phones far apart, it is possible to mimic and better understand the phenomenon of entanglement between remote quanta. That is the reason why I developed this app. Thanks again to MIT App Inventor for making it easy to achieve such advanced functionality!

●Manipulate a single qubit
In a previous post, I described a mobile application for a single qubit. Even when limited to a single qubit, it is possible to create any quantum state using various quantum gates. Using this app, we were able to learn the basics of quantum superposition and measurement. However, to handle the most mysterious and important principle of quantum entanglement, we need at least two qubits. So, what method should we use to handle more than two qubits in mobile apps? This will be explained below.

●Explore quantum entanglement by assigning one qubit to one mobile phone
The new app targets a two-qubit system, with one qubit assigned to one mobile phone. Perhaps this method will reduce the complexity of the app. To mimic quantum entanglement, we need to consider multiple qubits as a system, rather than looking at each one individually. To do this, I decided to use another mobile phone to calculate the tensor product of all qubits. The measurement result of one quantum bit in an entangled state automatically and instantly changes the state of the other quantum bit. The real-time Cloud DB included in MIT App Inventor was useful in achieving this.

●Experimental example of quantum entanglement

(1)IBM Quantum Composer
Let's take the most basic quantum entanglement as an example. Fig.1 shows the case using IBM Quantum Composer. Prepare two qubits q0 and q1. First, apply the Hadamard gate H to q0 to create a superposition state, and leave q1 in its initial state (|0⟩). At this stage, q0 has no relationship with q1.
Next, if we apply a CNOT(0,1) gate to two qubits (control bit is q0, target bit is q1), both become entangled. Then, for example, when q0 is measured, the states of q0 and q1 will be either 00 or 11. In other words, the measurement result of q0 is immediately reflected in q1. This is quantum entanglement.

The mathematical model for this example problem is explained in detail in reference [1].

(2) Mimic quantum entanglement with three mobile phones
What was done with IBM Quantum was achieved with three mobile phones. As shown in Fig. 2(a), quantum bits qubit_0 and qubit_1 are each assigned to one mobile phone, and the third mobile phone performs control. Hadamard Gate H has already been applied to qubit_0. Once the quantum states (probability amplitudes) of qubit_0 and qubit_1 are stored in CloudDB, the third mobile phone calculates the tensor product to treat the two qubits as one system. As a result, four disks (corresponding to the four basis vectors) are displayed, and the probabilities and phases are shown. Fig.2(b) shows the actual screens of the three mobile phones on which this was performed.
The third mobile phone then applies the CNOT(0,1) gate to these two qubits. This creates a quantum entangled state as shown in Fig. 3(a). Fig.3(b) shows the actual screens of the three mobile phones at this time.
Once entangled in this way, the two mobile phones set up their Cloud DBs so that they can sense when the other has taken a measurement. As shown in Fig. 4(a), when it senses the other party's measurement, it immediately changes its own state based on the already stored quantum entanglement information. Fig.4(b) is the actual screen at that time.
(Note) This example is an entanglement in which two qubits are in the Bell state. In entanglement cases other than the Bell state, the measurement result of one does not necessarily definitively determine the other state. It depends on the nature of Entanglement at that time. Quantum entanglement generally refers to a correlation, but its strength varies.

●Summary
By developing an application that mimics quantum entanglement, I have gained a deeper understanding of the meaning of the tensor product of multiple qubits and the phenomenon of quantum entanglement. This time, I used CNOT(0,1), but you can also use CNOT(1,0) with the control bit and target bit reversed. Additionally, other gates can be combined to create quantum entanglement.

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

2023年12月5日火曜日

Final version of my single-qubit apps

I recently completed the final versions of two apps for single-qubit manipulation!

These apps were developed in a short period of time using MIT App Inventor. Although many existing blocks could be used effectively, some ingenuity was required to represent the qubit states on the Bloch sphere. The problem was to project 3D coordinate data (x, y, z) onto a 2-dimensional plane, and I was able to solve this problem by using the isometric projection method.

(1) Displaying the results of successive application of quantum gates
Five types of quantum gates (Z, X, Y, H, T) can be used. The figure below (b) shows the result of successively applying H, T, and H to the quantum bit |0>. The final qubit state is shown as a big red dot on the Bloch sphere on the left. Small disks are also shown to the right. The area of the filled disk indicates the probability of each basis (|0>, |1>). A straight line coming out from the center of the circle indicates the phase. At the bottom of the Bloch sphere, some numerical values indicating quantum states are also shown.

(2) Conversion to make the phase of α 0 in qubit α|0>+β|1>
In order to represent a quantum bit on a Bloch sphere, the phase of α needs to be 0, and the phase of β needs to be the relative phase (φ) to it. The app shown below achieves this functionality. This is also a transformation that makes the imaginary part of the complex number α 0. Figure (b) below confirms that this conversion function is working correctly.

2023年12月2日土曜日

Dynamic representation of qubit for arbitrary θ and Φ

The static Bloch sphere model image is good, but it would be even better if we could dynamically represent the quantum bit state for arbitrary θ and Φ values !

I made this possible with a smartphone app! 

Generally speaking, it is somewhat difficult to create a 3D representation using MIT App Inventor, but it was relatively easy to map points on a Bloch sphere with a radius of 1 onto a 2D plane using Isometric projection.
Also check out the short video in action below.


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.