2025年6月6日金曜日

初夏の散歩道-厚木市郊外

 6月に入りまだ梅雨前ですが、初夏らしい日が続いています。散歩道(厚木市郊外)で写した数枚の写真をご覧ください。 2025年6月6日午前の散歩にて。

 かっての同僚の先生から、「もうトウモロコシが実っているのですか?北海道の感覚では、もっと後ですよね。そういえば、大通公園のとうきび売りの露店は本当に少なくなりました。」とのコメントをいただきました。そうなんですね。北海道では、「トウモロコシ」とは言わずに、「とうきび」と呼びます。でも、東京近辺に長年住んでいるとそれに合わせてしまったことに気が付く。懐かしい響き。

2025年5月22日木曜日

Holding the Quantum State of the Mermin-Peres Magic in the Palm of Your Hand

In my previous posts [here] and [here], I introduced the Mermin-Peres Magic Square. While there’s nothing particularly new in this post, I wanted to explore what it feels like to literally hold a quantum state in the palm of my hand. It’s just a plastic sphere I made as a hobby, but it gives me a more tangible sense of what a 4-qubit quantum state might be like.
Quantum state in the palm of my hand

For the corresponding quantum circuit and a detailed explanation, please see [here]. There’s no need to explain Figure 1—if you hold this ball in your hand, you’ll understand the depth of it...

From the initial state, through the generation of entanglement, to the final quantum state—it’s all captured inside this sphere! At first, I thought the 3D rendering from Qiskit’s QSphere would be enough. But once I actually built this physical model and held it in my hand, I realized it offered a somewhat different experience.
Fig.1 Quantum state of Mermin-Peres Magic (4-qubit)


2025年5月17日土曜日

Exploring Quantum Entanglement through Visualization

[Abstract]
The Mermin-Peres Magic Square is a well-known example that illustrates quantum entanglement. I have written related articles in the past (in Japanese, available [here]). This time, I aimed to deepen my understanding by visualizing the phenomenon, using four different methods:
(1)Display of a disk shape using my own simulator, (2)3D Qsphere representation with Qiskit, (3)Pauli correlation analysis, and (4)Measurement on IBM Quantum real hardware.

🔴Example: Tiny Mermin-Peres Magic

An explanation of this example is provided [here]. As shown in Fig. 1, Alice and Bob each possess two qubits. In the first half, their qubit pairs are prepared in an entangled quantum state, ǀψ₁⟩. After that, there is no further interaction between them. Nevertheless, when the final state ǀψ₂⟩ is measured, a strong correlation is observed between their outcomes (as shown later in Fig. 2 and Fig. 3). Specifically, the number of "1"s in the 2-bit classical measurement results is always even for one party and odd for the other. This reveals a strong inverse (or anti-) correlation.

🔴Confirmation Using a Homemade Quantum Circuit Simulator

Figure 2 shows the results of verifying the behavior of this example using a homemade quantum circuit simulator. The probability and phase of each basis state are displayed on a disk. In addition, numerical lists of the probability amplitudes, probabilities, and phases are provided.

For example, in the quantum state ǀψ₁⟩, if Alice's qubits are in the state ǀ00⟩, Bob's qubits will definitely be in the state ǀ11⟩. In the final state ǀψ₂⟩, if Alice is in the state ǀ00⟩, Bob's state will be either ǀ01⟩ or ǀ10⟩. It is also possible to confirm whether the total number of "1"s in the measured classical bitstrings is even or odd, as described earlier. In other words, this disk representation allows us to visually understand the quantum entangled state shared between Alice and Bob.

🔴3D display of quantum states using Qiskit's Qsphere

Quantum entanglement cannot be separated into individual qubit states, so quantum states cannot be displayed individually on a Bloch sphere. However, by using Qiskit's Qsphere, it is possible to simultaneously display all possible basis states on a sphere, as shown in Fig. 3. Here, the size of the circle at the tip of the quantum state vector is the probability value, and the color indicates the phase. It matches well with the disk display in Fig. 2.


🔴Indication of the strength of quantum entanglement by Pauli correlation

One way to investigate the quantum entangled state in more detail is the Pauli correlation measurement. This is based on the fact that, for example, the expectation value when the quantum state ǀψ⟩ is measured on the Z axis is calculated as follows: ⟨ZZ⟩ = ⟨ψǀ Z⊗Z ǀψ⟩

As an example, for the Bell state ǀψ⟩ = (ǀ00⟩+ǀ11⟩)/√2, calculations show that ⟨ZZ⟩ = 1, which means that the Z measurements of the two qubits are correlated in exactly the same direction. On the other hand, for the simple tensor product ǀψ⟩ = ǀ01⟩, ⟨ZZ⟩ = -1, which shows a strong correlation in the opposite direction but is not entangled.

In Fig. 4, in addition to the Z measurement, X and Y measurements are also performed. Although the above Pauli measurements can calculate correlations, they do not necessarily fully reflect the "quantum entanglement". Therefore, in some cases, measurements other than the Z measurement may be performed.
In Fig. 4, ZZ(q2,q3) on the horizontal axis is the ⟨ZZ⟩ calculation for Bob's quantum bit, and ZZ(q0,q1) on the vertical axis is the ⟨ZZ⟩ calculation for Alice's quantum bit. The color of the square at the intersection represents the product of their values ​​(expectation values). The darker the red, the closer it is to +1.

In the state ǀψ1⟩, if the Z measurement results of Alice's two qubits are in the same direction, then the Z measurement results of Bob's two qubits will also be in the same direction. If, on the other hand, the Z measurement results of Alice's two qubits are in opposite directions, then the Z measurement results of Bob's two qubits will also be in opposite directions. Such a strong correlation is also observed in ⟨XX⟩ and ⟨YY⟩, so they can be said to be in a fully entangled state.

On the other hand, in the state ǀψ2⟩, the Z measurement of the two qubits will have the same direction for either Alice or Bob, but different directions for the other. Therefore, it makes sense that the squares in the right panel of Fig. 4 are dark blue (the product of the expectations is -1).
 
🔴Measurement results on an actual IBM Quantum computer

Finally, Fig. 5 shows the measurement results on an actual IBM Quantum computer. This is the result of 10,000 shots performed on one of the most advanced machines, ibm_torino (Heron r1). Although there are some errors (likely due to noise) in both the measurements for the quantum states ǀψ1⟩ and ǀψ2⟩, the results well support the calculation results shown in Fig. 2, Fig. 3, and Fig. 4. It is once again amazing how far quantum computers have progressed!

2025年5月16日金曜日

可視化で量子もつれの理解を深める

【要旨】量子もつれを利用した例題の一つにMermin-Peres Magicがある。関連記事は過去にも書いてきた。(ここです)今回は、ビジュアル化によってさらに理解を深めたいので、量子状態の表示と分析を4通りの方法で行なってみた。①自作シミュレータでの円盤表示、②QiskitのQsphereによる3D表示、③パウリ相関測定、④IBM Quantumマシンによる実測である。

🔴例題Tiny Mermin-Peres Magic
 この例題の説明はここ示した。Fig.1に示す通り、AliceとBobはそれぞれ2量子ビットを保有している。両者の量子ビット対は、前半で量子もつれの状態 ǀψ1⟩となる。それ以降は両者のインタラクションは無い。それにもかかわらず、最終状態 ǀψ2⟩を測定すると、(後でFig.2やFig.3に示すように)両者に強い相関が見られる。すなわち、両者の測定結果の古典2ビット列に含まれる"1"の個数は、必ずどちらかは偶数個であり、他方は奇数個になる。いわば逆向きの強い相関である。

🔴自作量子回路シミュレータによる確認
 この例題の動作を、自作の量子回路シミュレータで確認した結果をFig.2に示す。起こり得る基底状態の確率と位相が円盤に表示される。また、確率振幅、確率、位相の数値リストも表示されている。
 例えば、量子状態 ǀψ1⟩では、Aliceがǀ00⟩ならばBobは必ずǀ11⟩となる。最終状態 ǀψ2⟩では、例えば、Aliceがǀ00⟩ならばBobはǀ01⟩か又はǀ10⟩となり、上述した測定古典ビットでの"1"の個数が偶数か奇数も確認できる。すなわち、この円盤表示から、両者の量子もつれの状況を掴むことができる。

