2025年3月1日土曜日

量子物理学(量子力学)誕生100周年

 今年は、量子物理学(量子力学)誕生100周年とのことである。それを記念して、国連は、2025年を「国際量子科学技術年」と定めた。その中核となるのはやはり、量子コンピュータの実用化であろう。今年は特に、色々な動きがあると思う。

 2025年2月に、NEDO(国立研究開発法人新エネルギー・産業技術総合開発機構)は、「量子コンピューターユースケース事例集」という、150ページに渡る詳細な報告書を公開した。最新の56のユースケースを含む、製造、金融、エネルギー、創薬などの分野での効果や課題がよく分析されていて非常に参考になった。素晴らしい資料である。

 産総研では、G-QuATと呼ばれる、3方式の量子コンピュータとGPUスーパーコンピュータを融合させて研究開発、実用化を促進させるためのセンターを2025年春に発足させる。

 また、大阪大学では、2025年7月末から「Quantum Innovation 2025」の開催を予定している。5日間に渡る大規模なイベントとなりそうである。

 ささやかならがら、小生も神奈川工科大学が開催する「ITを活用した教育研究シンポジウム2024」で、以下のような短い講演を行うことになった。



2025年2月12日水曜日

Qiskitで量子機械学習の例題を動かす

 量子コンピューティングに関する基礎的な知識を得て、基本的なアルゴリズムも一通り習得した後にやるべきことはいくつかある。例えば、量子機械学習量子暗号関連であろう。量子化学も非常に重要なのだが、その方面の素養がないとだめである。ということで、今後、量子機械学習を重点に学ぶことになろう。
 
 従来の機械学習アルゴリズムをそのまま量子コンピュータで高速化できるわけではない。

 現時点において、機械学習の世界の真の実用問題で、「計算速度」という面で、量子が古典を凌駕した報告はおそらく無い。それでも可能性を求めて、研究開発は進む!

 古典的な数値計算は、圧倒的に従来コンピュータの得意分野なのである。量子コンピュータには、これまでも経験したことだが、特有の得意分野がある。機械学習にそれをどう展開していくのか。例えばすでに、データそのものを量子データ化して、量子アルゴリズムにかけるというアプローチもあるようだ。でも、まだまだ未知の世界だと思う

 量子機械学習に関する日本語の書籍はとても少ない。私の知るところでは、下記の2つの書籍がある。まだよく読んでいないが、いずれもなかなか優れた解説書のようである。
 曽我部氏の著書のサブタイトルに「量子回路自動設計」という言葉があった。もしかすると、IBMのQASMで書かれたような量子プログラムを、量子的なデータとみなし、それを使った何らかの学習を行い、最適化するものかもしれない。違うかもしれない。よく読めばわかるだろうが。ともかく、主なアルゴリズムに関して、Pythonコードも公開されているので重宝するだろう。
曽我部東馬:Pythonではじめる量子AI入門

 もう一冊は、嶋田氏によるものだ。「4.4 量子コンピュータと機械学習」、「5.3 パラメータ付き量子回路による機械学習」に、詳しい解説が数式展開とともに説かれている。難度は高そうだが精緻な叙述なので取り組めるだろう。
嶋田義皓:量子コンピューティング

 だが、すぐにでも例題を動かしてみたい。話はそれからだ!という場合は、別の選択肢として、IBMのQiskitサイトには、Quatnum_Machine_Learningという、まとまった解説が載っている。シミュレータやIBM Quantum実機でもすぐに動かすことができる。まず動かして、次第に中身に迫る。それが私のやり方だ。

 だが、ここで注意すべき点がある。最新のローカルQiskit環境、Qiskitライブリにしないと、すぐに大量のコンパイルエラーが出てめげてしまう。下記のように頻繁に更新したり、バージョンを確認することが必要である。Qiskitは頻繁にバージョンアップがなされ、その都度、それまでの量子プログラムは動かなくなることで有名だ。Migrationガイドはあるものの、いちいちそれを調べるのはとてもしんどい。でもやむを得ない。以下は、忘備録。

(1)Qiskitを最新版にする。
 ターミナルで、pip install -U qiskit を実行

(2)量子機械学習関係ライブラリも最新版にする。
 ターミナルで、以下のように更新しても良い。
 pip uninstall qiskit-machine-learning
 pip install qiskit-machine-learning

(3)ラリブラリ関係のバージョンを確認する。
 現在(2025-02-12)の最新版:
 qiskit 1.3.2、qiskit_machine_learning 0.8.2
 ターミナルから、以下のようなコマンで現時点のローカル環境を確認。
 pip list
 pip show qiskit_machine_learning
