Skip to content
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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Add docstring #201

wants to merge 14 commits into from

Conversation

Glacialte
Copy link
Contributor

docstringを追加しました。docstringがReadtheDocsに反映されていない問題を解消しました。
f64のみ表示されていたのでf32も一応表示しています。

">>> 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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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(); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 393 to 398
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());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使ってない…?
もともとのマクロでは何が不都合でしたか

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変更してた時の残骸です...
消しておきます。

mgate.def(
"Y",
&gate::Y<Fp>,
"taget"_a,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"taget"_a,
"target"_a,

"controls"_a = std::vector<std::uint64_t>{},
DocString()
.desc("Generate general Gate class instance of S.")
.desc("Performs phase flip operation.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performs phase flip operationのコピペ跡がたくさん残ってそうです.

すべてのゲートについて言葉で説明しなくてもよさそうです(どちらかというと行列表現を全部書いてあげるとまず理解の齟齬がなくて良さそう)

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ前の書き方だったらドキュメント化されないんでしたっけ?いいとは思います.
値の名前をPAULI_*に変えた意図も一応知りたいのと,pauli_enumに代入する必要はなさそうに見えています.

Copy link
Contributor Author

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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"`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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"`paul_id_per_qubit` is applied to `i`-th qubit.")
"`paul_id_per_qubit[i]` is applied to `i`-th qubit.")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glacialte さんの変更差分ではないんですが,GlobalPhaseGateの表示がこうなっているのでついでに修正をお願いしたいです.
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もう一つついででいうなら,説明中の数式に現れる angle を θ とかに変えたいですね
数式っぽくないのと,U1,U2,U3 はそうなっているので

Copy link
Contributor

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,
Copy link
Contributor

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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このPRの変更分ではないんですが、Circuit::copyでは #135 以降各ゲートはコピーされなくなった(参照渡しされる)ので反映してほしい

Copy link
Contributor

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)

Copy link
Contributor

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, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ドキュメントはstate_vectorと書いてるので合わせたい

Comment on lines +162 to +175
.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 "
Copy link
Contributor

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.")
Copy link
Contributor

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しないといけないのでそう書きたい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants