-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docstring #201
base: main
Are you sure you want to change the base?
Add docstring #201
Conversation
…batched to ReadtheDocs
include/scaluq/circuit/circuit.hpp
Outdated
">>> print(circuit.to_json())", | ||
"{\"gate_list\":[],\"n_qubits\":3}"})) | ||
.build_as_google_style() | ||
.c_str()) | ||
.def(nb::init<std::uint64_t>(), "Initialize empty circuit of specified qubits.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.def(nb::init<std::uint64_t>(), "Initialize empty circuit of specified qubits.") | |
.def(nb::init<std::uint64_t>(), "n_qubits"_a, "Initialize empty circuit of specified qubits.") |
引数の名前をいれないとドキュメントがarg
やらarg0
やらになって見づらいのでここをそれぞれ入れていってほしいです
[](const GATE_TYPE<FLOAT>& gate) { return gate->get_inverse(); }, \ | ||
[](const GATE_TYPE<FLOAT>& gate) { \ | ||
auto inv = gate->get_inverse(); \ | ||
if (!inv) nb::none(); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
include/scaluq/gate/gate.hpp
Outdated
inline nb::sig concatenate_description(const std::string& desc) { | ||
std::string combined = | ||
desc + | ||
"\n\n.. note:: Upcast is required to use gate-general functions (ex: add to Circuit)."; | ||
return nb::sig(combined.c_str()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使ってない…?
もともとのマクロでは何が不都合でしたか
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
変更してた時の残骸です...
消しておきます。
include/scaluq/gate/gate_factory.hpp
Outdated
mgate.def( | ||
"Y", | ||
&gate::Y<Fp>, | ||
"taget"_a, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"taget"_a, | |
"target"_a, |
include/scaluq/gate/gate_factory.hpp
Outdated
"controls"_a = std::vector<std::uint64_t>{}, | ||
DocString() | ||
.desc("Generate general Gate class instance of S.") | ||
.desc("Performs phase flip operation.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performs phase flip operation
のコピペ跡がたくさん残ってそうです.
すべてのゲートについて言葉で説明しなくてもよさそうです(どちらかというと行列表現を全部書いてあげるとまず理解の齟齬がなくて良さそう)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
各ゲートのクラスとの関連性がわかるように書きたい(「RXGate
のインスタンスを作るけどGenericなGate
型で返す.RXGate
クラス固有の関数が使いたければダウンキャストしてくれ.」のような書き方をしたい)
.value("PAULI_I", PauliOperator<Fp>::PAULI_I) | ||
.value("PAULI_X", PauliOperator<Fp>::PAULI_X) | ||
.value("PAULI_Y", PauliOperator<Fp>::PAULI_Y) | ||
.value("PAULI_Z", PauliOperator<Fp>::PAULI_Z); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これ前の書き方だったらドキュメント化されないんでしたっけ?いいとは思います.
値の名前をPAULI_*
に変えた意図も一応知りたいのと,pauli_enum
に代入する必要はなさそうに見えています.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ただのIやXだとmake htmlで失敗してたんですが、今元通りにしたらエラーが消えてました...
それ以外で変えた意図はないので元通りにしておきます。pauli_enumに代入する必要がないのは確かに。
.desc("Given `target_qubit_list: std::vector<std::uint64_t>, pauli_id_list: " | ||
"std::vector<std::uint64_t>, coef: Complex<Fp>`, Initialize pauli operator. For " | ||
"each `i`, single pauli correspond to `pauli_id_list[i]` is applied to " | ||
"`target_qubit_list`-th qubit.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"`target_qubit_list`-th qubit.") | |
"`target_qubit_list[i]`-th qubit.") |
"`target_qubit_list`-th qubit.") | ||
.desc("Given `pauli_string: std::string_view, coef: Complex<Fp>`, Initialize pauli " | ||
"operator. For each `i`, single pauli correspond to `pauli_id_list[i]` is " | ||
"applied to `target_qubit_list`-th qubit.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"applied to `target_qubit_list`-th qubit.") | |
"applied to `target_qubit_list[i]`-th qubit.") |
"applied to `target_qubit_list`-th qubit.") | ||
.desc("Given `pauli_id_par_qubit: std::vector<std::uint64_t>, coef: Complex<Fp>`, " | ||
"Initialize pauli operator. For each `i`, single pauli correspond to " | ||
"`paul_id_per_qubit` is applied to `i`-th qubit.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"`paul_id_per_qubit` is applied to `i`-th qubit.") | |
"`paul_id_per_qubit[i]` is applied to `i`-th qubit.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
もう一つついででいうなら,説明中の数式に現れる angle を θ とかに変えたいですね
数式っぽくないのと,U1,U2,U3 はそうなっているので
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
引数の名前で書いてたんですが、そもそも引数の名前をギリシャ文字の名前にすると良さそうですね。(Global Phaseならphase
ではなくgamma
、RX/RY/RZならtheta
)
.def( | ||
"load_json", | ||
[](StateVectorBatched<Fp>& states, const std::string& str) { | ||
states = nlohmann::json::parse(str); | ||
}, | ||
"Read an object from the JSON representation of the states."); | ||
"json_str"_a, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ほかのload_json
も引数をarg
からjson_str
に統一したいですね
@@ -164,6 +186,8 @@ void bind_circuit_circuit_hpp(nb::module_& m) { | |||
} | |||
circuit.update_quantum_state(states, parameters); | |||
}, | |||
"state"_a, | |||
"kwargs"_a, | |||
"Apply gate to the StateVectorBatched. StateVectorBatched in args is directly updated. " | |||
"If the circuit contains parametric gate, you have to give real value of parameter as " | |||
"\"name=[value1, value2, ...]\" format in kwargs.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このPRの変更分ではないんですが、Circuit::copyでは #135 以降各ゲートはコピーされなくなった(参照渡しされる)ので反映してほしい
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Control qubits is not included.**
→**Control qubits are not included.**
(今回の変更分じゃないですが)
subprocess.run([sys.executable, '-m', 'nanobind.stubgen', '-m', 'scaluq.scaluq_core.gate', '-o', './stub/scaluq/gate.py']) | ||
stub_dir = Path('./stub/scaluq/') | ||
stub_dir.mkdir(parents=True, exist_ok=True) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GateType
initialize
などはサブモジュールに含まれていないのでscaluq_core
直下の分も入れてほしい
"Generate inverse gate as `Gate` type. If not exists, return None.") \ | ||
.def( \ | ||
"update_quantum_state", \ | ||
[](const GATE_TYPE<FLOAT>& gate, StateVector<FLOAT>& state_vector) { \ | ||
gate->update_quantum_state(state_vector); \ | ||
}, \ | ||
"state"_a, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ドキュメントはstate_vector
と書いてるので合わせたい
.desc("Given `coef: Complex<Fp>`, Initialize operator which just multiplying coef.") | ||
.desc("Given `target_qubit_list: std::vector<std::uint64_t>, pauli_id_list: " | ||
"std::vector<std::uint64_t>, coef: Complex<Fp>`, Initialize pauli operator. For " | ||
"each `i`, single pauli correspond to `pauli_id_list[i]` is applied to " | ||
"`target_qubit_list[i]`-th qubit.") | ||
.desc("Given `pauli_string: std::string_view, coef: Complex<Fp>`, Initialize pauli " | ||
"operator. For each `i`, single pauli correspond to `pauli_id_list[i]` is " | ||
"applied to `target_qubit_list[i]`-th qubit.") | ||
.desc("Given `pauli_id_par_qubit: std::vector<std::uint64_t>, coef: Complex<Fp>`, " | ||
"Initialize pauli operator. For each `i`, single pauli correspond to " | ||
"`paul_id_per_qubit[i]` is applied to `i`-th qubit.") | ||
.desc("Given `bit_flip_mask: std::uint64_t, phase_flip_mask: std::uint64_t, coef: " | ||
"Complex<Fp>`, Initialize pauli operator. For each `i`, single pauli applied to " | ||
"`i`-th qubit is " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complex<Fp>
とかstd::vector<std::uint64_t>
ではなくてPythonの型で書きたい。complex
, list[int]
"target"_a, | ||
DocString() | ||
.desc("Generate general :class:`~f64.Gate` class instance of CNotGate. Performs " | ||
"controlled-X operation.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「instance of XGate
with one control qubit」みたいなのほうが正しそうです。
downcastしてくれという説明もXGate
にdowncastしないといけないのでそう書きたい
docstringを追加しました。docstringがReadtheDocsに反映されていない問題を解消しました。
f64のみ表示されていたのでf32も一応表示しています。