ラベル Quantum Bit-Flip Correction の投稿を表示しています。 すべての投稿を表示
ラベル Quantum Bit-Flip Correction の投稿を表示しています。 すべての投稿を表示

2024年8月19日月曜日

Redesigned Mobile Quantum Circuit Simulators

Abstract: I have developed several quantum circuit simulator apps that run on mobile phones. Although my apps are not as good as well-known simulators such as Qiskit and Quirk, they are suitable for taking your mobile phone out of your pocket and learning the basics of quantum computing anytime, anywhere. No Internet connection is required. Until now, my simulators were for up to 3 qubits, but this time, I have made major design changes to enable it to handle any n qubits. (However, due to resource constraints on mobile phones, in reality, I am mainly assuming use of about 6 qubits.) These make it possible to run a large number of examples that are published in general quantum computing textbooks. These apps are currently unreleased, but I will provide them (.apk files for Android) immediately to anyone who is willing to try. Please contact me. (You can find my email address in the header of my blog.)

The app URL has changed, please contact me if you need it.

(▶️Please see the revised version V2 information here)

🔴Check out the introductory video for this simulator here!

🔴Two types of mobile phone apps developed

The following two quantum circuit simulators were developed.

(1) Simulator for n-qubit (app name: nQsim_9)

A new circuit description format similar to IBM's QASM was introduced. I also considered a GUI method in which qubits and quantum gates are set with buttons, but due to the limitations of mobile phone screen size and operability, I ultimately decided on a method in which quantum circuits are described in text. Fortunately, the description of quantum gates is very simple, and the number of qubits required for general learning is not very large, so I thought that there would be no major problems with this method. Rather, this method of creating a quantum circuit diagram by hand and writing (typing) quantum gates while looking at it would be more likely to deepen understanding.

(2) Simulator for one quantum bit (app name: sQ_b2)

This is an app specialized for one quantum bit, and the quantum state when various quantum gates are applied is graphically displayed on a disk-like image. The quantum bit state is also displayed on the Bloch sphere, which is useful for deepening understanding.


How to use the n-qubit simulator

(1) Overview of the simulator

See Fig.1 for an overview of this app. The user describes the quantum circuit in text format. For concrete examples, please refer to the built-in examples.

  • Specify the number of qubits to be used and the quantum bits to be measured.
  • Available quantum gates are I, X, Y, Z, H, T, S, √X , P, RX, RY, RZ, and SWAP.
    (CNOT should be represented by X with control.) 
  • (The next version will also include the following gates: T_dagger, S_dagger, QFT, IQFT)
  • The phase (angle) should be given in radians. The number π is specified as "pi".
  • Any quantum gate can be equipped with necessary number of control bits. (However, SWAP is excluded because it has a different description format.)
    [example] X, 2, [0, 1]  <- apply X to q2 controlled by q0 and q1
    [example] RY(pi/3), 2  <- apply RY with angle π/3 to q2 
    [example] SWAP, state, 2, 3  <- swap q2 and q3
  • Only one quantum gate can be specified per line. (->In the next version, this restriction will likely be removed.)
  • Lines containing "//" are considered comment lines.
  • Blank lines are not allowed. (->In the next version, this restriction will likely be removed.)
  • Measurements are automatically performed on the specified qubits at the end. (If you do not want to perform a measurement, set the list of qubits to be measured to a null list.)
  • Newly added quantum gates based on measurement results, can also be executed.
  • The described quantum circuits can be saved and retrieved. (However, the current version only supports two circuits.)
  • Six simple quantum circuit examples are built in. Namely, Toffoli, GHZ, QFT, 7k%15, Grover's Algorithm, and Error correction (bit-flip).

(2) Example: Bit-Flip Error Correction

This example is an application of quantum teleportation and is considered important, so the details are shown in Fig. 2. First, click ① to import the example circuit. In this example, 5-qubit is used, and a bit-flip error occurs in quantum bit q2. When the Go button is clicked in ②, a measurement result reflecting the error, that is, (q4q3=10) is obtained. Based on this result, in ③, a new quantum gate for error correction is provided. Next, when Go After Meas. button is clicked in ④, a new quantum state shown in ⑤ is obtained. Here, the error has certainly been corrected !

In this example, the following point is worth noting: namely, since the bottom two qubits (q3 and q4) are not entangled with the top three, measurements on the bottom two qubits make them collapsed, but will leave the top three unchanged. 

[Note]  When you use the "Go after meas" button, do not long-click the "clear" button. Doing so will cause the current quantum state to be completely lost. To clear the circuit description area, simply click the "clear" button.

(3) Other quantum circuit examples

Five examples other than the error correction above are shown in Fig. 3 to Fig. 5 for your reference. In the Fig.3, Grover's algorithm is demonstrated. The left hand side figure (a) shows flipping the phase of the target basis |01⟩ via the oracle. Then, amplitude amplification (b) is applied, and finally we can see the answer |01⟩.

In Fig.4(a), the GHZ circuit is illustrated which gives strong entanglement. A demonstration of applying QFT (Quantum Fourier Transform) is given in Fig.4(b).
Toffoli gate is applied in Fig.5(a) and SWAP gate is applied in Fig.5(b) to perform a modulo calculation.

[Notice 1] In the current version, error checking is not performed on the circuit description. If any strange results are obtained, please refer to the circuit description in the above example and review it. Also, the function to import handwritten circuit diagrams displayed to the right of the circuit is not supported.

[Notice 2] By using MIT App Inventor again, I was able to achieve significant efficiency in app development. The 1-qubit version of the simulator was developed using only App Inventor. The overall control and graphical parts of the n-qubit version were also developed using App Inventor, but most of the quantum state calculations (such as unitary matrix operations with complex coefficients) were created in Javascript (about 350 lines). The WebViewer function of App Inventor allowed us to call up the Javascript program smoothly.



How to use the single-qubit simulator

This is a graphical representation of operations on a single qubit using a disk and a Bloch sphere. In Fig. 6, a quantum state is set on the Bloch sphere using two sliders (θ and φ). In Fig. 7, the quantum state is changed using various quantum gates. Small disks on the right side of the Bloch sphere show the change in state before and after the application of the quantum gate. No detailed explanation might be necessary. Please try it out for yourself !

 

🔴 Other apps you might be interested in

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