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

Stubを分割 #169

Merged
merged 7 commits into from
Sep 10, 2024
Merged

Stubを分割 #169

merged 7 commits into from
Sep 10, 2024

Conversation

KowerKoint
Copy link
Contributor

@KowerKoint KowerKoint commented Sep 6, 2024

close #166

binding.cppが長いので、各ヘッダの末尾に分割しました。

エラーでstubが生成されていないものの検知をCIに入れました。

- name: Test if stub exists
run: |
echo -e "from scaluq import StateVector\nfrom.scaluq.gate import I" > /tmp/stub_sample.py
mypy /tmp/stub_sample.py
Copy link
Contributor Author

Choose a reason for hiding this comment

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

全オブジェクトを列挙してmypyするテストも考えましたが、むしろ一部だけでも名前を指定したほうがそもそもなにもbindingできていない事故を検知できていいと思ったのでこうしました。
全オブジェクト列挙を手動でしておく方法は、追加忘れが起きそうなのと一部だけ生成されないケースをまだ見ていないので一旦やめました。

@@ -62,7 +62,7 @@ class ParamGateBase {
}
virtual ~ParamGateBase() = default;

[[nodiscard]] double param_coef() { return _pcoef; }
[[nodiscard]] double param_coef() const { return _pcoef; }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

constがついてなかったのでつけました

.def( \
"param_coef", \
[](const PARAM_GATE_TYPE &gate) { return gate->param_coef(); }, \
"Get coefficient of parameter.") \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

param_coefがバインドされていなかったのでしました

"phi", [](const U3Gate& gate) { return gate->phi(); }, "Get `phi` property.")
.def(
"lambda_", [](const U3Gate& gate) { return gate->lambda(); }, "Get `lambda` property.");
DEF_GATE(SwapGate, "Specific class of two-qubit swap gate.");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SwapGateがバインドできてなかったのでしました(特にメンバ関数が増えるわけでもないのでそれほど必要ではないですが…)

@@ -127,7 +127,7 @@ namespace internal {
class GateBase : public std::enable_shared_from_this<GateBase> {
protected:
std::uint64_t _target_mask, _control_mask;
void check_qubit_mask_within_bounds(const StateVector& state_vector) const {
void check_qubit_mask_within_bounds(const StateVector &state_vector) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

このあたりよくわかっていないんですが、これは自動でformatされないんですかね?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

自動formatの結果動いたのですが、たぶん手元Dev containerとCIそれぞれでインストールされるclang-formatのバージョンが同時に変わったため変更+CI通過起こってます…
本家みたいにclang-formatのバージョン固定したほうがいいかも

&の位置は PointerAlignment で指定はできそうですが、デフォルトが変わったんだろうか…
ベースにしているGoogle Styleでは

When referring to a pointer or reference (variable declarations or definitions, arguments, return types, template parameters, etc), you may place the space before or after the asterisk/ampersand. In the trailing-space style, the space is elided in some cases (template parameters, etc).

と書いてあるのでどちらかに規定はされてないようです。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

バージョン固定でもいいですが、一意に定まるほどconfigをキッチリするほうがきれいだと思った(+PointerAlignmentはドキュメントの例でも指定されているほどみんなが設定している項目だった)ので、configのほうを追加する方針にしました。

Copy link
Contributor

Choose a reason for hiding this comment

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

対応ありがとうございます!

.def("copy", &Circuit::copy, "Copy circuit. All the gates inside is copied.")
.def("get_inverse",
&Circuit::get_inverse,
"Get inverse of circuit. ALl the gates are newly created.");
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: ALl

Copy link
Contributor

@gandalfr-KY gandalfr-KY left a comment

Choose a reason for hiding this comment

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

OKです!
ありがとうございます。

@@ -7,3 +7,5 @@ AccessModifierOffset: -4
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 100
DerivePointerAlignment: false
PointerAlignment: Left
Copy link
Contributor Author

Choose a reason for hiding this comment

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

format結果がブレるケースがあったので追加で指定しました。

@KowerKoint KowerKoint merged commit e7f133a into main Sep 10, 2024
4 checks passed
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.

stubが生成されなくなっている
2 participants