Skip to content

Commit

Permalink
QStabilizerHybrid::ProbRdm()
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Jul 25, 2023
1 parent c2b3e73 commit 1096544
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions include/qstabilizerhybrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,6 @@ class QStabilizerHybrid : public QParity, public QInterface {
return dMtrx;
}

real1_f 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;
}

template <typename F>
void CheckShots(unsigned shots, bitCapInt m, real1_f partProb, const std::vector<bitCapInt>& qPowers,
std::vector<real1_f>& rng, F fn)
Expand Down Expand Up @@ -392,6 +379,28 @@ class QStabilizerHybrid : public QParity, public QInterface {
}
}

real1_f 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;
}

real1_f CProbRdm(bitLenInt control, bitLenInt target)
{
AntiCNOT(control, target);
const real1_f prob = ProbRdm(target);
AntiCNOT(control, target);

return prob;
}

/**
* Switches between CPU and GPU used modes. (This will not incur a performance penalty, if the chosen mode matches
* the current mode.) Mode switching happens automatically when qubit counts change, but Compose() and Decompose()
Expand Down

0 comments on commit 1096544

Please sign in to comment.