Skip to content

Commit

Permalink
Debug rounding in RdmCloneFlush()
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Jul 30, 2023
1 parent 5b03899 commit ec8d6e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
28 changes: 3 additions & 25 deletions include/qstabilizerhybrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,29 +264,7 @@ class QStabilizerHybrid : public QParity, public QInterface {
shard->gate[3U] = complex(angleCos, angleSin);
}

const complex h[4U] = { SQRT1_2_R1, SQRT1_2_R1, SQRT1_2_R1, -SQRT1_2_R1 };
for (size_t i = qubitCount; i < shards.size(); ++i) {
// Flush all buffers as close as possible to Clifforrd.
const MpsShardPtr& shard = shards[i];
shard->Compose(h);

const real1 angle = (real1)(FractionalRzAngleWithFlush(i, std::arg(shard->gate[3U] / shard->gate[0U])) / 2);
if ((2 * abs(angle) / PI_R1) <= FP_NORM_EPSILON) {
stabilizer->H(i);
stabilizer->ForceM(i, false);
stabilizer->Dispose(i, 1U);
shards.erase(shards.begin() + i);
--ancillaCount;

continue;
}
const real1 angleCos = cos(angle);
const real1 angleSin = sin(angle);
shard->gate[0U] = complex(angleCos, -angleSin);
shard->gate[3U] = complex(angleCos, angleSin);

shard->Compose(h);
}
RdmCloneFlush();
}

void CombineAncillae();
Expand All @@ -295,11 +273,11 @@ class QStabilizerHybrid : public QParity, public QInterface {
{
CombineAncillae();
QStabilizerHybridPtr clone = std::dynamic_pointer_cast<QStabilizerHybrid>(Clone());
clone->RdmCloneFlush();
clone->RdmCloneFlush(ONE_R1 / 4);

return clone;
}
void RdmCloneFlush(real1_f threshold = (ONE_R1 / 4));
void RdmCloneFlush(real1_f threshold = FP_NORM_EPSILON);

real1_f ApproxCompareHelper(
QStabilizerHybridPtr toCompare, bool isDiscreteBool, real1_f error_tol = TRYDECOMPOSE_EPSILON);
Expand Down
14 changes: 10 additions & 4 deletions src/qstabilizerhybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,14 +1762,12 @@ void QStabilizerHybrid::CombineAncillae()
return;
}

RdmCloneFlush(FP_NORM_EPSILON);
FlushCliffordFromBuffers();

if (!ancillaCount) {
return;
}

FlushCliffordFromBuffers();

// The ancillae sometimes end up in a configuration where measuring an earlier ancilla collapses a later ancilla.
// If so, we can combine (or cancel) the phase effect on the earlier ancilla and completely separate the later.
// We must preserve the earlier ancilla's entanglement, besides partial collapse with the later ancilla.
Expand Down Expand Up @@ -1865,7 +1863,6 @@ void QStabilizerHybrid::CombineAncillae()

void QStabilizerHybrid::RdmCloneFlush(real1_f threshold)
{
FlushCliffordFromBuffers();
const complex h[4U] = { SQRT1_2_R1, SQRT1_2_R1, SQRT1_2_R1, -SQRT1_2_R1 };
for (size_t i = shards.size() - 1U; i >= qubitCount; --i) {
MpsShardPtr& shard = shards[i];
Expand All @@ -1875,6 +1872,15 @@ void QStabilizerHybrid::RdmCloneFlush(real1_f threshold)
for (int p = 0; p < 2; ++p) {
shard->Compose(h);
QStabilizerHybridPtr clone = std::dynamic_pointer_cast<QStabilizerHybrid>(Clone());

if (clone->stabilizer->IsSeparable(i)) {
stabilizer->Dispose(i, 1U);
shards.erase(shards.begin() + i);
--ancillaCount;

break;
}

clone->stabilizer->H(i);
clone->stabilizer->ForceM(i, p == 1);

Expand Down

0 comments on commit ec8d6e1

Please sign in to comment.