ラベル Grover's algorithm の投稿を表示しています。 すべての投稿を表示
ラベル Grover's algorithm の投稿を表示しています。 すべての投稿を表示

2024年1月23日火曜日

Development of scientific calculator-like quantum circuit simulator V2

(This is an English translation of a previous Japanese article)

I have been developing a quantum circuit simulator that is as easy to use as a scientific calculator. As a single smartphone app, you can try out various quantum algorithms and apps within the 3-qubit range. This time, version 2 has been completed. I also added a little bit of play.

If you shake your smartphone lightly, one of five icons will randomly appear. It's a little fun. Of the five images, one was created by me, while the other four were created by ChatGPT.
Of course, this is not the only thing. Added a playback function that applies quantum gates. That is, by recording the steps of an algorithm (which quantum gates were applied to which registers (qubits)) in sequence, and pressing one or two buttons, the algorithm can be played back. I found this to be very useful when showing a demo to someone or when running under different conditions myself. Although details are omitted, three algorithm playback examples recorded in this manner are shown below.

●Superdense Coding
In Fig.1, Alice has the top two qubits (q0 and q1), and Bob has q2. Both qubits are in a state of quantum entanglement. Just like that, Bob went away. Alice wants to send any of the classical 3-bit information (000, 001, 010, ..., 111) to Bob. In other words, she wants to send "101" out of eight, for example, in (a). However, there are only two qubits that can be sent. This is not enough!
Nevertheless, with this wonderful Superdense Coding, Bob can always obtain any information from Alice simply by operating a predetermined quantum gate! Fig.1(b) shows this.
●Grover's Algorithm
For example, assume that eight pieces of information (000, 001, ..., 111) are arranged randomly. The problem is finding specific information from among them. Fig.2 is an example of searching for "101". First, mark the information in (a). This is achieved by inverting the phase of the corresponding basis vector |101>. This is not a scam! It simply tells you what to look for. Without such information, the search itself is meaningless.
In (b), when the button Amp3step is pressed, the probability amplitude amplification is activated, and only the probability amplitude of the basis vector whose phase was inverted in (a) is amplified, and the desired information "101" is obtained. In this example, we only needed to perform the phase inversion and amplification pair once!
●Quantum Fourier Transform
This is an application example of quantum Fourier transform QFT. One of the characteristics of QFT is that it can be applied to states of quantum superposition. In Fig.3(a), we created a superposition of two certain quantum states. Next, in (b), when the button QFT is pressed, the phase waves that are the results of each QFT in both states interfere and appear as separate phase waves. The wave swell can be seen from the phase angle and amplitude (area of the disk filled in red) in the lower part of (b).
Although omitted here, you can restore the original quantum superposition state by pressing the button next to it, IQFT. IQFT is the inverse quantum Fourier transform.

2024年1月21日日曜日

関数電卓型の量子回路シミュレータV2

 関数電卓のような使い勝手の量子回路シミュレータを目指し、独自に開発を進めてきた。1台のスマホのアプリとして、3-qubitの範囲で、種々の量子アルゴリズムやアプリをこれで試すことができる。今回、バージョン2を完成させた。遊びもちょっと入れてみた。
 スマホを軽く振れば、4つのアイコンのいずれかがランダムに現れる。ちょっと楽しい。4つのイメージのうち、1つは自作したが、他の3つはChatGPT氏によるものである。

 もちろん、これだけではない。目玉は、量子ゲート適用の再生機能を追加したことだ。すなわち、あるアルゴリズムの手順(どのレジスタ(量子ビット)にどの量子ゲート適用したか)を順に記録して、ボタン1つか2つを押すと、そのアルゴリズムが再生できる。これは、人にデモを見せたり、自分でも条件を変えて実行する場合に非常に便利であることが分かった。詳細は略すが、そのようにして記録した3つのアルゴリズム再生例を以下に示した。

●Superdense Coding(超高密度符号化)
 Fig.1において、Aliceは上段の2つのqubit(q0とq1)を持ち、Bobは下段のq2を保有する。両者のqubitは量子もつれの状態にしてある。その後、Bobは遠方へ行ってしまった。もつれは保持されたままである。Aliceは古典3ビット情報(000, 001, 010, ... , 111)のどれかをBobに送りたい。つまり、8個のうちから、例えば、(a)では"101"を送たい。だが、送れるqubitは2つしかない。これでは足りない!
 それにも拘らず、この素晴らしいSuperdense Codingでは、Bobは常に予め決められた量子ゲートを操作するだけで、Aliceからのどの情報でも得られる!(b)はそれを示している。
●Grover's Algorithm(グローバーの探索アルゴリズム)
 これは、例えば、8個の情報(000, 001, ... , 111)がランダムに並んでいるとする。その中から特定の情報を探し当てる問題である。Fig.2は、"101"を探す例である。まず、(a)で、その情報に印をつける。それは、対応するbasis vector |101>の位相を反転させることで実現させている。これはイカサマではない!単に、何を探すべきかの情報を与えているだけである。そもそも、そのような情報がなければ、探すこと自体が意味をなさない。
 (b)において、ボタンAmp3stepを押すと、確率振幅増幅が作動して、(a)で位相反転したbasis vectorの確率振幅だけが増幅されて、求める情報"101"が得られた。この例では、位相反転と増幅のペアをただ1回実行するだけで解決した!
●Quantum Fourier Transform(量子フーリエ変換)
 これは、量子フーリエ変換QFTの適用例である。QFTの特徴の一つは、量子重ね合わせの状態に適用できることである。Fig.3(a)で、ある2つの量子状態の重ね合わせを作った。次に、(b)で、ボタンQFTを押すと、両方の状態のそれぞれのQFTの結果である位相の波が干渉して、別の位相波として現れる。(b)の下段の位相角度と振幅の大きさ(赤で塗り潰した円盤の面積)から、波のうねりが分かる。
 なお、ここでは省略したが、隣のボタンIQFTを押すと、元の量子重ね合わせ状態を復元できる。IQFTは、逆量子フーリエ変換である。

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年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