ラベル MIT App Inventor の投稿を表示しています。 すべての投稿を表示
ラベル MIT App Inventor の投稿を表示しています。 すべての投稿を表示

2024年11月20日水曜日

Using MicroBlocks with a Quantum Circuit Simulator

In the previous article, I used MicroBlocks to control the slider of the MIT App Inventor app from a micro:bit device. This time, I tried to display the results of my quantum circuit simulator on the micro:bit. Yet another use case for the micro:bit!

In quantum computing, one of the simplest and most important circuits is the Bell circuit, because it generates strong quantum entanglement. For example, for the Bell circuit in Fig.1, if the states of the two quantum bits are |0> and |1>, the output (measurement result) will be 00 and 11 with a 50% probability, respectively. And the results 01 or 10 will never appear. In other words, if the measurement result of one quantum bit is 0, the other will always be 0. On the other hand, if one is 1, the other will always be 1. I would like to try to display such a situation on the micro:bit.

My mobile circuit simulator has 12 types of quantum circuits using 2 to 6 qubits built in as examples. This time, I selected the Bell circuit from among them, as shown in Figure 2. The measurement results for that were displayed on the micro:bit, as shown in Figure 1. Of course, you need to first connect this simulator and the micro:bit with BLE. Each time the go button is pressed, the display on the micro:bit changed according to the probability obtained in ④.

[Design Considerations]

Since this circuit deals with two quantum bits, it is natural to use two micro:bits to display the output. However, when using MicroBlocks, it was found that the following two methods are either not possible or difficult to achieve.

  • Connect multiple micro:bits via BLE from the app.
  • Connect the app and micro:bit with BLE and use the radio from that micro:bit to communicate with another micro:bit.
Therefore, this time I decided to display the measurement results of two quantum bits on a single micro:bit.

Correction
I will correct the second paragraph above. A separate instance of both the MicroBlocks and the Bluetooth LE extension for each connection allows multiple micro:bits to be used from the app. I would like to thank David Kim, Peter Mathijssen, and John Maloney for letting me know this.

[Additional information]

The above example focuses on two qubits, but I have also created a version shown below that can display the measurement results for up to five qubits.

2024年7月29日月曜日

Developing a mobilephone app to demonstrate Shor's prime factorization

[Abstract] I have written several articles about Shor's prime factorization, one of the pinnacles of quantum algorithms. The mobilephone app I developed this time is an all-in-one app that includes both classical processing and quantum algorithms. However, I did not create the quantum algorithm part myself, but used the quantum circuit simulator Quirk. Quirk does not provide an API, so the necessary parameters for linking the classical and quantum parts are passed manually. The significance of this app is that it allows you to complete the execution of the entire Shor's algorithm on a single screen (although it is limited to small integers). In practice, this method of manually passing the necessary parameters (not a fully automated process) while checking the results of the quantum circuit simulation is useful for deepening your understanding. I would like to demonstrate this in detail below.

🔴Details of Shor's Factoring Algorithm
The theory and calculation details of Shor's algorithm are written in this article. Also, the most important part, finding order, is an application of quantum phase estimation, and this is also explained in detail in this article. Therefore, this article only describes the overview and usage of the app developed this time.

🔴All-in-one app for Shor's algorithm
First, the overall image of the developed app is shown in Fig.1. This screen shows an example of decomposing 221, given as the product of two prime numbers 13 and 17, into the original two prime numbers. It consists of a classical calculation part and a quantum calculation part.
This app was created with MIT App Inventor. The classical part verifies the order (period) candidates obtained from the quantum part, and if they are valid, prime factorization is performed immediately. If they are not, a parameter (called A here) is changed appropriately and the process is retried. Meanwhile, the quantum part calls the quantum circuit simulator Quirk to obtain order candidates. The Quirk screen is crowded, but you can use your finger to zoom in on the parts you need.