🔴QiskitのQsphereによる量子状態の3D表示
 量子もつれ状態は、個々の量子ビット状態に分離できないので、Bloch球に個別に量子状態を表示することはできない。しかし、QiskitのQsphereを利用すると、Fig.3に示す通り、起こり得る基底状態を同時に球面に表示することができる。ここで、量子状態ベクトルの先端の円の大きさは確率の値であり、色は位相を示す。Fig.2の円盤表示と良く合致している。

🔴パウリ相関による量子もつれの強さの表示
 量子もつれ状態をさらに詳しく調べる方法の一つはパウリ相関測定である。これは、例えば、量子状態 ǀψ⟩をZ軸測定した場合の期待値が以下のように計算されることに基づく。
⟨ZZ⟩ = ⟨ψǀ Z⊗Z ǀψ⟩
 一例として、ǀψ⟩ = (ǀ00⟩+ǀ11⟩)/√2というベル状態の場合は、計算してみると、⟨ZZ⟩ =1となる。これは2つの量子ビットのZ測定結果が確実に同じ方向になる相関を意味する。一方、ǀψ⟩= ǀ01⟩という単なるテンソル積ならば、⟨ZZ⟩ = -1となり、逆向きの強い相関を示すが、量子もつれではない。
 Fig.4では、Z測定に加えて、X測定とY測定も行なっている。上記のような各パウリ測定は、相関を計算できるが、必ずしも「量子もつれ」を完全に反映したものではない。そのため、場合によっては、Z測定以外の測定を行うことがある。
 Fig.4の横軸のZZ(q2,q3) は、Bobの量子ビット状態に対する⟨ZZ⟩ であり、縦軸のZZ(q0,q1) は、Aliceの量子ビット状態に対する⟨ZZ⟩ である。そして、その交点に示された正方形の色は、それらの値(期待値)の積を表現している。濃い赤色ほど+1に近い。
 状態 ǀψ1⟩においては、Aliceの2量子ビットのZ測定結果が同一方向ならば、Bobの2量子ビットのZ測定結果も同一方向となる。あるいは、AliceとBobのZ測定結果は、ともに異なる方向となる。そのような強い相関が、⟨XX⟩ と⟨YY⟩ でも観測されるので、両者は完全なもつれ状態にあると言える。
 一方、状態 ǀψ2⟩では、2量子ビットのZ測定結果は、AliceとBobのどちらかでは同じ方向となり、他方では異なる方向となる。したがって、Fig.4の右側の図の正方形は濃い青色(期待値の積は-1)になることは納得できる。
 
🔴IBM Quantum コンピュータ実機での測定結果
 最後に、IBM Quantum実機での測定結果をFig.5に示す。最新鋭機の一つibm_torino(Heron r1)で、10,000 ショット実行した結果である。量子状態 ǀψ1⟩と ǀψ2⟩での測定とも、若干のエラー(ノイズによると思われる)が生じているが、Fig.2、Fig.3、Fig.4で示した計算結果をよく裏付ける結果となっている。量子コンピュータが、ここまで進歩してきたことに改めて驚く次第である!

2025年5月9日金曜日

最新版Qiskit2.0を利用した量子コンピューティングの解説書

 IBMの量子コンピューティング開発プラットフォームQiskitは、頻繁に改訂されることで有名だ。研究開発が活発な証しではあるが、時として以前に書いたコードが動かなくなる状況が発生し、困ることも多い。直近では、かなり大幅な改訂版となったQiskit2.0が公開されている。IBMのサイトに関連ドキュメントはあるが、これを取り上げた書籍は(和書、洋書とも)まだ見当たらないと思っていた。ところが、以下の和書が早くも出版されていることを知り驚いた!
中山茂、Qiskit2.0 量子コンピューティング入門、2025年5月
🔴本書の特徴(深い理論も実際に動くコードでイメージを掴みやすい)
 著者の中山茂教授は、これまでもタイムリーに量子関連書籍を多数執筆されている。彼の著書では、量子コンピューティングに関するかなり深い理論も、量子回路シミュレータや量子コンピュータ実機で実際に動くコードを示して、分かりやすく説明している。それが最大の特徴と言える。それによって、読者はイメージを掴みやすく、より深く理解しようという意欲が湧く。

 本書(全214頁)の内容は、量子コンピューティングの基本から始まり、量子テレポーテーション、グローバー探索、量子フーリエ変換、ショアの因数分解といった重要なアルゴリズムをカバーしている。そして、ショアの因数分解に等に現れる量子/古典のハイブリッドアルゴリズムが、現状では実際的であることを強調している。実際、ショアの因数分解では、古典的には困難なモジュロ冪函数の周期発見を量子アルゴリズムで、そして、その後のユークリッド互除法を古典的に行う方法を、実際に動くコードを使って詳細に説明している。

 実は、さらに素晴らしいと感じたのが第4章(量子非局所性と期待値計算)である。ここでも、Qiskitコードを使って、量子物理学の根幹に関わる量子非局所性を説明している。すなわち、ベル状態でのテンソル積の期待値測定の量子回路を組んで、その測定結果を示しながら量子非局所性を実験的に証明している。

🔴量子状態 ∣ψ⟩に対する演算子Aの期待値 ⟨ψ∣A∣ψ⟩
 上に述べた「ベル状態でのテンソル積の期待値測定」の一つを具体的に見てみよう。
 例えば、ベル状態の一つを ψ = (1/√2)(∣01⟩+∣10⟩)とする。その時、⟨ZZ⟩=⟨ψ∣Z⊗Z∣ψ⟩は、パウリZ演算のテンソル積(行列)の期待値を与える。その値は、(具体的な展開計算は略すが)-1となる。これは、2つの量子ビットに対するZ基底測定が、それぞれ異なる値(0 or 1)となることが確実なことを意味する。そのような逆向きの強い相関である。
 このことを、QiskitのStatevectorクラスを使ったQiskitコードを作り確認している。すなわち、それを実行させると測定値が-1となり、手計算の結果と合致すること分かる。
(以下の図は、本書に載っているものではなく、私が用意した参考図である。)

2025年5月5日月曜日

IBM Quantum無料枠の利用可能時間の計算が変更になった!

 IBM Quantum無料利用枠の新しい計算方法:最近気付いたことだが、私にとってはちょっと重要事項なので書き留める!

 IBM Quantumの無料プラン(Open Plan)における利用時間の計算方法は、これまでの「28日毎にリセットされる固定制」から、「直近28日間のローリングウィンドウ制」に変更さた!ただし、IBM Quantum の新しいプラットフォーム(early access)の場合である。6月末まで利用可能な旧プラットフォームはそのままのようだが。
Here’s the image illustrating the change in IBM Quantum’s free usage calculation method.
An example

🟢変更前:固定制(28日毎に自動リセット)
 これまでは、Open Planの利用時間は28日毎に0:00 UTCにリセットされ、28日あたり最大10分間の量子計算時間が提供されていた。

🟢変更後:ローリングウィンドウ制(直近28日間)
 現在は、直近28日間の累積利用時間が10分間に制限される「ローリングウィンドウ制」が採用されている。28日経過しても、自動的にまた10分間使えるようにリセットされることはない!

 この変更により、過去28日間の利用状況に応じて残り時間が変動するので、それを念頭に量子コンピュータ実機を使わなければならない。これが本来の姿かも知れない。

2025年4月29日火曜日

御礼:ブログページビュー(アクセス数)20万回超え

🔴感謝:本ブログへのアクセス回数が20万回に到達
 2016年末に開設したこのブログ、このほど、20万回webビュー(アクセス)に達した。直近の約130件(これまでの総計は約500件)はほとんど量子コンピューティングに関する記事である。ブログアイコンもそれらしくした。ご愛読、そして、フィードバックしていただいた方々に御礼申し上げたい。


