2025年4月24日木曜日

Visualizing and Understanding QSVC

[Abstract] 
QSVC (Quantum Support Vector Classifier) ​​can sometimes produce new classification decision boundaries that are different from those of classical SVC. An example of this was reported in a previous article. This time, we visualized (part of) the QSVC process that leads to this point. Visualization is not simply beautiful or easy to understand. While it can help us understand the mechanism in concrete terms, it can also be a trigger for new questions to arise, encouraging progress. Javier's book “QML Unlocked” was very useful, and is mentioned at the end of this article.

🔴What to visualize
A small dataset for visualization, 16 samples of Gaussian Parity, was prepared. It consists of two features and a label. The parts to be visualized in the overall flow of QSVC are shown below.
  1. Normalization (scaling) of input data: No need for visualization.
  2. Reduction of input data dimension: Not necessary in this case, since it is two-dimensional (2 features).
  3. Display of input data: Draw data samples in a 2D scatter plot. → Figure 1
  4. Convert input data to quantum state: Display quantum state on Bloch sphere. → Figure 2
  5. Create quantum kernel matrix: Represented as a heat map. → Figure 3
  6. Perform SVC learning: Display the resulting classification decision boundary in 2D. → Figure 4

🔴Visualization of Quantum Feature Map

Here, we use ZZFeatureMap, which is equipped in Qiskit, to convert each sample of the input data in Figure 1 into a quantum state (feature vector). The result is plotted on two Bloch spheres, as shown in Figure 2. As shown in the figure, ZZFeatureMap is a system (considered to be four-dimensional) that includes two quantum bits of entanglement and phase shift, so quantum states are displayed in both q0 and q1.

🔴Visualization of Quantum Kernel Matrix

Next, we create a quantum kernel matrix using the results of the feature map. Each element is the fidelity calculated by the inner product of two combinations of quantum states. Figure 3 shows this matrix as a heat map. The brighter it is, the higher the similarity.
Classical SVC also implicitly calculates the corresponding similarity using a kernel function during training. On the other hand, quantum QSVC calculates all similarities in advance to create a kernel matrix, which is then passed to classical SVC training. SVC training has the option kernel='precomputed'. QSVC repeatedly runs the quantum circuit for all combinations of inputs to create a quantum kernel matrix.

Now, this quantum kernel matrix does not contain any original label information. Therefore, classification cannot be performed using this matrix alone. Learning  (SVC learning) using this matrix and label information is required. However, even with just Figure 3, it is possible to predict whether two samples are likely to fall into the same class or into different classes.

For example, the similarity between the vectors of sample numbers 0 and 2 is quite low, as shown in [A] in Figure 3. As shown in Figure 2, the two are almost orthogonal. And they have different labels. Therefore, it is highly likely that they will be placed in different classes.
Furthermore, the similarity between the vectors of sample numbers 4 and 8 is quite high, as shown in [B] in Figure 3. As shown in Figure 2, the two are also heading in a similar direction. And they have the same label. Therefore, it can be predicted that they will be highly likely to be placed in the same class.

🔴Visualization of classification decision boundary

Next, using the quantum kernel matrix in Figure 3 and the original label information, classification training is performed. This training is the same as classical SVC training. The resulting decision boundary is shown in Figure 4. The relationship between data points 0 and 2 [A] and the relationship between 4 and 8 [B] are as expected above.

🔴The decisive difference between quantum QSVC and classical SVC

The decisive difference between QSVC and classical SVC is not whether the kernel matrix is ​​calculated in advance, but in which space the vector inner product (similarity) is calculated. In classical SVC, the input data is also classified after mapping it to a high-dimensional space using a kernel function. However, the properties and structure of that space are different from QSVC.
In QSVC, it is important to know what kind of quantum feature map is used to convert the input into a quantum state. Whether or not QSVC's superiority is demonstrated depends on whether the feature map can realize a mapping that is difficult to realize classically.

🔴[Reference book] Introduction to Javier's "QML Unlocked"

There are few books in Japanese to learn quantum machine learning. The ones already published have a strong theoretical aspect and are not very suitable for beginners. In the meantime, the English book by Javier Mancilla Montero, shown in Figure 5, has very easy-to-understand explanations. Although the above example is my own original work, I obtained very useful information from this book, so I would like to briefly introduce the contents of this book.
It is a compact book (228 pages in total) with 10 chapters. Chapters 1-3 are an overview of quantum computing and machine learning. Chapters 4-7 cover QSVC, and chapters 8-10 cover more advanced topics such as VQC (Variational Quantum Classifier).

