Skip to content

Commit

Permalink
added an optimization where the qubits are sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
ShellyGarion committed Apr 4, 2019
1 parent de075e7 commit 647956f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/simulators/statevector/statevector_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,18 @@ void State<statevec_t>::apply_initialize(const reg_t &qubits,
RngEngine &rng) {
// Apply reset to qubits
apply_reset(qubits, rng);

if (qubits.size() == BaseState::qreg_.num_qubits()) {
// If qubits is all ordered qubits in the statevector
// we can just initialize the whole state directly
auto sorted_qubits = qubits;
std::sort(sorted_qubits.begin(), sorted_qubits.end());
if (qubits == sorted_qubits) {
BaseState::qreg_.initialize_from_vector(params);
return;
}
}

// Apply initialize_component
BaseState::qreg_.initialize_component(qubits, params);
}
Expand Down

0 comments on commit 647956f

Please sign in to comment.