Commit e741af2d authored by Adams, Austin Joel's avatar Adams, Austin Joel
Browse files

qpp Accelerator: Check for post-measure gates more accurately



As a result of XACC IR being serialized, it's possible to have gates
follow Measure instructions without the circuit truly having
post-measure gates. For example:

    H 0
    Measure 0
    H 1
    Measure 1

In cases like that, the current QppAccelerator decides it cannot
simulate the circuit once and repeatedly sample the resulting state
vector to simulate "runs." That is an overzealous judgment, since none
of the gates that follow the Measure instructions actually depend on the
results of measurements.

So instead, in the QppAccelerator logic detecting post-measurement
gates, track which qubits have been measured, and only report
post-measurement gates if it sees a gate operating on a qubit with an
earlier Measure instruction.
Signed-off-by: Adams, Austin Joel's avatarAustin Adams <aja@gatech.edu>
parent 17c30f48
......@@ -148,9 +148,9 @@ namespace {
bool shotCountFromFinalStateVec(const std::shared_ptr<CompositeInstruction>& in_composite)
{
InstructionIterator it(in_composite);
bool measureAtTheEnd = true;
bool measureEncountered = false;
std::set<std::size_t> bitsMeasured;
bool hasReset = false;
bool postMeasureGates = false;
while (it.hasNext())
{
auto nextInst = it.next();
......@@ -158,25 +158,32 @@ namespace {
{
if (nextInst->name() == "Reset") {
hasReset = true;
break;
}
auto bits = nextInst->bits();
if (isMeasureGate(nextInst))
{
// Flag that we have seen a Measure gate.
measureEncountered = true;
bitsMeasured.insert(bits.begin(), bits.end());
}
// We have seen a Measure gate but this one is not another Measure gate.
if (measureEncountered && !isMeasureGate(nextInst))
else
{
measureAtTheEnd = false;
postMeasureGates = std::any_of(bits.begin(), bits.end(),
[&](std::size_t bit) {
return bitsMeasured.count(bit);
});
if (postMeasureGates)
{
break;
}
}
}
}
// If Measure gates are at the very end and no reset,
// this Composite can be simulated by random sampling from the state vec.
return !hasReset && measureAtTheEnd;
return !hasReset && !postMeasureGates;
}
Eigen::MatrixXcd convertToEigenMat(const NoiseModelUtils::cMat& in_stdMat)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment