Qulacs-Osaka / scikit-qulacs

scikit-qulacs is a library for quantum neural network. This library is based on qulacs and named after scikit-learn.
https://qulacs-osaka.github.io/scikit-qulacs/index.html
MIT License
21 stars 6 forks source link

Toward Trainability of Deep Quantum Neural Networks #194

Open forest1040 opened 2 years ago

forest1040 commented 2 years ago

[Kosuke Mitarai] 11:51 手が空いている方がいたら https://arxiv.org/abs/2112.15002 の Fig. 6 再現をしてみてほしいですー arXiv.orgarXiv.org Toward Trainability of Deep Quantum Neural Networks Quantum Neural Networks (QNNs) with random structures have poor trainability due to the exponentially vanishing gradient as the circuit depth and the qubit number increase. This result leads to a... 理解が間違っていなければ、ansatz を組むときに CNOT を ladder にするのと CZ を ladder にするのとで訓練可能性が全然違うという謎現象が起こるみたいです

forest1040 commented 2 years ago

雑にslackから転記

KeisukeFujii 今日 12:12 @森俊夫 https://arxiv.org/pdf/2112.15002.pdf この論文のCLというansatzが勾配小さくならない、という性質があるそうで(なぜそうなるのか不明ですが、数値計算の結果はそのようになっています)、scikit-qulacsに入れておくと良いと思いました。

森俊夫 38分前 DNNでは、勾配消失問題に対処するために、Skip-Connectionを入れたりしますが CZを入れることにより、重ね合わされてSkip-Connection的な効果がでるのでしょうか。。

Kosuke Mitarai 35分前 skip-connection との関連はよくわからないのですが、 CZ のラダーより CNOT のラダーのほうが、(非可換な分) 全体に渡るエンタングルメントが作られやすくて、結果として勾配消失が起きやすい的なことかなーという妄想はできましたが実際のところはなぜそういうことが起きるのかよくわからないです (編集済み)

forest1040 commented 2 years ago

とりあえず自分、論文読んでみます。 プログラミングバイトの方で実装したい方がいらっしゃいましたら、一緒にやりましょう!

WATLE commented 2 years ago

やります

WATLE commented 2 years ago

すでにikanago さんが取り組んでいましたね...

forest1040 commented 2 years ago

まぁ、2名でやってもいい気もしますがね。。

ikanago commented 2 years ago

いま skqulacs のコード読んでて手が止まってるのでやってもらっても大丈夫です 🙆

WATLE commented 2 years ago

じゃあ、やります

ikanago commented 2 years ago

ikanago/arxiv-2112.15002 にやりかけのコードがあるので参考にしたりしなかったりしてください

forest1040 commented 2 years ago

@WATLE 一応、論文読みましたので、必要であれば、打ち合わせしましょう。

WATLE commented 2 years ago

お願いします 

WATLE commented 2 years ago

あ、 現在、 前の時間割との関係で研究室で業務を行っていて、 環境が違うので マイクが使えません やっぱり打ち合わせは難しいです.  

forest1040 commented 2 years ago

了解です!次回のときにでも打ち合わせしましょう! そのときにslackのメンションください。

ikanago commented 2 years ago

論文に直接リンクがなかったので,wine dataset のリンク貼っときます: https://archive-beta.ics.uci.edu/ml/datasets/wine

WATLE commented 2 years ago

precision recall f1-score support

       0       0.90      1.00      0.95        28
       1       1.00      0.92      0.96        37

accuracy                           0.95        65

macro avg 0.95 0.96 0.95 65 weighted avg 0.96 0.95 0.95 65

WATLE commented 2 years ago

https://github.com/Qulacs-Osaka/scikit-qulacs/tree/ikanago/arxiv-2112.15002  にpushしました

WATLE commented 2 years ago

論文の実装と簡素な確認をしましたが、 最終的にどのようにまとめればよいかわかりません。

forest1040 commented 2 years ago

Czがあることによって、層をふやしても勾配が発散しない事が特徴かと思います。 ですので、Cz層があるなしを比較して、層を横軸に取って、精度を比較すると良い気がします。

WATLE commented 2 years ago

accuracy 単純比較 0.74 0.86 0.94 0.63 0.91 0.80 0.83 新 0.88 0.58 0.54 0.37 0.89 0.62 0.86 旧

WATLE commented 2 years ago

横軸: depth 3~9 です

WATLE commented 2 years ago

勾配が発散しない感が出ています 

forest1040 commented 2 years ago

ありがとうございます。見てみます!

forest1040 commented 2 years ago

https://github.com/Qulacs-Osaka/scikit-qulacs/commit/75e27bf084c6ea4f82a51931dbff9c8b65ef6f7a で、cz層のありなしで、depthを1〜20で計測してみました。

何か変ですね。。(自分のテストコードが間違っているかも。。)

czあり

depth: 1  score: 0.8625454545454544
depth: 2  score: 0.8469785575048733
depth: 3  score: 0.8625454545454544
depth: 4  score: 0.8625454545454544
depth: 5  score: 0.9081871345029241
depth: 6  score: 0.877992277992278
depth: 7  score: 0.893090909090909
depth: 8  score: 0.893090909090909
depth: 9  score: 0.893090909090909
depth: 10  score: 0.893090909090909
depth: 11  score: 0.893090909090909
depth: 12  score: 0.893090909090909
depth: 13  score: 0.893090909090909
depth: 14  score: 0.893090909090909
depth: 15  score: 0.893090909090909
depth: 16  score: 0.893090909090909
depth: 17  score: 0.893090909090909
depth: 18  score: 0.893090909090909
depth: 19  score: 0.893090909090909
depth: 20  score: 0.893090909090909

czなし

depth: 1  score: 0.8610573343261356
depth: 2  score: 0.8619456015682431
depth: 3  score: 0.9084942084942085
depth: 4  score: 0.8769230769230769
depth: 5  score: 0.893090909090909
depth: 6  score: 0.9081871345029241
depth: 7  score: 0.893090909090909
depth: 8  score: 0.9081871345029241
depth: 9  score: 0.9081871345029241
depth: 10  score: 0.9081871345029241
depth: 11  score: 0.9236363636363636
depth: 12  score: 0.9081871345029241
depth: 13  score: 0.9081871345029241
depth: 14  score: 0.9081871345029241
depth: 15  score: 0.9081871345029241
depth: 16  score: 0.9081871345029241
depth: 17  score: 0.9081871345029241
depth: 18  score: 0.9081871345029241
depth: 19  score: 0.9081871345029241
depth: 20  score: 0.9081871345029241
forest1040 commented 2 years ago

czなしの方のビット数をs_qubit分減らすのを忘れてました。。修正します。 よく考えたら、depthの深さの件は実機のノイズがないとご利益がない気がしてきました。。 Noisyを使わないといけない?

forest1040 commented 2 years ago

勾配消失や爆発の対策なので、パラメータの変動が大きいモデルを使わないといけない気がしてきました。。

forest1040 commented 2 years ago

そもそも試験の前提がまちがってました。。 depthは固定でイテレーションを増やしていって計測するようです。 ちょっと論文を見直します。。

forest1040 commented 2 years ago

イテレーションを400まで回して、CLありとなしで比較しました。 200までは、CLの方がいい感じでしたが、最終的にCLなしの CL-QNN.result.txt 回路の方が 精度が高くなりました。。

WATLE commented 1 year ago

これどうしますか

forest1040 commented 1 year ago

御手洗先生と話をしまして、後は私の方でグラフ追加して、整理してpre_definedに追加しておきます。

WATLE commented 1 year ago

ありがとうございます。