Overall, the book focuses on the explanation of QSVC. Although there are few mathematical expressions, the description is precise and quite deep. The explanation of creating a quantum kernel using several types of feature maps is excellent. Going further, it also attempts to combine them for SVC learning (multi-kernel learning). It explains this concretely using quantum platforms such as Qiskit and PennyLane. All the codes provided were able to run perfectly in my local environment.

Those who reach Chapter 4 for the first time may be a little confused. This is because the chapter explains code that demonstrates (1) MinMaxScaling, (2) dimensionality reduction using principal component analysis, (3) quantum state generation using ZZFeatureMap, (4) quantum kernel matrix generation, and (5) SVC learning all at once for a large dataset consisting of 1,000 samples with 20 features. However, there is no need to worry, because the following chapters explain dimensionality reduction in detail in Chapter 5, FeatureMap in Chapter 6, and SVC learning using quantum kernels in Chapter 7. In other words, the overall picture is shown first, followed by specific discussions.

For large-scale input data, creating feature maps and quantum kernel matrices, and training using them takes a lot of time in simulation. Although this book is not a programming book, as a countermeasure, it also provides multi-core parallel processing code using the PennyLane library and Python joblib. In fact, on my M1-mac-mini (8 cores), I was able to achieve a speedup of more than four times.

----------------------------------------------------------
🟢Special thanks to Javier Mancilla Montero, Ph.D. for posting this article of mine on Linkedin, see below.
----------------------------------------------------------

2025年4月23日水曜日

量子サポートベクタ分類QSVCのビジュアル化

【要旨】QSVC(Quantum Support Vector Classifier)により、古典SVCの場合とは異なる新たな分類決定境界が得られる場合がある。その一例を先の記事で報告した。今回は、そこに至るQSVCの過程(の一部)をビジュアル化してみた。ビジュアル化は、単に、美しい、分かり易いではない。具体的に仕組みを納得できる一方、新たな疑問が湧くきっかけともなり、進歩を促す。

🔴何をビジュアル化するのか
 ビジュアル化のための小さなデータセット、Gaussian Parityの16サンプルを用意した。2つのfeatureとラベルから成る。QSVC全体の流れにおいて、ビジュアル化する箇所を以下に示す。
  1. 入力データの正規化(スケーリング):ビジュアル化の必要は特になし。
  2. 入力データの次元削減:今回は2次元(2 features)なので不要。
  3. 入力データの表示:データサンプルを2D散布図に描く。→図2
  4. 入力データを量子状態に変換:ブロッホ球に量子状態を表示。→図3
  5. 量子カーネル行列の作成:ヒートマップとして表現。→図4
  6. SVC学習を行う:結果としての分類決定境界を2D表示。→図5

🔴Quantum Feature Mapの可視化
 ここでは、Qiskitに装備されているZZFeatureMapによって、図2の入力データを量子状態(特徴ベクトル)に変換する。その結果を、図3の示すとおり、2つのブロッホ球に描いた。ZZFeatureMapは、図の通り、2量子ビットのEntanglementとPhase Shiftを含む一つの(4次元と見做せる)システムであるため、q0とq1の両方に量子状態を表示する。

🔴Quantum Kernel Matrixの可視化
 次に、Feature Mapの結果を使って量子カーネル行列を作る。その各要素は、2つの量子状態の組合わせについて、その内積で計算された類似度(fidelity)である。この行列を、ヒートマップとして表現したものが図4である。明るいほど、類似度が高い。

 古典SVCでも、これに該当する類似度を学習中に暗黙にカーネル関数で計算する。一方、量子QSVCの場合は、予め全部の類似度を計算してカーネル行列を作り、古典SVCの学習へ渡すのである。SVCの学習には、kernel='precomputed'というオプションがある。QSVCでは、入力の全ての組み合わせについて、量子回路を繰り返し実行し、量子カーネル行列を作る。

 さて、この量子カーネル行列には、元のラベル情報は一切入っていない。したがって、これだけで分類を行うことはできない。この行列とラベル情報を使った学習(SVC学習)が必要である。だが、図4だけでも、2つのサンプルが同じクラスに入り易いか、または別々のクラスになり易いかを予想することはできる。

 例えば、サンプル番号0と2のベクトルの類似度は図4の[A]の通りかなり低い。図3でも両者はほぼ直交している。そして、両者は異なるラベルを持っている。したがって、両者は別々のクラスに入る可能性が高いであろう。
 また、サンプル番号4と8のベクトルの類似度は図4の[B]の通りかなり高い。図3でも両者の向きは近い。そして、両者は同一ラベルを持っている。したがって、両者は同じクラスに入る可能性が高いと予想できる。

🔴分類の決定境界の可視化
 次に、図4の量子カーネル行列と元のラベル情報を使って、クラス分けの学習が行われる。この学習は、古典SVCの学習と同じものである。その結果としての決定境界を図5に示した。データポイント0と2の関係[A]、4と8の関係[B]は、上述の予想通りである。

🔴量子QSVCと古典SVCの決定的な違い
 QSVCと古典SVCの決定的な違いは、カーネル行列を事前に計算するか否かではなく、どの空間においてベクトルの内積(類似度)を計算するかである。古典SVCにおいても、カーネル関数を用いることで入力データを高次元空間へ写像した後に分類を行う。しかし、その空間の性質や構造はQSVCとは異なる。
 QSVCでは、どのような量子Feature Mapによって入力を量子状態に変換するかが重要である。QSVCの優位性が発揮されるか否かは、そのFeature Mapが古典的には実現困難な写像を実現できるか否かによる。

🔴[参考書] "QML Unlocked"(量子機械学習の扉を開く)の紹介
 量子機械学習を学ぶための日本語の書籍は少ない。既刊のものは理論的側面が強く初心者にはあまり向かない。そんななか、図6に示した、Javier Mancilla Montero氏による英語の書籍は説明がとてもわかりやすい。今回の上述の事例は私のオリジナルではあるが、この書籍から大いに参考になる情報を得たので、簡単に本書の内容を紹介したい。
 小型本(全228ページ)で、10章からなる。第1〜3章は、量子コンピューティングと機械学習の概説である。第4〜7章はQSVCを、また、第8〜10章はより進んだVQC(Variational Quantum Classifier)などを扱っている。

 全体的に見て、QSVCの解説に重点が置かれている。数式はほとんど出てこないが、叙述は精緻であり、かなり深い。いくつかの種類のFeature Mapを使って量子カーネルを作る説明が優れている。さらに進んで、それらを組み合わせてSVC学習させること(Multi Kernel Learning)も試みている。それを、QiskitやPennyLaneなどの量子プラットフォームを用いて具体的に説明している。提供されている全てのコードは、私のローカル環境で完全に動かすことができた。

 初めてChapter4に達した人は、ちょっと戸惑うかもしれない。そこでは、20 featuresの1000サンプルからなる大きなデータセットに対して、(1)MinMaxScaling、(2)主成分分析による次元削減、(3)ZZFeatureMapによる量子状態生成、(4)量子カーネル行列の生成、(5)SVC学習、の全てを一気にデモするコードを解説しているからである。しかし、心配ご無用である。続くChapter5では次元削減が、Chapter6ではFeatureMapが、Chapter7では量子カーネルを使ったSVC学習が、詳細に説明されているからである。つまり、先に全体像が示され、その後、各論が続いている。

 大規模入力データの場合、Feature Mapと量子カーネル行列の作成、およびそれを用いた学習には、シミュレーションでは多くの時間を要する。本書は、プログラミングの本ではないが、その対策として、PennyLaneのライブラリとPythonのjoblibを使って、マルチコア向け並列処理コードも提供している。実際、私のM1-mac-mini(8コア)では、4倍を超える高速化が実現できた。

2025年4月18日金曜日

量子機械学習の第一歩QSVC(Quantum Support Vector Classifier)

【要旨】古典的手法では見つけられなかった(or できなかった)ことが、量子的手法では可能になったという事例があれば勇気付けられる。その一つとして、量子計算を用いたQSVC(Quantum Support Vector Classifier)が、古典SVCよりも高い精度で分類できる一つの例を示す。この例に対しては、古典SVCでは見つからなかった、新たな分類決定境界が、量子QSVCで見つけられたと言える。これは、量子機械学習に取り組む上で意義がある事例と思われる。

