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

Extended stabilizer is not thread safe #1932

Closed
doichanj opened this issue Sep 8, 2023 · 0 comments
Closed

Extended stabilizer is not thread safe #1932

doichanj opened this issue Sep 8, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@doichanj
Copy link
Collaborator

doichanj commented Sep 8, 2023

Informations

  • Qiskit Aer version: 0.12.2
  • Python version:
  • Operating system:

What is the current behavior?

Extended stabilizer uses same random generator among multiple threads without considering thread safety in the parallel section as below

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();
#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;
}
for (auto it = first; it != last; it++) {
switch (it->type) {
case Operations::OpType::gate:
apply_gate(*it, rng, i);
break;
case Operations::OpType::barrier:
case Operations::OpType::qerror_loc:
break;
default:
throw std::invalid_argument("CH::State::apply_ops_parallel does not "
"support operations of the type \'" +
it->name + "\'.");
break;
}
}
}
}

I think we can not reproduce the same results with the same random seed

Suggested solutions

To get the consistent resault with the same random seed, we have to allocate random generators for each states

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant