-
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 batch update #179
base: main
Are you sure you want to change the base?
Add batch update #179
Conversation
…, add batched control test
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.
途中までしか見れてません
すみません
scaluq/gate/gate.hpp
Outdated
[[nodiscard]] std::vector<std::uint64_t> mask_to_vector(std::uint64_t mask) const { | ||
std::vector<std::uint64_t> qubits; | ||
for (std::uint64_t i = 0; i < 64; ++i) { | ||
if ((mask >> i) & 1) qubits.push_back(i); | ||
} | ||
return 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.
もっと高速なのがutil/utility.hppにあるはず
scaluq/gate/gate_probablistic.hpp
Outdated
std::ranges::upper_bound(_cumulative_distribution, r[i])) - | ||
1; | ||
if (indices[i] >= _gate_list.size()) indices[i] = _gate_list.size() - 1; | ||
auto state_vector = states.get_state_vector_at(i); |
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ゲートとかなのにコピーするのは流石に嫌なので、
https://kokkos.org/kokkos-core-wiki/API/core/view/view.html#_CPPv44ViewRK4ViewI2DTDp4PropEDp4ArgsでUnmanaged Viewを作って底からStateVectorを得るようにしたい
ViewからStateVectorを作るコンストラクタを作って、
StateVector state_vector = StateVector(Kokkos::View(states._raw, std::make_pair(i, 0), std::make_pair(i, dim)));
みたいにすれば良さそう
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.
先に抽選をしておいて、一定以上の個数がかけられるゲートは一度Batchにコピーして適用するのがいいかも
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.
全体的にはかなりいい感じです!
ありがとうございます!
Parametricのparamをvectorにするのだけは必ずやってほしいです(QCLで使うらしいので)
scaluq/gate/gate.hpp
Outdated
[](const GATE_TYPE& gate, StateVectorBatched& states) { \ | ||
gate->update_quantum_state(states); \ | ||
}, \ | ||
"Apply gate to `state_vector_batched`. `states` in args is directly updated.") \ |
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_batched
の部分、引数の名前として入れてるつもりだったのでstates
にしたほうがいい
scaluq/gate/param_gate.hpp
Outdated
@@ -114,6 +115,7 @@ class ParamGateBase { | |||
[[nodiscard]] virtual internal::ComplexMatrix get_matrix(double param) const = 0; | |||
|
|||
virtual void update_quantum_state(StateVector& state_vector, double param) const = 0; | |||
virtual void update_quantum_state(StateVectorBatched& states, double param) const = 0; |
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.
Paramのほうはstd::vectorでparamsを受けるようにして、それぞれの場所に別々のパラメータを渡せるようにしたいです。
scaluq/gate/gate_probablistic.hpp
Outdated
std::ranges::upper_bound(_cumulative_distribution, r[i])) - | ||
1; | ||
if (indices[i] >= _gate_list.size()) indices[i] = _gate_list.size() - 1; | ||
auto state_vector = states.get_state_vector_at(i); |
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.
先に抽選をしておいて、一定以上の個数がかけられるゲートは一度Batchにコピーして適用するのがいいかも
insert_zero_at_mask_positions(it, target_mask | control_mask) | control_mask; | ||
std::uint64_t basis_1 = basis_0 | lower_target_mask; | ||
std::uint64_t basis_2 = basis_0 | upper_target_mask; | ||
std::uint64_t basis_3 = basis_1 | target_mask; |
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.
間違ってはないけどbasis1
にかぶせてるの結構変な感じはしますね…
@@ -177,7 +177,7 @@ inline ComplexMatrix convert_internal_matrix_to_external_matrix(const Matrix& ma | |||
} | |||
|
|||
inline ComplexMatrix convert_coo_to_external_matrix(SparseMatrix mat) { | |||
ComplexMatrix eigen_matrix(mat._row, mat._col); | |||
ComplexMatrix eigen_matrix = ComplexMatrix::Zero(mat._row, mat._col); |
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.
👍
scaluq/gate/gate_matrix.hpp
Outdated
@@ -50,6 +50,11 @@ class OneTargetMatrixGateImpl : public GateBase { | |||
one_target_dense_matrix_gate(_target_mask, _control_mask, _matrix, state_vector); | |||
} | |||
|
|||
void update_quantum_state(StateVectorBatched& states) const override { | |||
check_qubit_mask_within_bounds(states.get_state_vector_at(0)); |
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.
範囲の確認のためにget_state_vector_at
してるの,ちょっと気になります
check_qubit_mask_within_bounds
には単に長さを渡すように変えてもいいかも
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.
statesを渡すcheck_qubit_mask_within_boundsを作りました
scaluq/gate/gate.hpp
Outdated
[[nodiscard]] | ||
|
||
std::string | ||
get_qubit_info_as_string(const std::string& indent) const { |
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.
これシンプルに気になります
バッチ版の更新とテストを追加しました。
また、CIでエラーが起きていたのでpyproject.tomlのCIの項からnumpyの指定を削除しました。