🔴How to use the app
Please see Fig.2 below. Give two prime numbers p and q, and press the blue button "setup R" to obtain the desired integer R. Next, turn on the switch with red characters "Quirk Q Sim". Then, manually give this integer R as an input to the displayed Quirk simulator. Give another (randomly selected) integer A to Quirk in the same way. This Quirk quantum circuit is designed to find candidates for the order (i.e., period) of f(x) = Ax mod R. This simulation consists of a total of 14 qubits. (8 qubits for problem setting, 6 qubits for solution)
Next, as shown in Fig. 3, the results of the Quirk simulation (measurement results) show that out of 256 (=28) bases, only four appeared with a probability of 25% each. If you enlarge the screen, you can see that one of the bases, |010000⟩, is a candidate for giving the order. Set this as the binary bit string "010000" in the window at the top of the screen.
Next, press the round "Shor" button as shown in Fig. 4. This binary bit string is then converted into a decimal, and then converted into a rational number (fraction s/r) using the continued fraction approximation method. The denominator r becomes a candidate for the order. In this example (N=221, A=18), s=1 and r=4. The validity of the order can be confirmed, and as mentioned earlier, we get GCD(Ar/2+1, R)=13 and GCD(Ar/2-1, R)=17, completing the prime factorization!
Although it is not a fully automated process, it is impressive that the entire Shor prime factorization can be demonstrated on a single screen in this app!

🔴Shor's Algorithm is Probabilistic
So far we have seen the whole picture of Shor's algorithm. It is a probabilistic algorithm. In fact, another result executed under the above conditions did not give a valid order, and the prime factorization ultimately failed. Such an example is shown in Fig. 5.
However, when executed using a fully quantum computer, the correct answer can be obtained with a sufficiently small number of attempts! The details are described in Nielsen & Chuang [1].

[Additional Notes]

MIT App Inventor was once again very useful. It was great to be able to call the external quantum circuit simulator Quirk easily using the WebViewer. On the other hand, if all the processing related to "f(x) = Ax mod R" was created in App Inventor, the number of blocks would increase, making it difficult to manage. Furthermore, it was necessary to use the Modular Exponentiation Method to prevent the calculation from overflowing. Therefore, this time, most of these were created in JavaScript and called from App Inventor. This kind of integration with JavaScript is also useful.

In creating this app, I referred to the chapter II-5 of Nielsen & Chuang [1], the chapter 7 of Wong [2] and the chapter 9 of Burd[3]. I would like to express my gratitude.

Reference

[1] Michael A. Nielsen and Isaac L. Chuang: Quantum Computation and Quantum Information - 10th Anniversary Edition, Cambridge University Press, 2010 (First published 2000).

[2] Thomas G. Wong: Introduction to Classical and Quantum Computing, Rooted Grove, 2022.

[3] Barry Burd: Quantum Computing Algorithms -Discover how a little math goes a long way, Packt Publishing, 2023.

2024年7月28日日曜日

ショアの素因数分解をデモするためのスマホアプリの開発

【要旨】量子アルゴリズムの頂点の一つ、ショアの素因数分解については、何度か記事を書いてきた。今回開発したスマホアプリは、その古典的処理と量子アルゴリズムの両方を包含したall-in-oneとなっている。ただし、量子アルゴリズム部分は自作ではなく、量子回路シミュレータQuirkを利用した。QuirkではAPIが提供されていないため、古典的部分と量子部分の連携では、必要なパラメータは人手で授受した。このアプリにより、(対象は小さな整数に限定されるが)一つの画面でショアのアルゴリズム全体の実行を完結できることに意味がある。実際に行ってみると、量子回路シミュレーション結果を確認しながら、人手で必要なパラメータを渡す(完全自動処理ではない)この方法は、理解を深める上で有用な面がある。以下に、それを具体的に示したい。

🔴Shor's Factoring Algorithmの詳細
 ショアのアルゴリズムの理論と計算の詳細はこの記事に書いた。また、その最も重要な部分である位数発見(finding order)は、量子位相推定の応用であるが、これに関してもこちらの記事に詳細を示した。従って、本記事では、今回開発のアプリの概要と使い方についてのみ述べる。

🔴ショアのアルゴリズムのAll-in-oneアプリ
 まず、開発したアプリの全体像をFig.1に示す。この画面は、2つの素数13と17の積として与えた221を、元の2つの素数に分解した例である。古典的計算部分と量子計算部分から成る。
 このアプリはMIT App Inventorで作られた。古典的部分では、量子部分から得た位数(周期)の候補を検証し、妥当であれば、直ちに素因数分解を行うことができる。そうでなければパラメータ(ここではAという名称)を適宜変更して再試行する。
 一方、量子部分では、位数の候補を得るため、量子回路シミュレータQuirkが呼び出される。Quirkの画面は込み入っているが、必要な箇所を指で拡大して見ることができる。
 
🔴アプリの操作手順
 下図のFig.2をご覧いただきたい。2つの素数p,qを与えて、青いボタン「setup R」を押すと目的の整数Rが得られる。次に、赤字のスイッチ「Quirk Q Sim」をonにする。そして、この整数Rを、表示されたQuirkシミュレータへの入力として(手動で)与える。もう一つの(ランダムに選んだ)整数Aも同様にQuirkに与える。このQuirkの量子回路は、f(x) = Ax mod Rの位数(すなわち、周期)の候補を見つけるように作られている。全部で14-qubitの構成(問題設定用に8-qubit、解答用に6-qubit)である。
 次に、Fig.3に示すように、Quirkシミュレーションの結果(測定結果)として、28= 256個の基底のうち、4個だけがそれぞれ25%の確率で出現した。画面を拡大して見ると、その一つの基底 |010000⟩が、位数を与える候補であることが分かる。それを2進ビット列"010000"として、画面上部の窓に設定する。
 続けて、Fig.4に示すように丸い「Shor」ボタンを押す。するとこの2進ビット列が10進小数に変換され、さらに、連分数近似法により有理数(分数s/r)に変換される。その分母rが位数の候補となる。この例(N=221, A=18)では、s=1、r=4であった。位数としての妥当性が確認できるので、すでに述べた通り、 GCD(Ar/2+1, R)=13とGCD(Ar/2-1, R)=17が得られて、素因数分解完了!
 完全自動処理ではないが、このアプリの一つの画面だけで、ショアの素因数分解の全体をデモできることは意味があるのではないか!

🔴Shor's Algorithmは確率的
 ここまでにショアのアルゴリズムの全貌を見た。これは確率的アルゴリズムである。実際、上記の条件で実行された別の結果は、妥当な位数を与えず、最終的に素因数分解が失敗した。そのような例をFig.5に示す。
 しかし、完全な量子コンピュータを使った実行においては、十分に少ない試行で正解が得られるという事実がある。その詳細は、Nielsen & Chuang [1]に叙述されている。

【補足】
 今回もMIT App Inventorをとても有効に利用できた。外部の量子回路シミュレータQuirkをWebViewerから簡単に呼び出せることは素晴らしい。一方、f(x) = Ax mod R に関係する処理を全てApp Inventorで作るとブロック数が増えて見通しが悪くなる。計算がオーバーフローしないように、Modular Exponentiation Methodを使う必要もある。そこで、今回は、これらの大部分をJavascripで作成し、それをApp Inventorから呼び出している。このような、Javascriptとの連携機能も有用である。

 このアプリの作成にあたっては、Wong[2]の第7章「Quantum Algorithms」とBurd[3]の第9章を参考にさせていただいた。感謝申し上げる。

References

[1] Michael A. Nielsen and Isaac L. Chuang: Quantum Computation and Quantum Information - 10th Anniversary Edition, Cambridge University Press, 2010 (First published 2000).

[2] Thomas G. Wong: Introduction to Classical and Quantum Computing, Rooted Grove, 2022.

[3] Barry Burd: Quantum Computing Algorithms -Discover how a little math goes a long way, Packt Publishing, 2023.
https://users.drew.edu/bburd/quantum/



2024年6月26日水曜日

Enjoy Shor's Prime Factorization with a Mobilephone App

This is the English translation of this article.
[Abstract]
To fully execute the well-known Shor's Factoring Algorithm, a large-scale fault-tolerant quantum computer is required, and with current quantum computers, this is unlikely to happen. However, when an ideal quantum computer appears, it is believed that this algorithm will have a huge impact on cybersecurity. Here, we created an app to apply Shor's algorithm to small integers (products of two prime numbers). This will allow you to become familiar with Shor's algorithm and deepen your understanding.

🔴 Overview of Shor's Factoring
There are many explanations of Shor's algorithm, but I was drawn to the YouTube video by Elucyda shown in Fig. 1. It takes about 25 minutes, and he explains it clearly and step by step, using only a whiteboard and clearly handwritten. This is great!

Shor's algorithm is said to be difficult to understand, but the outline is on this one page (8 lines). It involves prime factorizing an integer N, which is the product of two prime numbers. If N is small, it is not difficult to create an original program on a classical computer by following the steps in this diagram. However, you should pay attention to the part surrounded by a red frame in Fig. 1, "Find MIN r>0 such that ar=1 mod N". This finds the smallest integer r (order) such that ar = 1 mod N when you bring in another integer a for the integer N you want to factorize. This is nothing more than finding the minimum period of the repeating wave of the value of ar mod N.

For very large N, this order-finding is the core of Shor's algorithm, and this is where quantum computers come into play. (This article is only beginner level. Without a complete understanding of quantum algorithms for order finding, it cannot be called intermediate level or above. I would like to write about this in another article.) Since we are assuming a small N this time, we have realized the entire processing of Fig. 1 as a mobilephoe app. This will help you become familiar with Shor's algorithm, and will also serve as a preparation for creating quantum programs later.

🔴 Creating a mobile phone app
Originally, the search for the above order r would be performed as a quantum algorithm, but since we are creating a mobile phone app here, this part is also a primitive (naive) program that runs on a classical computer. Fig. 2 shows the order calculation function created with MIT App Inventor. It should be noted that there is a risk of overflow when calculating ar, especially when the value of r becomes large. Therefore, in order to prevent this to a certain extent, we do not calculate ar mod N directly, but instead use repeated calculations using a small r.

🔴 Review of execution results
Let's start by trying to prime factorize a small integer, for example N=247, with this app. (N is given as the product of two prime numbers p=19 and q=13.) Figure 3 shows two successful examples. In Figure (a), the integer a randomly set in Figure 1 happened to be GCD(q, a)>1, so factorization was completed immediately. This corresponds to Case 1 in Figure 1. On the other hand, Figure (b) corresponds to Case 2 in Figure 1, and factorization was successful as expected.
Figure 4 shows different cases of failure. In Figure 4(a), the order r for a random integer a could not be found within the preset range. Furthermore, in Figure 4(b), the random integer a and the order r were set successfully, but prime factorization failed. This corresponds to Case 3 in Figure 1. Shor's algorithm thus succeeds probabilistically (by heuristics). However, it is known that the success rate is quite high.
🔴Why can this algorithm be used for prime factorization?
This article focuses on how Shor's algorithm works, not on why it can be used for factorization. However, I would like to briefly explain the key points of why below. One of them, which may be surprising, is the following formula (junior high school math!):
      a2 - 1 = (a + 1)(a - 1)
Using this, ar-1 = 0 mod N in the explanation of Fig. 1 becomes (ar/2 + 1)(ar/2 - 1) = 0 mod N. In other words, the left side of = is divisible by N. Therefore, one of the prime numbers that make up N divides one of the factors on the left side. From this, GCD(N, ar/2 + 1) and GCD(N, ar/2 -1) should be prime factors of N. When we calculate the case of Fig.3(b) (a = 30, r = 6), we see that this is indeed the case, as shown below:
     GCD(306/2+1, 247) = GCD(27001, 247) = 13
     GCD(306/2 -1, 247) = GCD(26999, 247) = 19

Incidentally, the algorithm for finding the underlying order r turns out to be roughly equivalent to the (precise) quantum phase estimation already described here and here, which makes Shor's algorithm more familiar.

2024年5月20日月曜日

Congratulations Global AI Hackathon Winners!

MIT RAISE and the App Inventor Foundation have announced the winners of the Global AI Hackathon 2024. The Global AI Hackathon was a free virtual hackathon that encouraged people around the world to use MIT App Inventor to build AI apps for their purposes. The winners in each category will be invited to present their projects at the MIT AI & Education Summit in Boston from July 24-26.

For more information, see here and here.


2024年3月6日水曜日

Limited release: My mobile quantum circuit simulator

I have developed several types of original quantum circuit simulators as mobile applications. Eventually, I decided to make two of them available to the public, albeit in beta version. All of these were efficiently developed using MIT App Inventor. In these developments, the books [1] , [2] and [3] written by three professors, Chirs Bernhardt, Barry Burd and Shigeru Nakayama, respectively, were very helpful.

If you are interested in these apps and would like to try them out, please contact me. I will provide you built files (.apk format) for Android phones. Below is a very simple document to help you use it.

(Japanese summary "限定公開:私のモバイル量子回路シミュレータ"
私は、これまでに数種類の独自の量子回路シミュレータを、モバイルアプリとして開発してきた。そのうちに2つを、まだベータ版ではあるが、限定公開することにした。これらは、すべてMIT App Inventorによって、効率的に開発されました。これらの開発では、3人の教授Chirs BernhardtとBarry Burdと中山茂がそれぞれ執筆された著書[1]と[2]と[3]が非常に参考になりました。これらのアプリにご興味を持ち、試用してみたいという方がおられたら、私にご連絡ください。Android phone用のビルトファイル(.apk形式)をご提供します。それをご使用いただくために、以下に極簡単なドキュメントを示します。)

●Two types of mobile quantum circuit simulator
    Q1_beta1: for a single-qubit
    Q3_beta2: for 3-qubit system

------- Q1_beta1 app ----
● Q1_beta1 app - Setting quantum state using sliders

● Applying quantum gates

------- Q3_beta2 app ----
● Overview of the Q3_beta2 app

● Phase Kickback

● Grover’s Algorithm

● Superdense Coding

● Finding the frequency of coprime powers sequence(1)

● Finding the frequency of coprime powers sequence(2)

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

[2] Barry Burd: Quantum Computing Algorithms -Discover how a little math goes a long way, Packt Publishing, 2023.
https://users.drew.edu/bburd/quantum/

[3] Shigeru Nakayama(中山 茂): Quantum app Qni, Gaia Education series 52, 2022. (In Japanese)

2024年2月14日水曜日

Functional Programming in MIT App Inventor

Abstract: Functional programming blocks such as map, filter, reduce, and sort can be used in list operations in MIT App Inventor. These will allow you to create clean and easy-to-understand programs without using for loops or if-then-else. (This article has also been posted to the MIT App Inventor community. Have a look at this.)

要旨:MIT App Inventorのリスト操作において、map、filter、reduce、sortなどの関数型プログラミングブロックが使える。これにより、forループやif-then-elseを使わず、すっきりとした分かりやすいプログラムが作れるであろう。(この記事は MIT App Inventor コミュニティにも投稿されています。 こちらをご覧下さい。)

●MIT App InventorのFunctional List Operators
 
リスト処理において、図1に示すような関数型プログラミングのためのブロックが使える。すなわち、

  • map:要素に何らかの変換を施して新たなリストを作る。
  • filter:条件を満たす要素だけのリストを作る。
  • reduce:要素の最大値、最小値などを得るなど、縮約する。
  • sort:要素を条件に従ってソートし、新たなリストを作る。

 このような関数型プログラミングは、多くのプログラミング言語でサポートされている。しかし、MIT App Inventorのようなブロック型プログラミング環境にこれを取り入れるには多くの課題があったようである。この機能は、参考文献[1]で説明されているが、その元になる論文が[2]である。

 この論文[2]は、米国Wellesley大学(最難関の女子大らしい)の学生が2015年に発表したものであり、全98ページに及ぶ。表紙には、"Thesis advisor : Prof. Franklyn Turbak"と書かれているので(修士)学位論文のようだ。それだけ奥が深いものである。MIT App Inventorは、生徒学生を主な対象とした使いやすいプログラミング環境を提供しているが、関数型のような、高度なソフトウェア技術もしっかり取り入れて、強固なバックグラウンドを築いていることを改めて感じる。

●例題1: 指定された年の"13日の金曜日"を全て求める
 よくある例題かも知れないが、"指定年の13日の金曜日"を全て求めるアプリを、上記の機能を使った書いてみた。図2はその全ブロックである。大きなブロック"get_13Fri_list"が主要部であるが、ここには、forループもif-then-elseも全く出てこない。これが典型的な関数型プログラミングの簡単な例である。
 このブロックには、関数型ブロックが3つ使われている。(a)では、mapにより、月のリストをその月の13日の日にちリストに変換している。(b)では、そのリストをfilterにより、"金曜日=曜日番号6"だけのリストに変換している。このリストの要素は日にちオブジェクトなので、それを(c)でのmapにより、通常の書式の日付に変換している。つまり、map - filter - mapを連続して適用して、一気に流れるように、答えの日付のリストを得ている。爽快感がある!

●例題2: reduce(combining)も使ってみる
 上記のmapとfilterの他に、reduce(combining)も有用です。図3に、リスト要素をユークリッドノルムで正規化して新たなリストを作る例を示します。

参考文献

[1] MIT App Inventor Functional List Operators
https://ai2.appinventor.mit.edu/reference/concepts/pholo.html#map

[2] Soojin Kim, "Developing and Assessing New List Operators in App Inventor", 2015.
https://repository.wellesley.edu/object/ir558


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年9月20日水曜日

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

 MIT App Inventorでは、いち早くChatBotやImageBotなどの生成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年8月1日火曜日

生成AIブロックがMIT App Inventorで使えるようになった(2)

 前報の続編です。(2023-08-03、GUIにもこだわり、全面改訂しました!)

 例えば、スライダーが3本あり、そのつまみを音声で動かしたいします。結論から言うと、

"スライダーの2番を0度に、3番を45度に、1番を90度に設定せよ。"

などと発話するだけでできました。音声から生成されたテキストから、数値だけを取り出すのはちょっと面倒ですね。英語と違って、空白の区切りが無いこともその一因です。まあ、正規表現を利用したExtesion(これに関してはこちらをご参照)などを使う手もありますが...

 ここでは、本来、アプリの中で実施すべきこの処理を、ChatGPTにやらせています!具体的には、 次の図をご覧ください。「指示文」がChatBotに対する命令です。そして、発話文はそのデータとなります。結果として、この発話例からは、3行のコンマ区切り数値が得られています。そうなれば、App Inventorの「List from CSV Table」ブロックが使えて、スライダーの値の設定はすぐにできます。

 Speech2TextやChatGPTの特性を踏まえて使う必要があります。ちょっとした発話の違いで、Speech2Textの出力テキストは変わります。このアプリは、発話後は自動的に実行結果を出しますが、Speech2textの結果を確認・修正した後にChatGPTへ進むように変更しても良いでしょう。
 また、同一テキストに対して、ChatGPTはいつも同じ結果を出すとは限りませんので、ここにも注意が必要です。深層学習などの仕組みには確率的要素が多分に含まれているからです。場合によっては、「指示文」を調整する必要があるでしょう。例えば、こんな感じ。

-----------------------------------
 なお、この例題は、既に報告した「光子の偏光アプリ」での、3枚の偏光板の角度を音声で自由に変更するために検討したものです。元の画像を再掲します。


2023年6月21日水曜日

生成AIブロックがMIT App Inventorで使えるようになった(1)

 昨日(2023-06-20)、MIT App Inventor version nb193がリリースされ、新たに生成AI系ブロックが使えるようになった。すなわち、ChatGPTとDALL-E2を利用するChatBotとImageBotである。早速、簡単な例を考えて試してみた。なかなか素晴らしい!応用はまだまだこれからだろうが。(→続編はこちら)

●私の考えた簡単な質問:
「次の5つの行動からランダムに一つを選んでください:
learn quantum mechanics, lecture in front of students, climb Mt. Fuji, shake your dice, swim in the sea」

●ChatBotとImageBotの答え:
質問に答えて、どれかを(例えばshake your dice)選んで、そのイメージを図示してくれます!

 普通のアプリでは、行動リストの中からランダムに選ぶコードも書きます。しかし、ここでは、そのコードは書かずに、ChatGPTが指図を理解して選択しています。ここにも、生成AIの片鱗を窺えるのです。

 こんな風に楽しんでいると、なんと、OpenAIの無料枠API利用回数限度に達して使えなくなってしまった。だが、24時間後にはリセットされて、1日あたり数十回はリクエストできるようだ。それを超える場合は、有料プランの契約が必要。

[追加]他にもなかなかの結果がありますので、追加します。
 "harvest cabbage(キャベツを収穫)"と、"teach math(数学を教える)"です。それらしい雰囲気が出ています。Very goodですね。
 もう2つ行きます。2つの行動を同時に選んで、そのイメージを描いてもらいました!
"climb Mt. Fuji, teach math"(富士山にのぼり、数学を教える)と"swim in the sea and harvest cabbage" (海で泳ぎ、キャベツを収穫する)です。なかなか創作力ありますわ。

MIT App Inventor version nb193:
https://community.appinventor.mit.edu/t/mit-app-inventor-version-nb193/87279