2025年7月19日土曜日

量子風鈴?で涼しさを

 猛暑に風鈴はいいものだ。ただし、チリンチリンと、時に耳障りになることもある。そこで、音は出ないが、量子ビットの不思議な世界を想起させる「量子風鈴」なるものを私の研究部屋に吊るしてみた。

熊本城天守閣から吊り下げられたかのような量子風鈴

「量子風鈴」のある研究室風景
 熊本城のカレンダーの前に、透明プラスチック球体が3個吊るされている。これらの球体については何度かこのブログの記事にしてきたので詳細は略します。中央とその下にある2個はBloch Sphereであり、単一量子ビットの状態とそれに対する基本的な量子論理ゲートを射影演算子で表現している。一番上の球体は、4量子ビットのもつれた状態をQ-Sphereで可視化している。

 扇風機の風に乗ってゆらつらするので、少しは涼しげな気分になる。だが実は、それ以上に、量子コンピューティングの世界を探求して行く意欲を持続させるための"おまじない"でもある!

生成AIの判断が、人間の感覚に近かった一つの例

 Webに掲載されたある記事のタイトルが以下のようになっていました。
 (句読点や文章中の空白は原文のままです。)

住宅地でヒグマ駆除、ハンターがライフル銃で 死者出た北海道福島町
 このタイトルを読んだ人は、撃たれたのはヒグマなのか、人間なのか、直ぐにわかるでしょうか?私の第一印象は、「おやっ、何かおかしなタイトルだなあ」ということでした。そこで、生成AIにも判断してもらいました。結論として、現代の生成AIは、(少なくとも本例に関しては)人間の感覚と近いところに来ているということでした。

🟢[生成AI - a]の回答
 非常に曖昧で、文を読んだだけでは「誰が撃たれて死亡したのか」が明確に伝わりません。「ヒグマ駆除」という言葉から、「ヒグマが撃たれた」とは読み取れます。しかし「死者出た」という語句が続くため、人間の死者が出たのか、ヒグマのことを指しているのかが不明瞭です。特に「ヒグマ駆除」と「死者出た」が同列で並べられているため、「駆除の過程で人が撃たれて死亡した可能性」まで想起させてしまいます。

🟢[生成AI - b]の回答
 このタイトルだけでは、撃たれたのがヒグマなのか、人なのかは分かりません。「死者出た北海道福島町」という部分が、撃たれた結果亡くなったのがヒグマなのか、あるいは別の要因で人が亡くなったのか(例えば、ヒグマに襲われて亡くなった、または駆除作業中に事故で亡くなったなど)が不明瞭だからです。文脈として「ヒグマ駆除」とあるので、ヒグマが死んだことは示唆されますが、「死者出た」が誰を指すのかが明確でないため、このタイトルだけでは判断できません。記事本文を読む必要があります。

2025年7月16日水曜日

稲作について生成AIに聞いてみた

 お米の値段、流通が話題になっています。近所を散歩していて、すっかり少なくなった水田ですが、まだ7月中旬だというのに、写真の通り、水田に水が全く無い!ひび割れしているじゃないですか!これじゃ不作になって、米の値段がさらに高騰するのではないか?

「中干し」でひび割れした水田(厚木市 2025-7-15)

 違いました!これは、梅雨明け前後に行われる、稲の生育を調整する手法で「中干し」と呼ばれるものでした。水を一時的に抜くことで、田んぼの表面を乾かし、酸素を取り込める様にして根の健全な発達を促す効果があるとのこと。田んぼをひび割れさせることで、土中に溜まった有害なメタンガスなどを排出させる、また、病害虫を防ぐ効果もある。水をなくすことで、稲に適度なストレスを与えて、育成を調整することにもなるらしい。

 いつ頃からこのような手法が取られていたのか?生成AIからの回答によれば、江戸時代中期にはすでに行われていた。つまり、水の管理の基本として、灌漑と排水が行われていた。17世紀末に書かれた「農業全書」(宮崎安貞著)には、「中干し」を指すと思われる以下の叙述があるという:

「分げつ過多の稲は倒れやすし、時に水を抜きてこれを止むるべし」

🟢感想
 私は、普段、量子コンピューティングやPythonプログラム開発に生成AIを使っている。だが、今回の様な調べ物にも、とても有用だと分かる。時代は変わってきた。今後はさらに、AIエージェントが、人に変わって勝手に?調べ物もしてくれるらしい。昨日、ソフトバンクからその事業化の発表もあった。小学生の夏の自由研究なども様変わりするだろう。ああ!

2025年7月4日金曜日

IBM Quantum Composer - 惜しまれてsunset

----重大な修正------- Composerはsunsetではなかった!2025-07-08 JST確認したところ、New Platformへ移行した後も、Composerは従来通りOpen Planで利用できることが分かった!(ただし、ファイルはローカルに保存するように変更された。それをアップロードすることはできる。)こちらのポストが参考になる。これは力強い!
--------------------------

(元記事はこのままにしておきます。)

【要旨】
量子コンピューティング教育上の優れたプラットフォームIBM Quantum Classic Platformが、2025年7月1日をもって終了(sunset)となった。数ヶ月前から予告があり、完全に new platformへ移行した。小生も準備済みだったので特に問題はないのだが、こんな素晴らしい開発環境、特にその中のComposer(作曲家)という機能を惜しんで、以下に記録しておきたい。

🟢IBM Quantum Platformからの通知(2025-07-01)
 下図の通りである。量子コンピュータハードウェア開発競争の激化が背後にあるようだ。初心者向けの環境から、よりプロフェッショナルな利用のサポートにシフトしたように思われる。ともかく、このPlatformでのOpen Plan(無償)はもはや使えないことが分かる。私は、2年間ほど愛用してきた。図にある通り、これまでに865件のジョブを投入した。小さな量子回路ではあるが(基本的な量子アルゴリズムである、BB84、Ekrt、Grover、Superdense Coding、Teleportation、Simon、Phase Kickback、Phase Estimation, QFT等々)を探求した。その利用経験から得られた知見は、現在とても役立っている!!!その後の、Quantum Machine Learningへの取り組みにも繋がった。大いに感謝したい。
IBM Quantum Classic Platformのサービス終了

🟢量子コンピューティングの全ての操作を一括提供のComposer
 このClassic Platformにおいて、特に使いやすく有用であったComposer機能を振り返り、記憶に留めたい。ログインすると、その場で、以下の項目を一気に実施することができたのである!

(1)ビジュアルに量子回路を編集し、シミュレートする
(2)その量子回路の状態の表示(Q-Sphere、Probability、StateVector)
(3)OpenQSAM(手動量子回路編集)との連携
(4)IBM Quantumマシン実機での実行と結果の取得

量子回路の編集と量子状態表示(Q-Sphere, Probability, StateVector)
OpenQASM(右側)との連携

🟢新しいプラットフォーム(IBM Quantum New Platform)
 新しいプラットフォームでは、上記の様なWebサービスは終了となった。それらと同等のことは、各自がローカルにQiskit環境を設定して行うことになった。しかし、(詳細は略すが)新しい様々な機能が新たに使えるようになった。特に、これまでOpen Planでは使えなかった新鋭の実機 ibm_torino(Heronプロセッサ)が利用可能となったことは大きい!

2025年6月23日月曜日

Comparison of Kernel PCA on Gaussian and Quantum kernel

Auto-translated from Japanese.

[Abstract]
The ad_hoc_data dataset is commonly used in research exploring quantum methods for data classification. An example of applying the KPCA (Kernel Principal Component Analysis) method to this dataset is provided in the IBM tutorial "Qiskit Machine Learning 0.8.3". In the tutorial, a comparison is made between a Gaussian kernel (the classical RBF kernel) and a quantum kernel (based on the ZZFeatureMap). The results demonstrated an example of quantum advantage. This article revisits and reaffirms those findings.

🔴 Characteristics of the Input Dataset: ad_hoc_data
This is an artificial dataset designed to make linear separation (classification) difficult for classical methods but easier for quantum techniques. Although it lacks practical applications, it is often used in studies of quantum advantage. Specifically, the dataset is constructed so that classification is challenging with classical kernels (e.g., Gaussian RBF), but effective with quantum kernels based on quantum feature maps such as ZZFeatureMap. It is primarily a binary classification dataset (labels 0 and 1), split into training and test sets.

    A key parameter, gap, controls how easily the classes can be separated. Larger values generally make the separation easier. Figure 1 shows the sample distribution. The samples for classes 0 and 1 are grouped into small clusters, making linear separation appear difficult.


🔴 Mechanism of KPCA (Kernel Principal Component Analysis) and Classification
KPCA is an extension of traditional PCA using the kernel trick, allowing it to effectively handle datasets with nonlinear structures. First, the input data is implicitly mapped into a high-dimensional feature space using a kernel function. In that space, similarities between samples are calculated, forming a kernel matrix (see Fig. 2). The kernel can be either a classical kernel (e.g., Gaussian RBF) or a quantum kernel (e.g., using a quantum feature map).

    Next, PCA is applied to this kernel matrix to project the data onto the principal components (or, reduce dimensionality).

    At this stage, we are only preparing for classification — no label information is used yet. Interestingly, when constructing a kernel matrix based on fidelity (similarity) using the ZZFeatureMap, a class-like structure (similar to clustering) can emerge even without using labels, particularly in datasets favorable to quantum kernels such as ad_hoc_data. That is, a block-like structure becomes visible in the heatmap of the kernel matrix.

    Figure 2(a) demonstrates this clearly. Most of the data pairs with label 0 (indices 0–49) form a high-similarity block (dark green), as do those with label 1 (indices 50–99). By contrast, in the classical Gaussian kernel case (Fig. 2(b)), this block structure is much less evident.


    After this stage, we proceed to supervised learning by incorporating label information. While Support Vector Classification (SVC) could be used, we opted for Logistic Regression due to its simplicity and compatibility with quantum kernels such as ZZFeatureMap-based.

    The classification results are shown in Fig. 3. They appear to reflect the structure seen in the kernel matrix of Fig. 2. Indeed, the test accuracy was 0.95 using the quantum kernel (Fig. 3(a)) and 0.6 with the classical kernel (Fig. 3(b)). This provides an illustrative example of the potential benefits of quantum kernels.

🔴Reference [Qiskit Machine Learning 0.8.3]

カーネルPCA法における古典カーネルと量子カーネルの比較

[要旨]データのクラス分けに関する量子的手法の研究用として、ad_hoc_datasetがある。これに、KPCA法 (Kernel Principal Component Analysis)を適用する例が、IBMのチュートリアル "Qiskit Machine Learning 0.8.3"にある。その中で、Gaussianカーネル(古典rbfカーネル)と量子カーネル(ZZFeatureMapに基づく)を適用した場合の比較がある。結果として、量子優越性を示す例となっていた。本記事では、これを再確認した。

🔴入力データセット ad_hoc_dataの特徴
 これは、古典的な方法では線形分離(クラス分け)が難しいが、量子的手法ではそれが容易になるように設計された人工的データセットである。実用性はないが、量子優位性(quantum advantage)の研究などで利用される。すなわち、古典的なカーネル(GaussianカーネルRBF等)では分類が難しいが、量子特徴マップ(ZZFeatureMap等)に基づく量子カーネルではうまく分類できるように構成されている。主にバイナリ分類用のデータセット(ラベル 0 と 1)であり、トレーニングセットとテストセットに分けられる。

 このデータセットの生成用のパラメータの一つであるgapは、クラスの分離性を決める。この値が大きいほど、クラス分けは容易になる傾向となる。Fig.1にそのデータサンプルの分布を示す。クラス0とクラス1のデータがそれぞれ小さなグループとなって散在しており、線形分離は困難のように見える。