🔴対象としたデータセットGaussian-Parity
 今回用いたデータセットGaussian-Parityの一例を図1に示す。右側の表は、その内容である。2つの特徴量(Feature1、Feature2)とラベル(0 or 1)で構成される300サンプルが含まれる。これをMiniMax(0〜π)スケーリングして散布図にしたものが左側の図である。ラベル0とラベル1のデータが、斜めに交差して分布しているので、境界線を引くのは難しそうに見える。

🔴古典的SVCによるクラス分け
 
このデータセットに対して、まず、古典SVCでクラス分けした。300サンプルの7割を訓練用として学習させた結果を、残り3割のサンプルをテスト用として評価した分類の精度は81%であった。学習結果を反映した分類の決定境界を図2に示した。かなりよく分類できていると思われる。SVCの威力が感じられた。(SVCに与える種々のパラメータの値で結果は変動するが。)

🔴量子的QSVCによるクラス分け
 次に、量子的QSVCでクラス分けした。今回は、Qiskitに装備されているライブラリQSVCを量子回路シミュレーションで実行した。学習の条件はSVCの場合と同じである。分類精度は、90%となり、SVCの場合よりもかなり高まった。それは、図3に示す通り、図2とは異なる決定境界が得られたことによる。このように、SVCでは見つからなかった新たな決定境界が得られた理由は、(技術詳細は略すが)少ない量子ビットnでも、2のn乗次元の広い量子状態の空間を探索できることによるのであろう。すなわち、多様なカーネル行列と呼ばれる情報を古典的なSVCの仕組みに与えることができる。


🔴古典的SVCと量子的QSVCとの関係
 詳細は、別のブログ記事で後日議論したいが、図4に両者の関係の概要を示した。Javier Mancilla M.氏の著書"QML Unlocked"が非常に参考になったので、その中のFigure 16を引用し、加筆した。(この書籍のレビュー結果の記事も別途書く予定である。)

 QSVMも、学習(訓練)には、古典SVMの仕組みをそのまま使う。それができるようにするため、量子回路を用いて計算する所が2箇所ある。1箇所目は、元の入力数値データを量子状態にマッピングするQuantum Feature Mapである。さらにその前に、次元削減(主成分分析PCAなど)を施す必要がある。なぜなら、一つの特性(Feature)につき1量子ビットが必要なため、利用量子ビット数を抑えるためである。2箇所目は、マップされた量子状態同士の類似度を計算してKernel Matrixと呼ばれるものを作る部分である。このカーネル行列を従来のSVMの仕組みに与える。

🔴今後の予定
  1. Quantum Feature MapやKernel Matrixを構成する方法はいくつかあるので、それらも調査し、試行する。
  2. 量子コンピュータ実機で動かす。現状では、性能(計算速度)は古典コンピュータに及ばないが、実機での試行で得られる知見は貴重である。
🔴追加情報
 図2(SVC)に対する図3(QSVC)の優越性は、ある特殊なデータセットに関する偶然の結果なのか?そうではないことを願って、少なくとももう一例、優越性を示す必要があると考え、以下に別のケースも示した。先の例と同様に、QSVCの優越性が見られた!

2025年4月9日水曜日

Reduction of error occurrence in IBM quantum computer (Heron processor)

Theoretically, the success rate of Mermin-Peres magic, a 4-qubit application using quantum entanglement, is 100%. When this was executed on ibm_torino (Heron r1), the success rate was 92% due to errors caused by noise. This is a big improvement from the 86% success rate on ibm_brisbane (Eagle r3) a while ago. The reason for this is that the error rate was 14% on ibm_brisbane, but was reduced to 7.9% on ibm_torino. Figure 1 shows the details.


2025年4月8日火曜日

IBM量子コンピュータ(Heronプロセッサ)におけるエラー発生の低減

【要旨】量子もつれを用いた例題Mermin-Peres-Magicを、IBM量子コンピュータ新鋭機ibm_torino (Heron r1プロセッサ)で実行させた結果、ノイズ等によるエラーの発生率が、以前のibm_brisbane (Eagle r3プロセッサ)に比べて、ほぼ半減することが分かった。これにより、所望の正解が得られる成功率は、86%から92%に大きく改善された。今後出現するであろう華々しい成果は、このような長年の地道な研究開発によるものなのだと実感できた気がする。

🔴誤り低減を目指す量子コンピュータの進展
 Eagle(鷲)は攻撃的で強く、Heron(鷺)はしなやかで強いというイメージがあるという。IBMがそれを念頭において量子コンピュータに命名したのかは定かではない。IBMはこれまで、無償で量子プロセッサEagle r3(マシン名 ibm_kyiv, ibm_brisbane)を提供してきたが、この3月から、新鋭機Heron r1(マシン名 ibm_torino)を追加した。Heronは、Eaglelよりも、大幅にエラー発生率が低減されて強力になったという。そのハードウェアの仕組みは私には分からないが、最大の難題の一つであるエラー低減に向けて着実に進展していることが窺える。

🔴量子コンピューティングプラットフォームQiskitの更新
 IBMは量子コンピューティング開発環境Qiskitを頻繁にバージョンアップしているが、今回、Heronプロセッサの無償公開に合わせて、さらに大幅な改訂を行なった。そのための移行説明会もオンラインで行われた。実際、これまでの量子プログラムは環境を色々と修正しないと動かない状況である。だが、そこを何とか調べて、Heronプロセッサもようやく使えるようになった!!!

🔴量子もつれの例題「Mermin-Peres-Magic」をHeronプロセッサで動かす
 このHeronプロセッサの性能を十分に発揮できるような量子アプリを見つけることは容易ではない。しかし、自分がやれるアプリを少しづつ動かして、自分のスキルを高めることができるだろう。そういう思いで、量子もつれが本質的に効いている「Mermin-Peres-Magic」をやってみた。それがどんな問題かは、過去に書いたこちらの記事をご覧いただきたい。
 ごく簡単に言えば、この問題に対しては、古典的には100%成功する方法は無いが、量子的方法(量子もつれ)では、必ず100%成功させることができる。ただし、実際の量子コンピュータでは、ノイズ等による誤り発生のため、失敗するケースも出てくる。

🔴Heronプロセッサではエラー発生が着実に低減されていた!
 詳しいことは省略するが、図1をご覧いただきたい。この例題を実行した場合のエラーの発生率が、Eagleプロセッサに対して、約半減されることが分かった。すなわち、本来の得たい正解を得る場合の失敗率は、14.0%から7.9%に大幅に低減されたのである。これによって、正解を得る成功率は、86%から92%に上昇した。私自身の、しかも一つの例題の実測結果に過ぎないのだが、これによってモチベーションは確実に高まった!こうして、技術は進歩するものなのだと。


2025年3月26日水曜日

Introduction to two books on quantum computing

The number of books on quantum computing has been steadily increasing. Here, I’d like to briefly introduce two books I recently purchased, both of which I found to be excellent.

🔴Peter Y. Lee, Huiwen Ji, Ran Cheng: Quantum Computing and Information, Polaris QCI Pub., 2nd edition, Feb. 2025

First off, I was excited to see the publication date listed as 2025—and the book certainly lives up to that excitement! With 502 pages, its thickness alone hints at the density of its content. The material ranges from beginner to intermediate levels and is presented with numerous illustrations, making it a great choice for those who want to study carefully and in depth.

Published in February 2025, 502 pages total, chapter titles provided by me

The book begins by explaining the basic concept of quantum bits using photon polarization. It then progresses through topics such as quantum superposition, measurement, quantum gates, and quantum circuits. At this stage, it derives BB84, one of the foundational protocols for quantum key distribution.

Next, it devotes around 80 pages to a detailed discussion of quantum entanglement, including a thorough explanation of Bell's inequality. It also covers E91 (Ekert’s protocol), another important technique in quantum key distribution, as well as quantum teleportation—with clear examples using IBM Qiskit code.

Impressively, the book also ventures into applications from the NISQ era, including hybrid algorithms such as the Variational Quantum Eigensolver (VQE) and Adiabatic Quantum Computation (AQC), as well as quantum error correction techniques like the Bit-Flip, Phase-Flip, and Shor Code.

On the other hand, since it does not cover the Quantum Fourier Transform (QFT) or Shor’s algorithm for prime factorization, it may be a bit lacking for intermediate to advanced readers. That said, the co-authors are reportedly preparing a follow-up book focusing on more advanced applications, to be published by the same publisher. I’m very much looking forward to that release as well.

One important point worth mentioning: in many newer books, the example programs often contain errors or fail to run in readers’ environments, largely due to frequent updates in quantum computing platforms. However, the code provided in this book is carefully updated to match the latest Qiskit environment, and every example worked flawlessly in my local setup! This is incredibly important, as it motivates deeper exploration of the book’s contents.
Qiskit quantum app worked perfectly on my local environment

🔴Jack D. Hidary: Quantum Computing - An Applied Approach, 2nd edition, Springer, Aug. 2021

This second book is also a thick, full-color hardcover with a total of 422 pages, targeting beginners to intermediate learners. The latter 170 pages provide a detailed introduction to the basics under the section titled Mathematical Tools for Quantum Computing, so it may be a good idea to review this part first.

The quantum algorithm section in the first half overlaps somewhat with the content of the aforementioned book by Lee et al., but I was happy to see that it includes QFT (Quantum Fourier Transform) and Shor’s Algorithm, which were not covered in that book. For instance, it walks through the entire process (quantum + classical parts) of factoring the small integer 15 (= 3×5), which greatly enhances reader's understanding of the Shor algorithm. Moreover, the second edition includes new content related to Quantum Machine Learning, which is a big plus.

(Note) Factoring a slightly larger integer like 184573 (= 487×379) is considered difficult in simulations due to memory limitations, and on current quantum computers due to limitations in qubit count and error rates. However, simulation is still possible by replacing "quantum order finding" with "classical order finding."

Published in August 2021, 422 pages total

By the way, when you open this book, the Schrödinger equation appears right at the beginning—in other words, the wave function and the Hamiltonian. Since most books on quantum computing are computer science–oriented, this equation is rarely mentioned, which is a bit surprising. However, this is actually a very good thing, because both the quantum gate model and the quantum annealing method are said to originate from the time-dependent Schrödinger equation. Though the explanation spans only four pages, it clearly demonstrates, with a few equations, that “to understand the time evolution of a wave function, one must consider the total energy of the system.” Specifically, it derives the case of a harmonic oscillator potential, as shown below.

Schrödinger Equation – Harmonic Oscillator Potential

Also, please note that the quantum algorithm programs provided in the book are written in Google’s Cirq, not IBM’s Qiskit as mentioned earlier. These programs were created in an older Cirq environment than mine, and I encountered various errors when trying to run them. However, the official Google Cirq site provides examples very similar to those in the book, and I was able to run them perfectly in my Cirq setup! Using those as a reference, you should be able to run the remaining examples in the book as needed.

Examples from Google Cirq

🔴Note the differences between IBM and Google machines

Lastly, there's something important to keep in mind: the bit order in quantum registers is reversed in IBM Qiskit (Little Endian) and Google Cirq (Big Endian)! This is an easy mistake to make and can cause all sorts of confusion. For example, if the initial state of three qubits is |000⟩, applying X gates to q1 and q2 results in q0q1q2 → 011 in Cirq, but q2q1q0 → 110 in Qiskit. For more details, please refer to my earlier article, Testing My Mobile Quantum Circuit Simulator.


tinyurl-------   https://tinyurl.com/eaacxan2   -------


2025年3月24日月曜日

Quantum Computing書籍を新たに2冊購入

 量子コンピューティング関係書籍(特に洋書)の出版が増加している。なかには買ってみて残念な本もあったのだが、今回の以下の2冊はとても優れていると感じたので簡単に紹介したい。

🔴Peter Y. Lee, Huiwen Ji, Ran Cheng: Quantum Computing and Information, Polaris QCI Pub., 2nd edition, Feb. 2025

 まず、2025年出版という新しさに期待した。十分それに応えてくれるものだった!全502ページの厚みに内容の濃さが窺えるだろう。初級〜中級程度の内容が、豊富な図版とともに詳述されていて、じっくり学ぶのに適している。

