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

Fix extended stabilizer thread safety in apply_ops_parallel #1993

Merged
merged 6 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fixes:
- |
Extended stabilizer simulation was sharing a single copy of RngEngine amongst
parallelized states in ``ExtendedStabilizer::State::apply_ops_parallel``,
leading to thread safety issue. Now, a new RngEngine is seeded for each parallel
state.
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,24 @@ template <typename InputIterator>
void State::apply_ops_parallel(InputIterator first, InputIterator last,
ExperimentResult &result, RngEngine &rng) {
const int_t NUM_STATES = BaseState::qreg_.get_num_states();

std::vector<size_t> rng_seeds(NUM_STATES);
for (int_t i = 0; i < NUM_STATES; i++) {
rng_seeds[i] = rng.rand_int<size_t>(0, SIZE_MAX);
}

#pragma omp parallel for if (BaseState::qreg_.check_omp_threshold() && \
BaseState::threads_ > 1) \
num_threads(BaseState::threads_)
for (int_t i = 0; i < NUM_STATES; i++) {
if (!BaseState::qreg_.check_eps(i)) {
continue;
}
RngEngine local_rng(rng_seeds[i]);
for (auto it = first; it != last; it++) {
switch (it->type) {
case Operations::OpType::gate:
apply_gate(*it, rng, i);
apply_gate(*it, local_rng, i);
break;
case Operations::OpType::barrier:
case Operations::OpType::qerror_loc:
Expand Down
Loading