Skip to content

Commit

Permalink
QStabilizerHybrid::ProbRdm()
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Jun 13, 2023
1 parent e9f1bf5 commit 2dbdf78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/qstabilizerhybrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class QStabilizerHybrid : public QParity, public QInterface {

return dMtrx;
}
real1_f ProbRdm(bitLenInt qubit);

real1_f ApproxCompareHelper(
QStabilizerHybridPtr toCompare, bool isDiscreteBool, real1_f error_tol = TRYDECOMPOSE_EPSILON);
Expand Down
21 changes: 17 additions & 4 deletions src/qstabilizerhybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ void QStabilizerHybrid::MCPhase(
}

if (IS_NORM_0(topLeft - ONE_CMPLX) || IS_NORM_0(bottomRight - ONE_CMPLX)) {
real1_f prob = Prob(target);
real1_f prob = ProbRdm(target);
if (IS_NORM_0(topLeft - ONE_CMPLX) && (prob == ZERO_R1)) {
return;
}
Expand Down Expand Up @@ -920,7 +920,7 @@ void QStabilizerHybrid::MCInvert(

if ((controls.size() > 1U) && IS_SAME(topRight, ONE_CMPLX) && IS_SAME(bottomLeft, ONE_CMPLX)) {
H(target);
const real1_f prob = Prob(target);
const real1_f prob = ProbRdm(target);
H(target);
if (prob <= FP_NORM_EPSILON) {
return;
Expand Down Expand Up @@ -993,7 +993,7 @@ void QStabilizerHybrid::MACPhase(
}

if (IS_NORM_0(topLeft - ONE_CMPLX) || IS_NORM_0(bottomRight - ONE_CMPLX)) {
real1_f prob = Prob(target);
real1_f prob = ProbRdm(target);
if (IS_NORM_0(topLeft - ONE_CMPLX) && (prob == ZERO_R1)) {
return;
}
Expand Down Expand Up @@ -1043,7 +1043,7 @@ void QStabilizerHybrid::MACInvert(

if ((controls.size() > 1U) && IS_SAME(topRight, ONE_CMPLX) && IS_SAME(bottomLeft, ONE_CMPLX)) {
H(target);
const real1_f prob = Prob(target);
const real1_f prob = ProbRdm(target);
H(target);
if (prob <= FP_NORM_EPSILON) {
return;
Expand Down Expand Up @@ -1110,6 +1110,19 @@ real1_f QStabilizerHybrid::Prob(bitLenInt qubit)
return ONE_R1_F / 2;
}

real1_f QStabilizerHybrid::ProbRdm(bitLenInt qubit)
{
if (!ancillaCount || stabilizer->IsSeparable(qubit)) {
return Prob(qubit);
}

std::unique_ptr<complex[]> dMtrx = GetQubitReducedDensityMatrix(qubit);
const complex pauliZ[4]{ ONE_CMPLX, ZERO_CMPLX, ZERO_CMPLX, -ONE_CMPLX };
complex pMtrx[4];
mul2x2(dMtrx.get(), pauliZ, pMtrx);
return (ONE_R1 - std::real(pMtrx[0] + pMtrx[1])) / 2;
}

bool QStabilizerHybrid::ForceM(bitLenInt qubit, bool result, bool doForce, bool doApply)
{
if (engine) {
Expand Down

0 comments on commit 2dbdf78

Please sign in to comment.