Skip to content

Commit

Permalink
More QUnit classical shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Nov 10, 2024
1 parent 6fbf4c7 commit 4ebc581
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/qunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2678,7 +2678,25 @@ void QUnit::ApplyEitherControlled(
ebits[i] = &allBitsMapped[i];
}

QInterfacePtr unit = EntangleInCurrentBasis(ebits.begin(), ebits.end());
QInterfacePtr unit;
try {
unit = EntangleInCurrentBasis(ebits.begin(), ebits.end());
} catch (const bad_alloc& e) {
if (targets.size() > 1U) {
throw e;
}
// We overallocated; use a really primitive classical shadow, at least.
for (bitLenInt i = 0U; i < controlVec.size(); ++i) {
if (Prob(controlVec[i]) < (ONE_R1_F / 2)) {
// Any control has less than 50% probability to be measured as |1>:
// Do nothing.
return;
}
// Act the classical shadow of the gate payload.
cfn(unit, {});
}
return;
}

for (size_t i = 0U; i < controlVec.size(); ++i) {
bitLenInt& c = controlVec[i];
Expand Down

0 comments on commit 4ebc581

Please sign in to comment.