(なお、Jupyterのコード内で行うには、pipの代わりに、!pipを使う。)

🔴実は、上記のような更新だけで済めば極めてラッキーだ。過去に作ったプログラムと現行Qiskitは整合が取れないことも多いからだ。

-----蛇足----
 英語の書籍もあるのだろうが躊躇している。最近、量子コンピューティング関係の英語書籍には、粗雑というか、がっかりする内容のものも見受けられる。例えば、明らかにChatGPTなどを使って集めた知識の羅列を体裁を整えて出版しただけというのがあった。買ってしまって憤慨ということもあった。大手出版社ではない、個人出版のような書籍には特に要注意と思われる。

2025年1月17日金曜日

マウスもポインターも使わないパワポ・プレゼン

 皆様すでにご利用かと思いますが、Power Pointのプレゼンで、マウスもポインターも使わず、聴衆と向かい合ったまま話を進めたい場合がありますね。そんな時、遠隔から指先で(くまモンを)クリックしてスライドのアニメーションを行うといいのではないでしょうか。
 一例を挙げます。「量子もつれを利用したMermin-Peresマジック(ゲーム)」の説明をそのようにしてみました。そのビデオをご覧ください。黙ってみていても、話の流れがつかめていい感じではないでしょうか。

2025年1月9日木曜日

関孝和と仏陀に、量子コンピュータについて質問してみた

 AIチュートリアルシリーズ「AI with MIT App Inventor」に、このほど「GenAI: Historical Character Advisor App」が追加された。これは、歴史上の偉人に、自由に質問をして回答を得るアプリの作成である。慣れた学生であれば、30分もあれば作れてしまう!

 私が最も驚いたのは、Steve Jobsは、40年前に今のようなAI時代を予測していた!との記述である。彼がそれを話しているYoutubeビデオ(90秒)がここにある。その中で、例えば、現代の人がアリストテレスに質問して答えを得るといった構想を述べているのである。上記のチュートリアルは、これをスマホアプリとして実現するものなのである。

 これは素晴らしい!と思い、かっての同僚のT. H.先生に話したら、「面白いが、AIによる回答が、本人の回答と同じという保証はない...」との感想でした。冷静に考えると、確かにその通りである。そんな回答を信じていいのかと思い直した。だが、捨て切れるものでもない。まずは、試してみよう!

 このチュートリアルを自分なりにデザインを変えて、関孝和(江戸時代の世界的数学者)と仏陀に、「量子コンピュータは実用化できますか?」と質問してみた。それぞれ、確かにその人らしい回答が得られた!

 両者の回答のポイントは、以下のとおりだと解釈される。
⭕️関孝和:課題は多いが、多くの分野に革命を起こすほどの可能性を秘めている。
⭕️仏陀:潜在的な利点とリスクに留意せよ。

 困った!本人からの回答だと信じるべきか否か。あなたならどうしますか?


(補足1)
仏陀からの回答の最後の方が画像では欠けていましたので補います。

「最後に、人間の人生の究極の目標は物質的な成功や技術的進歩を達成することではないことを覚えておく必要があります。究極の目標は、悟りと苦しみからの解放を達成することです。私たちは、テクノロジーの追求に夢中になりすぎて、精神的な成長を忘れてはなりません。」

(補足2)LLMは、デフォルトではGoogleのGeminiになっていますが、ChatGPTを使うこともできます。ただし、一定回数以上になると、有料のAPIトークンの入手が必要のようです。

2025年1月1日水曜日

新年を迎えて:原点から湧き出るような

  新年を迎え、今年もこうありたい、という想い(の一端)を描いてみた。良く知られていることだが、複素数の神秘の一つを、久しぶりにPythonでコーディングしてみた。ある程度イメージに近いかも知れない。本当は、綺麗なアニメーションにすべきだが、そこまで手が回らない。Pythonで書くにあたっては、ChatGPTのお世話になった。今年もそういう機会はどんどん増えるだろう!

 短いgif画像を残像処理付きで作ってみた。流れがはっきり見えてきた!
 これ以外にも、複素数の神秘をいくつか描いてみた。極と零点付近の偏角の分布と、-1のn乗根である。

2024年12月26日木曜日

Feliz Natal (Merry Christmas)

ブラジルの量子コンピューティング関係の友人から、素敵なクリスマスカードが届きました!

"Feliz Natal" とはポルトガル語で「メリークリスマス」を意味します。

ご覧ください。

なお、彼の小さな素晴らしい量子コンピューティング書籍はこちらで紹介しました。

2024年12月1日日曜日

40分で量子コンピューティングに親しむ(Quantum Computing in 40 minutes)

こんなチュートリアルを作ってみました。日本語pdf版で14ページです。
(ご希望の方にはお送りします。)
[題名]
40分で量子コンピューティングに親しむ

[ねらい]
 量子力学や量子コンピュータに馴染みのない方々(学生、技術者)に、この分野を学ぶきっかけとしていただくことを目指し、短い説明を試みました。一定の技術内容は含めましたが、叙述の一貫性や精密さよりも親しみやすさを第一としました。量子コンピュータの高速性の仕組みに気をかけながらも、従来の”計算”(computation)と対比した場合の斬新さと不思議さに迫ることに主眼を置いています。
 もう一つの特徴として、自作のモバイル量子回路シミュレータを動かし、その結果の図も取り入れて具体性を持たせました。さらに、量子コンピュータは(難しい技術課題を抱えながらも)そこまできていることを感じていただくため、IBM Quantumコンピュータ実機での「量子もつれ」の実行例も含めました。

[目次]
🔸概 要
🔸量子ビット/量子ゲート/測定 (qubit, quantum gates, measurement)
🔸重ね合わせ(superposition)をどのように使うのか
🔸重ね合わせの応用(1) Grover の探索アルゴリズム(振幅増幅法)
🔸重ね合わせの応用(2) 偽コイン発見パズル(量子天秤)
🔸量子もつれ(entanglement) - その1 (Bell回路)
🔸量子もつれ(entanglement) - その2 (Tiny Mermin-Peres Magic)
🔸量子コンピュータの実機は利用できるのか? Yes, You Can !
🔸量子コンピュータの現状と今後
🔸補足事項

(このチュートリアルに含まれる幾つかの図を以下に示します。)
------------------------------------------------------

I made this article. It's 14 pages long (Japanese PDF version). (Please contact me if you need it.)

[Title]
Get familiar with quantum computing in 40 minutes

[Objective]
A short explanation has been provided for students and engineers who are not familiar with quantum mechanics and quantum computers, with the aim of offering an opportunity to learn about this field. Although a certain amount of technical content has been included, familiarity has been prioritized over consistency and precision of description. Emphasis has been placed on the mechanism behind the high speed of quantum computers, highlighting their novelty and mystery compared to conventional "computation." Another feature is the inclusion of diagrams generated by running a mobile quantum circuit simulator, making the explanation more concrete. Additionally, an example of "quantum entanglement" executed on a real IBM Quantum computer has been provided to illustrate how far quantum computers have progressed, despite the technical challenges they continue to face.

[Table of Contents]
🔸Overview
🔸Quantum bits and quantum gates
🔸How to use superposition
🔸Applications of superposition (1) Grover's search algorithm (amplitude amplification method)
🔸Applications of superposition (2) Fake coin detection puzzle (quantum balance)
🔸Quantum entanglement - Part 1 (Bell circuit)
🔸Quantum entanglement - Part 2 (Tiny Mermin-Peres Magic Game)
🔸Can we use a real quantum computer? Yes, You Can!
🔸Current status and future of quantum computers
🔸Additional information

------------------------------------------------------

The end of the year is approaching. I am preparing next year's calendar. Mt. Fuji often appears as a picture on the calendar. Mt. Fuji is of course beautiful, but I love this mountain more than Mt. Fuji.

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年11月16日土曜日

Using MicroBlocks with a Quantum Bit Simulator

Recently, I read an article titled "Using MicroBlocks with MIT App Inventor" [1]. It looked very interesting, so I applied it to the quantum bit simulator I am creating. Specifically, I controlled two sliders to change the state of quantum bit on the Bloch sphere with a single MicroBlocks device. I was able to experience a fun feeling of operation that was different from software sliders!

The outline is summarized in two figures, Fig. 1 and Fig. 2, below. If you would like to know more about this quantum bit simulator, please refer to the document [4]. 


In addition, the following three documents [1][2][3] were very helpful. I would like to express my gratitude.

References

[1] Using MicroBlocks with MIT App Inventor (by App Inventor Foundation)
https://microblocks.fun/blog/2024-11-08-appinventor-intro/

[2] MicroBlocks BLE Extension (by Peter)
https://community.appinventor.mit.edu/t/microblocks-ble-extension/129412

[3] Tools Extension (by Taifun)
https://puravidaapps.com/tools.php



2024年11月11日月曜日

How to run quantum circuits on the development platform Qiskit

[Abstract] IBM Qiskit is used as a typical development environment for quantum computing. Its version is frequently updated, and some parts are soon deprecated, which can be confusing. The description of quantum gates and quantum circuits remains almost the same, but there are frequent changes in simulations and execution methods on actual machines. Here, I would like to note three typical execution methods at the present time (2024-11-10).

🔴Example: Quantum computation part of Shor's prime factorization algorithm

Here, we will focus only on running the order finding quantum circuit, which is the main part of Shor's algorithm. Fig.1 shows the prime factorization of the very small integer 15 (15 = 3 × 5) for demonstration purposes. We will not explain the relationship between the entire Shor algorithm and the quantum circuit in Fig.1 this time, so if necessary, please refer to the following past articles.

🔴[1] Simulation with Qiskit Sampler (run on local PC)

Qiskit Sampler is the most common simulator for running a quantum circuit (name: qc) like the one in Fig.1 (including measuring the lower three qubits). The main points of its use are as follows. The results of this simulation (measurement results of 1,000 shots) are shown in Fig.2.

# Running the Simulation
from qiskit_aer.primitives import Sampler
sampler = Sampler()
result = sampler.run(qc, shots=1000).result()

# Extraction and visualization of measurement results
quasi_dists = result.quasi_dists
binary_quasi_dist = quasi_dists[0].binary_probabilities()
counts_dict = quasi_dists[0].binary_probabilities()
counts = Counts(counts_dict)
plot_histogram(counts)


🔴[2] Simulation incorporating a noise model of the actual machine (run on a local PC)

In the above, the simulation results (Fig.2) show that the counts corresponding to the four bases are approximately 25% each, and the counts of the other bases are zero as expected because there is no noise. In addition to using a normal sampler like this, it is also possible to perform simulations that reflect the noise generated by the actual quantum computer.

Fig. 3 shows the result of incorporating a noise model generated by a real machine (127-qubits) named ibm_sherbrooke into AerSimulator and running it. Indeed, the effects of noise that did not occur in Fig. 2 are apparent. This may be useful for preliminary examination before running on a real machine.

# important imports
from qiskit_aer import AerSimulator
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2 as Sampler

# Set the noise model of the real machine
real_backend = service.backend("ibm_sherbrooke")
aer = AerSimulator.from_backend(real_backend)
pm = generate_preset_pass_manager(backend=aer, optimization_level=1)
isa_qc = pm.run(qc) # transpile for the real machine
sampler = Sampler(mode=aer)
result = sampler.run([isa_qc],shots=1000).result() # execution

# Extraction and visualization of measurement results
pub_result = result[0]
counts = pub_result.data.c.get_counts() # Note the 'c' !
plot_histogram(counts)

🔴[3] Execution on an actual IBM Quantum machine (submitting a job via the web)

Next, the job was submitted to an actual IBM Quantum machine via the web and executed. The machine was ibm_sherbrooke, the same as that given in the noise model above. The job was executed in batch mode, so the execution results were retrieved via the web after it was completed. This is shown in Fig. 4, and it was found to be almost identical to the simulation results shown in Fig. 3, which reflect the above noise model.

# Automatically select machines with low load
from qiskit_ibm_runtime import SamplerV2 as Sampler
service = QiskitRuntimeService(channel="ibm_quantum", token= "***")
be = service.least_busy(simulator=False, operational=True)
print(f"QPU backend:{be}")

# Transpile for real machine and submit the job
pm = generate_preset_pass_manager(optimization_level=1, backend=be)
ic = pm.run(qc) # Transpiled circuit
job = Sampler(be).run([ic], shots= 1000)
print(f"job ID: {job.job_id()}")
print(f"job statusI: {job.status()}")

# After execution, the results are retrieved and displayed
from qiskit_ibm_runtime import QiskitRuntimeService
service = QiskitRuntimeService(
    channel='ibm_quantum',
    instance='ibm-q/open/main',
    token='token for the job'
)
job = service.job('jab ID')
job_result = job.result()
counts = job.result()[0].data.c.get_counts()
plot_histogram(counts)

The execution status is shown in Fig. 5. Usage = 2 sec. Free users are limited to 10 minutes of usage per month. This is sufficient for testing simple quantum circuits, but caution is required when testing slightly more complex quantum circuits, as this can result in unexpectedly high usage. At present, there are three models of actual machines available for free use, as shown in Fig. 6. For paid users, eight more models of actual machines can be used in addition to these.


🔴 Differences between the results of a real machine and a simulator

Currently, quantum computers generate various noises, which causes errors. For example, the difference between the results of a pure simulator (Fig. 2) and the results of a real machine (Fig. 4) shows this. Although it cannot be said in general, errors that occur on a real machine can have a large impact on the necessary calculations. However, in the case of this example problem, due to the nature of probabilistically searching for an order, it can be said that the difference between Fig. 2 and Fig. 4 is almost no problem.