I am a professor emeritus of CS at Kanagawa Institute of Technology, Japan. Originally my specialty was parallel and distributed systems. My current interests include machine learning, natural language processing, creating mobile apps with MIT App Inventor, and quantum computing. In the web version of this blog, clicking the icon on the right (a plastic sphere) will take you to the "List of Quantum Computing Articles". - Fujio Yamamoto (for e-mail, add "@ieee.org" after "yamamotof")
2026年5月29日金曜日
IBM Quantumの教室アカウントの取得が可能に!
2026年5月26日火曜日
Standalone Quantum Circuit Simulators Running on Mobile Phones
Abstract
Full-featured quantum circuit simulators such as Qiskit and Cirq are widely used in the quantum computing community. However, I wanted a quantum circuit simulator that could be used like a pocket calculator—something I could quickly pull out anytime and anywhere, without requiring an internet connection. Several years ago, I developed the app described in [2] for this purpose. Using it, I was able to experiment with many of the basic examples commonly found in introductory quantum computing textbooks, and I still find it extremely useful today.
Recently, I discovered that a similar simulator is also available: the product developed by Codexus Technologies [1]. In this article, I briefly compare the two simulators through several example problems, focusing on usability and design philosophy. Exploring the ideas behind each simulator is both interesting and enjoyable.
🟢 Standalone Quantum Circuit Simulators
Both simulators run entirely on an Android smartphone without requiring any user configuration or internet connection. Like using a calculator, users can immediately experiment with basic quantum circuits whenever they wish. Their main features are summarized below.
• Codexus Technologies App [1]
The app features an attractive and polished user interface. A wide range of fundamental quantum gates is available, and circuits of up to five qubits can be simulated. Users build circuits graphically by placing gates through the GUI, so no text-based programming is required.
Simulation results are obtained from 1,024 measurement shots and displayed both as a histogram and as a textual state vector (probability amplitudes). The development environment used to create the application is not publicly known.
• Fujio Yamamoto's App [2]
This simulator consists of two versions: a single-qubit simulator and an n-qubit simulator. In the single-qubit version, users can apply quantum gates interactively through a graphical interface, and the state vector is visualized on a three-dimensional Bloch sphere. The n-qubit version accepts circuits in a text-based format similar to IBM's QASM language.
Simulation results are displayed both graphically (using a disk representation) and in textual form as state vectors. Created circuits can be saved with a button press and later reloaded for further editing. The application was developed efficiently using MIT App Inventor, although much of the complex-number arithmetic is implemented in embedded JavaScript code.
🟢 Comparing Usability Through Example Problems
The purpose of this comparison is not to determine which simulator is superior. Rather, it is to explore the design philosophy behind each application and understand how their creators approached the challenge of building a quantum circuit simulator. Examining these differences is both informative and enjoyable. Let us try the following three examples on each simulator.
(1) Applying X and H Gates Sequentially to a Single Qubit
In the Codexus app, as shown below, the interface is highly polished and intuitive. Users simply place quantum gates one after another. Pressing the "Simulate" button automatically performs 1,024 measurement shots and displays both the state vector and histogram, making the results easy to understand.
The Fujio app also applies quantum gates through a graphical user interface. Its most distinctive feature is the visualization of the state vector on a 3D Bloch sphere. The probability amplitudes are additionally displayed as complex numbers in the lower section of the screen.
(2) Creating a GHZ State with Three Qubits
In the Codexus app, the configuration of CNOT gates is particularly well designed. First, the user selects the control qubit. The simulator then highlights the candidate qubits where the target NOT gate can be placed, allowing the user to complete the operation simply by tapping the desired qubit. The simulation output correctly shows that only the states 000 and 111 occur, confirming the presence of quantum entanglement.
In the Fujio app, quantum gates are specified using a text-based description. Because the circuit can be edited directly, the approach offers a high degree of flexibility. In addition, several example circuits are built into the application, allowing users to load and execute them immediately with a single button press. Simulation results are displayed on a disk diagram showing both probabilities and phases, providing an intuitive and user-friendly representation.
(3) The Mermin–Peres Magic Square Using Four Qubits
This example is somewhat more sophisticated than the previous two. It demonstrates a remarkable form of quantum "magic" that makes clever use of entanglement. Readers interested in the details are referred to [3].
In the Codexus app, circuits containing many gates can still be configured conveniently by scrolling horizontally across the screen. The output correctly shows that only eight of the sixteen possible four-qubit basis states appear, each with approximately equal probability.
At this point, I do have one feature request: for circuits of this length, it would be very useful to save the circuit and reload it later for further editing. I hope this capability will be added in a future version.
As with the previous examples, the Fujio app represents the circuit textually. The simulation results are displayed on the right side of the figure, where the probability and phase associated with each basis state are shown graphically on a disk diagram. The results are easy to interpret and match those produced by the Codexus simulator exactly.
Some readers may notice a small difference. For example, Codexus reports an amplitude of −0.354 for 0001, whereas Fujio reports −0.354 for 1000. This discrepancy is simply due to a different ordering convention for qubit indices. In other words, it reflects the difference between the conventions commonly used by Google Cirq and IBM Quantum.
(4) Calculation of 7k mod 15 (where k=8)
This example appears as part of quantum phase estimation (QPE). Here, we have a simple example of "7k mod 15". We have confirmed that the answer is 11 when k=8.
In Codexus, this is implemented using swap gates. The simulation result shows that the probability amplitude of |1101> is 1.0. This means that the answer is 1011 in classical binary and 11 in decimal. The bit order is as explained in example (3).
Fujio's result needs no explanation.
(5) 4-qubit QFT without swap
This example is a quantum Fourier transform (QFT) using 4 qubits. Unfortunately, it seems that Control Phase, Control S, and Control T are not available in the Codexus app. Therefore, it was not possible to create a quantum circuit for the QFT.
On the other hand, in the Fujio app, the following result can be obtained using the Control Phase gate.
Subsequently, applying the inverse quantum Fourier transform IQFTx (lowercase x means no swap) was confirmed to return to the state before applying QFTx, |1111>, as shown in the following figure.
🟢 Conclusion
Both the Codexus app and the Fujio app have their own strengths and distinctive features. They are enjoyable, convenient, and easy to use. As standalone quantum circuit simulators that run directly on Android mobile phones, they provide an accessible way to explore the fundamentals of quantum computing.
Such tools could serve as valuable educational resources for introductory quantum computing courses at both the high school and university levels.
References
[1]Quantum Circuit Simulator by Codexus Technologies (Sri Lanka)
https://play.google.com/store/apps/details?id=com.codexustechnologies.quantumcircuitsimulator&hl=en-US
[2] Redesigned Mobile Quantum Circuit Simulators by Fujio Yamamoto
https://sparse-dense.blogspot.com/2024/08/redesigned-mobile-quantum-circuit.html
[3] Mermin-Peres Magic
Exploring Quantum Entanglement through Visualization
https://sparse-dense.blogspot.com/2025/05/exploring-quantum-entanglement-through.html
スマホで動くスタンドアロン型量子回路シミュレータ
【要旨】本格的な量子回路シミュレータとして、IBM QiskitやGoogle Cirqなど広く使われている。しかし、電卓のように、いつでもどこででも、さーっと取り出して、web接続も不要な量子回路シミュレータが欲しくて、数年前、[2]に示すアプリを自作した。これを使って、一般的な量子コンピューティングのテキストブックに出てくる基本的な例題の多くを試すことができた。今でも、重宝している。一方、最近になって、同様のシミュレータが他にもあることを知った。Codexus Technologiesの製品[1]である。今回、これら両者を、いくつかの例題を通して、使い勝手などを簡単に比較してみた。両者の設計思想を探るのは楽しいことである。
🟢スタンドアロン量子回路シミュレータ
いずれも、Androidモバイルフォン単体で動作するのである。ユーザによる環境設定や、Web接続は全く必要としないので、電卓を使うような感覚で、基本的な量子回路を動かすことができる。それぞれの特徴を簡単にあげる。
・Codexus Technologies のアプリ[1]
デザインが美しく、綺麗な画面である。基本的な量子ゲートの多くを使うことができる。量子回路の規模は5量子ビットまで。GUIでゲートを置いていく形式であり、テキストでのプログラミングは不要である。1024ショットのシミュレーションの結果を、ヒストグラムと state vector(確率振幅)をテキストで得ることができる。どのような開発環境で作成されたかは不明である。
・Fujio Yamamoto のアプリ[2]
1-qubit用とn-qubit用の2種類がある。1-qubit用は、GUIで各種の量子ゲートを連続的に適用でき、State vectorは、3Dブロッホ球に表示できる。n-qubit用は、IBMのQASMに近いテキスト形式で与える。シミュレーション結果は円盤形式とテキスト形式の両方で、State vectorとして示す。作成した回路は、ボタン操作で格納でき、あとで取り出して再編集できる。このアプリは、MIT App Inventorで効率良く作成されたものである。ただし、複素数演算の多くは、 JavaScriptでコーディングして組み込んでいる。
🟢例題による使い勝手の比較
この比較は、両者の優劣を論じるものではない。それぞれのアプリの作者がどのような設計思想を抱いて、そのシミュレータを作り上げたのかを探るのが主な目的である。それを調べることは楽しいことである。以下の3つの例題を、それぞれのシミュレータで実行してみよう!
(1)量子ゲートXとHを連続して1-qubitへ適用
Codexusアプリは、下図の通り、洗練されたデザインで、ポンポンと量子ゲートを並べれば良い。”simulate"ボタンを押すと、1024回ショットが自動的に実行され、State VectorとHistogramが表示され、わかりやすい。
Fujioアプリも、同様にGUIで量子ゲートを適用する。最大の特徴は、3Dブロッホ球にState vectorを表示することある。下部には、確率振幅も複素数で表示される。
(2)3-qubitを使ったGHZ
Codexusアプリでは、CNOTゲートの設定に工夫が見られる。まず、コントローラをどのqubitにするかを決める。すると、NOTゲートを置けるqubitの候補が示されるので、適当なqubitをクリックすれば良い。シミュレーション結果は、000と111だけが表示され、量子もつれを確認することができる。
Fujioアプリでは、量子ゲートの配置をテキストで与える。それを編集できるので、自由度は高い。また、いくつかの例題がすでに組み込まれているので、ボタンを押して、その量子回路をすぐに使える。シミュレーションの結果は、円盤に、確率と位相が表示されるので、親しみやすい。
(3)4-qubitを使ったMermin-Peres Magic
この例題は、ここまでの2つよりも若干複雑であり、量子もつれを巧みに利用したマジックである。詳細は[3]を参照されたい。
Codexusでは、画面を横方向にスクロールすることで、ゲート数が多くなってもうまく設定できる。出力は、4量子ビットのすべての組み合わせ16個のうちの、8個だけがほぼ同数出現するという正しい結果を示している。
ここで、一つ要望事項がある!このくらい長い回路になると、この結果をsaveして、後でそれを取り出して編集したい!次回のバージョンではそれを追加してほしい!
Fujioアプリでは、他の2つの例題と同じく、テキストで量子ゲートを配置している。右側のシミュレーション結果には、基底ごとの出現確率と位相が円盤に示されるので、分かりやすい。Codexusと全く同じ結果が得られている。
しかし、ちょっと違うことに気づく人もいるだろう!たとえば、Codexusでは、"0001のamplitudeが-0.354"となっているのに対して、Fujioでは、"1000のamplitudeが-0.354"となっている。これは単に、ビットの並べ順が異なるだけである。つまり、Google Cirq流かIBM Quantum流かの違いである。
(4)7k mod 15 (where k=8)の計算
この例題は、量子位相推定(QPE)の一部として出てくる。ここでは、"7k mod 15"という簡単な例である。k= 8の場合、答えは11であることを確認している。
Codexusでは、swapゲートでこれを実現している。シミュレーション結果は、|1101>の確率振幅が1.0となる。これは、答えが、古典2進で1011、10進で11であることを意味する。ビットの並び順に関しては、例題(3)で説明した通りである。
Fujioの結果については、説明は不要であろう。
(5)4-qubit QFT without swap
この例題は、4-qubitを使う量子フーリエ変換(QFT)である。残念ながら、Codexus appでは、Control Phaseや、Control S、Control Tが使えないようである。したがって、QFTの量子回路を作ることはできなかった。
一方、Fujio appでは、Control Phaseゲートを使って、以下の図のような結果を得ることができる。
🟢結 論
Codexusアプリも、Fujioアプリもそれぞれ特徴があり、楽しく、気軽に使える。高校、あるいは大学ででも、入門的な量子コンピューティングに活用できるのではないだろうか!
References
[1]Quantum Circuit Simulator by Codexus Technologies (Sri Lanka)
https://play.google.com/store/apps/details?id=com.codexustechnologies.quantumcircuitsimulator&hl=en-US
[2] Redesigned Mobile Quantum Circuit Simulators by Fujio Yamamoto
https://sparse-dense.blogspot.com/2024/08/redesigned-mobile-quantum-circuit.html
[3] Mermin-Peres Magic
Exploring Quantum Entanglement through Visualization
https://sparse-dense.blogspot.com/2025/05/exploring-quantum-entanglement-through.html
2026年5月24日日曜日
量子鍵配送プロトコルBB84での混合状態
Mixed States in the BB84 Quantum Key Distribution Protocol
At first glance, it may seem that if a perfectly noise-tolerant quantum computer existed, quantum computations would remain in pure states from beginning to end, making mixed states unnecessary. However, this is a misconception. Even in such an ideal quantum computer, mixed states can play an important and practical role.
I came to understand this through the BB84 quantum key distribution (QKD) protocol. Using the dynamic-circuit functionality available in Qiskit, I was able to verify this behavior experimentally on an IBM Quantum processor, ibm_kingston.
Specifically, when an eavesdropper is present, the BB84 protocol predicts a theoretical error-detection rate of 25%. Running the protocol on the quantum computer yielded an observed error rate of 25.9%, in close agreement with the theoretical expectation.
This experiment demonstrates that mixed states are not merely artifacts of noise or imperfections. Rather, they are an essential and useful concept in quantum information processing, even when quantum operations themselves are ideally coherent.
【要旨】これまで、密度行列に関する記事を2つ(こちらとこちらに)書いた。それによれば、もしも、完璧なノイズ耐性量子コンピュータがあれば、量子計算は最初から最後まで、純粋状態を保たれるので、混合状態は考える必要がないように思われた。しかし、それは誤りであり、たとえ、そのような量子コンピュータであっても、混合状態は有効に利用されるのである。そのことを、量子鍵配送プロトコルBB84を例として理解した。Qiskitに装備されている動的量子回路機能を用いて、IBM Quantum実機で確かめることもできた。
→Dr. Peter Lee, Dr. M.S. Qureshiからのこちらのコメントもここにあります。
🟢量子鍵配送プロトコルBB84の仕組み
すでに、過去の記事(こちらとこちら)で詳細を述べたが、短く言えば以下のようになるだろう。
-----「Aliceは、古典ビット(0か1)と、使用する基底(2種)をそれぞれランダムに選んで決定する。そして、選択した基底における、古典ビットに対応する状態ベクトルをBobへ送る。
Bobは、Aliceとは全く独立に選んだ基底で、受信した量子状態を測定する。もしもAliceとBobの選んだ基底が一致していれば、両者は同一の古典ビットを得ることになる。
しかし、ここでEveが盗聴を試みる場合、Eveは自身がランダムに選んだ基底でAliceの量子状態を測定してしまう。そして、Eveは盗聴を隠蔽するため、自身の測定結果に応じて量子状態を再度生成してBobへ送らざるを得ない。これは、”量子状態複製不可定理”による。しかし、Eveの選んだ基底がAliceのものと異なる場合(1/2の確率)、BobへはAliceが送ったものとは異なる(変質した)量子状態が届くことになる。
その結果、後線でAliceとBobが互いの基底を照合し、『基底が一致していたケース』のみを抽出したとしても、そのうち1/4(25%)の確率で二人の古典ビットが不一致を起こす。 AliceとBobはこのエラー率を検出することで、Eveの盗聴を確実に察知できる。」-----
たとえば、Aliceが連続して多数回、量子ビットを送信した場合の動きの例を以下に示す。盗聴がない場合と、盗聴がある場合について、その先頭部分を示す。
=== 1. 盗聴がない場合 (Eve: NO) ===
試行 1: Alice基底=X(0), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)
試行 2: Alice基底=X(0), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)
試行 3: Alice基底=X(0), Bob基底=Z -> Bob測定=0 | 不一致 (廃棄)
試行 4: Alice基底=X(0), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)
試行 5: Alice基底=X(0), Bob基底=Z -> Bob測定=1 | 不一致 (廃棄)
試行 6: Alice基底=Z(1), Bob基底=X -> Bob測定=0 | 不一致 (廃棄)
試行 7: Alice基底=X(1), Bob基底=Z -> Bob測定=1 | 不一致 (廃棄)
試行 8: Alice基底=Z(1), Bob基底=X -> Bob測定=0 | 不一致 (廃棄)
試行 9: Alice基底=Z(0), Bob基底=X -> Bob測定=1 | 不一致 (廃棄)
試行 10: Alice基底=X(1), Bob基底=Z -> Bob測定=0 | 不一致 (廃棄)
. . . . . . . . . .
【結果】Aliceの鍵 : 0000101000111110110111100000101011011001110100111111
【結果】Bobの 鍵 : 0000101000111110110111100000101011011001110100111111
エラー率: 0.0%
=== 2. 盗聴がある場合 (Eve: YES) ===
試行 1: Alice基底=Z(0), Bob基底=X -> Bob測定=1 | 不一致 (廃棄)
試行 2: Alice基底=Z(1), Bob基底=X -> Bob測定=1 | 不一致 (廃棄)
試行 3: Alice基底=X(1), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)
試行 4: Alice基底=X(0), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)
試行 5: Alice基底=X(0), Bob基底=Z -> Bob測定=1 | 不一致 (廃棄)
試行 6: Alice基底=X(0), Bob基底=Z -> Bob測定=1 | 不一致 (廃棄)
試行 7: Alice基底=X(0), Bob基底=X -> Bob測定=1 | 一致 (鍵採用)
試行 8: Alice基底=X(1), Bob基底=X -> Bob測定=1 | 一致 (鍵採用)
試行 9: Alice基底=X(1), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)
試行 10: Alice基底=X(0), Bob基底=Z -> Bob測定=0 | 不一致 (廃棄)
. . . . . . . . . .
【結果】Aliceの鍵 : 10011101100010110010001110110010011100110100
【結果】Bobの 鍵 : 00110101100011110010101111010111001100110000
エラー率: 25.0%
🟢混合状態はどこに現れ、利用されるか
Aliceは「基底 Z= {|0>, |1>} または基底 X = {|+>, |->}」と「古典ビット(0または1)」をそれぞれ全くランダムに選び、以下に示す可能な4つの状態のいずれか1つを送信することになる。
すなわち、送信される側のBobや、途中で盗聴を試みるEveの視点では、彼らはAliceがどの基底を使ったかを事前には知らない。したがって、彼らにとって届く量子状態は、4つの純粋状態が等確率(各 25%)で混ざり合った最大混合状態(Maximal Mixed State)になる。それを密度行列ρで表すと以下のようになる。
ρ = (|0><0| + |1><1| + |+><+| + |-><-| ) /4 = (1/2)I (Iは単位行列)
このことは、Aliceが2つの基底をランダムに行き来することで、「基底情報を知らないEveが、その量子ビットから正しくビット情報を取り出すことはできない」ことを意味する。あるいは、
「Eveがどの基底で待ち伏せしても、見つからず盗聴することは不可能」であることを示している。これが混合状態の正体であると言える。
🟢Qikitの動的量子回路機能でBB84を構成する
以前は、量子回路は「測定」して得られた古典ビット情報に依存して、その後の量子回路を動的に変更や追加することができなかった。しかし、現在のQiskitではそれが可能なので、上に述べた混合状態を含む量子回路を、一つのジョブとして実行することができ、非常に便利である。その回路図は以下の通りである。
Alice, Eve, およびBobがそれぞれ、どの基底を採用したか、また、測定結果はどうだったを見るため、量子回路の途中で、それぞれ2回づつ測定を行っている。それらの結果を6個の古典レジスタに格納し、その値に応じて、必要な量子ゲートを動的に追加している。
🟢IBM Quantumマシン実機(ibm_kingston)による実行結果
以上の量子回路を、Open Planで利用可能なIBM 量子コンピュータ実機で実行した結果を以下に示す。盗聴なし、盗聴ありの両ケースとも、ノイズによる若干の影響がみられたが、ほぼ、理論値通りの結果が得られた。
==================================================
【 Eveによる盗聴なし】IBM Quantum ibm_kingston usage = 2s
==================================================
採用鍵の長さ: 504 / 1000 shots
AliceとBobの選択基底が合致した先頭30個について:
Aliceの鍵 : [1 1 0 1 0 1 0 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 0 0 1 0 1 0 1 0]
Bobの鍵 : [0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0]
実機エラー率: 1.4% (理論値: 0% + 実機ノイズ)
==================================================
==================================================
【 Eveによる盗聴あり】IBM Quantum ibm_kingston usage = 2s
==================================================
採用鍵の長さ: 455 / 1000 shots
AliceとBobの選択基底が合致した先頭30個について:
Aliceの鍵 : [0 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 1 1 0 0 1 1 1 0]
Bobの鍵 : [1 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0]
実機エラー率: 25.9% (理論値: 25% + 実機ノイズ)
==================================================