🔴KPCA(Kernel Principal Component Analysis)の仕組みとクラス分け
 KPCAは、"非線形構造データ"の分類に有効なように、通常の主成分分析PCAをKernel Tickによって拡張したものである。すなわち、まず、カーネルを使って、入力データを暗黙的に高次元空間に写像し、その空間での特徴表現(データサンプル間の類似度の計算)を行う。結果としてFig.2に示すようなカーネル行列が得られる。カーネルとしては、古典カーネル(Gaussianカーネルrbf等)や量子カーネル(Quantum Feature mapに基づく)を使うことができる。これに続けて、主成分分析PCAの手法を適用して、その空間での主成分への射影(または次元削減)を行う。

 ここまでは、クラス分類のための準備であり、分類学習はしていない。クラスを示すラベル情報も全く使っていない。しかし驚くべきことに、ad hoc datasetのような量子カーネル向きのデータセットに対して、ZZFeatureMap を用いた fidelity(類似度) に基づくカーネル行列を構成すると、クラス構造(クラスタリング的な構造)が浮かび上がる場合がある。つまり、ラベル情報がなくても、カーネル行列のヒートマップを見ると、ブロック構造(クラスタ)が現れる。

 Fig.2(a)は、まさにそれを示している!すなわち、ラベル0のデータ(番号0〜49)のペアは、ほとんどが高い類似度(濃い緑色)を示すブロックになっている。ラベル1(番号50〜99)についても同様である。しかし、これに反して古典Gaussianカーネルの場合(FIg.2(b))は、そのようなブロック構造が明瞭でない。
 さて、この後、カーネル行列に加えて、ラベル情報を用いた教師付き学習を行う。その際の分類学習器としてSVCを使っても良いのだが、ここでは、より軽量でZZFeatureMapとの相性も良いとされるLogistic Regression(ロジスティック回帰)を使った。

 Fig.3にその結果を示す。この結果は、Fig.2に示したカーネル行列の構造がそのまま反映されているように見える!つまり、テストデータに対する分類精度は、量子カーネルの場合0.95(Fig.3(a))、古典カーネルの場合0.6(Fig.3(b))であった。量子カーネルの可能性を示唆する一例となった!

🔴参考資料 [Qiskit Machine Learning 0.8.3]

2025年6月11日水曜日

Enjoy Observing Classical and Quantum Kernels in SVC

[Abstract]
The Support Vector Classifier (SVC) is a well-known and effective method for classification. One of its key strengths is the kernel trick, which implicitly maps complex, intertwined data into a higher-dimensional space using a kernel function—allowing for linear separation in that space. In this article, we’ll visually explore and enjoy the differences between classical and quantum kernels!

🟢 Input Dataset: Gaussian Parity
Classical SVC is highly powerful and often outperforms current quantum methods. However, quantum techniques offer novel capabilities that classical approaches cannot, which is why research in this area is gaining momentum.In this article, we use a dataset known as Gaussian Parity, which is considered well-suited for quantum methods.

     As shown in Fig. 1, this dataset consists of 80 samples (56 for training and 24 for testing) and two class labels. The data points from each class are interleaved in a diagonally crossed pattern, making linear separation difficult without transformation. This is where the kernel function—mentioned in the abstract—comes into play.

🟢 SVC Results with Classical and Quantum Kernels
Let’s start with the conclusion. Figure 2 shows classification results using SVC trained with (a) a classical kernel (RBF) and (b) a quantum kernel (a kernel matrix based on the ZZFeatureMap). On the test set, classification accuracy was 0.58 for (a) and 0.93 for (b).

     Of course, these results can vary depending on parameter settings. However, in this instance, the quantum kernel significantly outperformed the classical one. Also, the direction of the decision boundary differs considerably between (a) and (b).

🟢 Exploring the Classical Kernel (RBF)
Let’s take a closer look at the classical case. The RBF kernel is not used directly, but rather called internally during SVC training. It implicitly maps the input data into a higher-dimensional space.
Based on the learned model, we can use Principal Component Analysis (PCA) to project this high-dimensional space into three dimensions and visualize the decision function in 3D.

     The top two images in Fig. 3 show this 3D decision function. You can observe two peaks and two valleys. If we slice this 3D surface at the decision function value = 0, the resulting plane gives us the decision boundary.

🟢 Exploring the Quantum Kernel Matrix
Now let’s examine the quantum case. As shown in Fig. 4, the decision function exhibits a more complex pattern, with more peaks and valleys than in the classical case.
When we slice the surface at decision function = 0, we obtain a decision boundary that achieves a classification accuracy of 0.93.

     This example suggests that the quantum method is exploring and learning within a feature space that classical methods cannot access. This may open the door to entirely new possibilities!


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!