🔴実用的な量子コンピュータへの道は険しい
 最近、国産の256量子ビット(世界最大規模の)コンピュータが開発されたというニュースがあった。素晴らしいことだが、その発表には、実用問題を解くには最低6万量子ビットを要するうえ、現在は達成されていないノイズ耐性が必要ということが含まれていた。すなわち、これで世界が変わった!というわけでは全くない。その先はとてつもなく険しそうだ。

 この業界の巨人IBMのロードマップでも、2025年に156x7 = 1092量子ビットでError suppression and mitigation(誤り抑制と緩和)、2026年以降にError correction(本格的に?誤り訂正)となっている。例えば、Shor's素因数分解アルゴリズムの実用化には、100万量子ビットが必要との情報もある。研究開発は続く... 。私もできるだけ学び、少しづつ前へ進み、ブログ記事も続けたい。

 そんな厳しい状況だが、大手企業やベンチャー、大学などでは多くの人々が活発に量子コンピューティングに関して、論文やSNSでの発信を行なっている。それは、ますます増える傾向にある。私自身も、わずかながら、そういう人たちと何らかのつながりを持とうとしてやっている。

🔴本ブログ記事を査読、引用、掲載して戴いた方々に感謝
 これまでに下記の方々に、量子コンピューティングに関する私のブログ記事を査読参照掲載して戴いた。とてもありがたいことである。すでに、それらに関する記事は個別に掲載済みだが、ここ改めて感謝したい。

(1) Chris Bernhardt (Prof. of Mathematics at Fairfield University)
・掲載サイト:Chris Bernhardt info

(2) Isaac L. Chuang (Prof. of Physics MIT), Selim Tezel (MIT App Inventor Education Team Lead)
・掲載サイト:MIT App Inventor Stories from the Field, 理化学研究所 Q-Potal

(3) Nivio dos Santos (Product Manager at Avalara Brasil)
・掲載サイト:http://www.nivio.com.br/

(4) Javier Mancilla Montero (PhD in Quantum Computing, Quantum Machine Learning Researcher)
・掲載サイト:Linkedin記事
・当方の元記事:Visualizing and Understanding QSVC

(5) Peter Y. Lee (Ph.D. in EE from Princeton, faculty member at Fei Tian College)
・掲載サイト:Polaris QCI Publishing Web site

2025年4月28日月曜日

A Basic Mathematics Book for Learning Quantum Computing

In the previous article, we introduced a new book on quantum computing. However, many people may want to first learn basic mathematics before reading such books. I would like to briefly introduce the following book as one such book. Generally speaking, the relationship between this book and the previous one is as follows:

Peter Y. Lee, James M. Yu, Ran Cheng :Mathematical Foundations of Quantum Computing, Polaris QCI Publishing, 2025.

This book is a large volume of 539 pages. It provides a very thorough explanation of the basics of mathematics related to quantum computing. Parts 1 and 2 are basic mathematics, mainly linear algebra. However, since Dirac Notation (bra-ket) is already used here, it becomes clear that this is not purely basic mathematics, but is aimed at quantum computing. The authors explain that readers who have already mastered the basics of linear algebra can skip these parts and move on to Part 3. Even for such readers, Part 2 is very useful for reviewing points that they may have forgotten. In other words, this book also serves as an encyclopedia.

In the third and fourth parts, the most important operations in quantum computing are explained in detail, with a focus on "Tensor products". Although it is not very noticeable, it is worth noting that the "Change of Basis" introduced in the second part is explained in more detail in this third part. This will be important in many fields,  including quantum key distribution later. You will also see that the "Kronecker Product" is important in simplifying quantum computing. More advanced content such as "Singular Value Decomposition" is also included. Furthermore, one of the outstanding features of this book is that "Probability", another foundation of quantum computing, is dealt with extensively in the fourth part.

At the beginning, there is a "Level Indicator" explanation, which is useful for understanding the level of difficulty of the content. However, it would be even better if it had a marking to indicate which of the minimum necessary knowladge is required to read the second book, "Quantum Computing & Information." This is because this book contains a huge amount of content, and some people want to study efficiently. For example, it may be okay to skip "Discrete Fourier Transform" and "Markov Chains" for the time being.

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倍を超える高速化が実現できた。