ラベル Quantum machine learning の投稿を表示しています。 すべての投稿を表示
ラベル Quantum machine learning の投稿を表示しています。 すべての投稿を表示

2025年8月19日火曜日

量子機械学習でIBM認定資格を取得

 IT分野では、資格認定が色々あります。量子コンピューティングの世界もそうなってきました。今回、量子機械学習(QML : Quantum Machine Learning)の基礎に関するIBM認定資格を取得しました。下図はそのデジタルバッチと認定証です。勉強や探求を続けるには、このようなマイルストーンがあるといいですね。

Earned IBM Certification in Quantum Machine Learning
In the IT field, there are many different kinds of professional certifications. Now, the world of quantum computing is beginning to follow the same path. This time, I obtained an IBM certification on the fundamentals of Quantum Machine Learning (QML). The image below shows the digital badge and certificate. Having milestones like this is a great motivation to keep studying and exploring further.

(→こちらに、その後取得した「量子変分アルゴリズム」認定資格があります。)

🔴IBM認定資格の意味
 IBMでは量子コンピューティング分野のいくつかの資格認定を、Foundational、Intermediate、Advancedに分けています。今回の資格(Intermediate)認定バッチは、例えて言うならば、「量子機械学習」という山岳への入山許可証みたいなものかと思います。道は険しく、まだまだこれからです。デジタルバッチの右下にある、登りかけの階段が象徴的です!

🔴IBMの量子コンピューティング関係チュートリアル
 量子機械学習関係の書籍はまだあまり多くないです。そんななか、IBMが提供している様々な量子計算チュートリアルの一つ、「量子機械学習」は非常に充実した内容になっています。以下のURLをご覧ください。

⭐️量子コンピューティングチュートリアル全体
    https://quantum.cloud.ibm.com/learning/en

⭐️量子機械学習チュートリアル
    https://quantum.cloud.ibm.com/learning/en/courses/quantum-machine-learning

 従来からの公開内容が、2025-07-01の開発環境の一新に伴い、大幅に改訂されています。(1)古典機械学習との関係、(2)古典データの量子化のためのEncoding、(3)Fidelityと量子カーネル、(4)QVC(量子変分回路分類器)とQNN(量子ニューラルネットワーク)などで構成されています。

 このチュートリアル全体の学習には、(経験による個人差が大きいですが)標準的には10時間程度。何ヶ所かに、そのセクションを要約した短いビデオがあり、大いに助かりました。また、理論と計算法の説明に加えて、シミュレータおよび量子コンピュータ実機で動かす例題もあり、コードを実行させながら理解を深められます。

 この講座全体を終えた後、1時間ほどのオンライン試験を受けます。守秘義務のため試験内容等は書けませんが、合格ラインは80点/100満点です。不合格になっても、一定期間後には、再挑戦できる教育的配慮もなされています。

 ただし、前提条件として、量子ビットと量子ゲートの基礎(重ね合わせ、確率振幅、相対位相、テンソル積、ユニタリ変換、エルミート行列、量子もつれ、観測量、測定など)、および、量子計算プログラム開発環境にも、ある程度馴染んでいる必要があります。そうでない場合は、下記の講座からスタートするのが良いと思います。
 ⭐️量子情報の基礎
    https://quantum.cloud.ibm.com/learning/en/courses/basics-of-quantum-information

🔴情報工学科ではどうする
 
世の中の関心も高いので、情報系学科では、量子コンピューティング基礎科目を設置するところが増えています。現時点では実用的でなくても、このような先進分野の魅力を教えてこそ大学、という見方もあるでしょう。一方、そんな時間があるのなら、急成長の生成AIやAIエージェント技術をうんと教えて、就職させた方いい、と言えるかもしれない。0か1かではないこの状況が、まさに量子力学的であリます!

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年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などを使って集めた知識の羅列を体裁を整えて出版しただけというのがあった。買ってしまって憤慨ということもあった。大手出版社ではない、個人出版のような書籍には特に要注意と思われる。