2025年2月出版、全502ページ、章タイトルを記入してみた
 冒頭で、光子(Photon)の偏光を用いて、量子ビットの基本的な考え方を示している。そこから重ね合わせや測定、量子ゲート、量子回路へと繋げている。この段階で、量子鍵配送の基本の一つであるBB84を導く。次に、量子もつれに関しては、約80ページを費やして精緻に叙述している。この中には、もちろんBellの不等式なども含まれる。さらに、量子鍵配送の別の重要技術であるE91(Ekert)や量子Teleportationが、Qiskitコード例とともに良く説明されている。応用として、NISQ時代のハイブリッドアルゴリズム(VQE: Variational Quantum Eigensolver, AQC: Adiabatic Quantum Computation)や、誤り訂正(Bit-Flip, Phase-Flip, Shor Codeなど)の基本を含めるなど意欲的である。

 一方、QFT(量子フーリエ変換)やShor's Algorithm(素因数分解)が含まれていないので、中級以上の読者には少し物足りないかも知れない。実は、この共著者らは別途、さらに高度なアプリケーンを扱う別の書籍の出版を準備中であると、この出版社のWebサイトでアナウンスされているのでそれにも期待したい。

 特筆すべきことがある。比較的新しい書籍でも、そこに公開されている例題プログムを実行しようとしても種々のエラーが出て動かいないことが多い。量子計算プラットフォームの更新が頻繁なことがその主な要因である。だが、本書の場合は、Qiskitの最新環境によく追随したコードが提供されおり、全てが、私のローカルQiskit環境で完全に動いた!これはとても重要だ。それなら、中身をもっと詳しく探究しようという意欲が湧くからである。

ローカル環境で完全作動したQiskit量子アプリ

🔴Jack D. Hidary: Quantum Computing - An Applied Approach, 2nd edition, Springer, Aug. 2021

 この書籍も初級〜中級向けの全422ページの厚みのある、カラー版ハードカバーである。後半の約170ページは、Mathematical Tools for Quantum Computingという、初心者向けの基礎事項の詳しい解説になっているので、先にこちらを復習するのも良いだろう。前半の量子アルゴリズム関係は、上記のLee本と重なる部分も多いが、そこには無かったQFT(QUantum Fourier Transform)Shor's Algorithmが含まれていて安心する。たとえば、例題として、小さな整数15(=3x5)の素因数分解の過程(量子部+古典部)を全部追跡するのだから、Shorアルゴリズの理解は大いに深まるだろう。また、第二版になって、Quantum Machine Learning関係が追加されたのも大きい。

(注) 例えば、少し大きな整数184573(=487x379)の素因数分解は、シミュレーションではメモリ量の制約により、また、現状の量子コンピュータ実機では、搭載量子ビット数の制約とエラー発生などにより困難な状況と思われる。ただし、シミュレーションでは、「古典的な位数発見」を代用すれば実行は可能である。

2021年8月出版、全422ページ

 ところで、この本を開くと、冒頭にSchrödinger equation(シュレディンガー方程式)が出てくる。つまり、波動関数とハミルトニアンだ。通常、量子コンピューティングの本は(コンピュータサイエンス寄りなので)そういうことがなく、ちょっと驚く。だが、これはとても良いことだ。量子ゲート方式も、量子アニーリング方式も、その理論の源流は、ともに、時間依存シュレディンガー方程式にあるとのことだから。4ページだけの簡単な説明だが、「波動関数の時間変化を知るにはシステムの全エネルギーを見る必要がある」ことを少しの数式で示している。具体的には、以下のような調和振動子ポテンシャルの場合を導出して見せている。

シュレディンガー方程式(調和振動子ポテンシャル)

 さて、公開されている量子アルゴリズムのプログラムであるが、これは(上記のようなIBM Qiskitではなく)、GoogleCirqで書かれていることに注意する。当方の現在のCirq環境とは異なる環境のプログラムであるためか、いろいろなエラーが出て動かすことができなかった。しかし、これには救いがあった。GoogleのCirq公式サイトには、本書の例題にそっくりなものも載っていて、それらは、当方のCirq環境で完全に動いた!それを頼りに、本書の残りの例題も、必要に応じて動かすことができるだろう。

Google Cirqの例題の一部

🔴IBMとGoogleのマシンの相違に注意

 最後にもう一つ重要なことがある。IBM Qiskit (Little Endian)とGoogle Cirq (Big Endian)では、レジスタでのビットの並び順が逆になっている!これは間違いやすく、色々と影響がある場合が多い。例えば、3量子ビットの初期状態が|000⟩である場合、q1q2にXゲートを適用して測定した結果は、Cirqでは、q0q1q2→011となり、Qiskitでは、q2q1q0→110となる。これに関しては過去の記事Testing my mobile quantum circuit simulatorの中でも説明しているので参照願いたい。


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乗根である。