Skip to content

Extended stabilizer is not thread safe #1932

@doichanj

Description

@doichanj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions