Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Gheorghiu <[email protected]>
  • Loading branch information
vsoftco committed Aug 19, 2024
1 parent 14c74ec commit 65f171f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions include/qpp/classes/qengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,16 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
*
* \param engine_state Instance of qpp::internal::QEngineState<T>
* \param steps Vector of qpp::QCircuit::iterator
* \idx pos Index from where the execution starts
* \idx reps Number of repetitions
* \return Reference to the current instance
* \param pos Index from where the execution starts
* \param reps Number of repetitions
* \param last_rep When last_rep is true, the last repetion is executed
* repeatedly until the post-selection succeeds \return Reference to the
* current instance
*/
// IMPORTANT: ALWAYS pass engine_state by value!
QEngineT& execute_no_sample_(internal::QEngineState<T> engine_state,
const std::vector<QCircuit::iterator>& steps,
idx pos, idx reps) {
idx pos, idx reps, bool last_rep = false) {
auto worker = [&](bool last_rep) {
// sets the state of the engine to the entry state
qeng_st_ = engine_state;
Expand Down Expand Up @@ -136,10 +138,11 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
for (idx rep = 0; rep < reps - 1; ++rep) {
worker(false);
}

if (reps > 1) {
worker(true); // ensure post-selection for >1 reps
} else {
worker(qeng_st_.ensure_post_selection_);
worker(last_rep || qeng_st_.ensure_post_selection_);
}

return *this;
Expand Down Expand Up @@ -385,7 +388,7 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
}

// the last state is always computed with ensure_post_selection = true
execute_no_sample_(qeng_st_, steps, pos, 1);
execute_no_sample_(qeng_st_, steps, pos, 1, true);

return *this;
}
Expand Down

0 comments on commit 65f171f

Please sign in to comment.