From 109654466036820d627345504fa9dff5bee4cb68 Mon Sep 17 00:00:00 2001 From: Dan Strano Date: Mon, 24 Jul 2023 20:43:40 -0400 Subject: [PATCH] QStabilizerHybrid::ProbRdm() --- include/qstabilizerhybrid.hpp | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/include/qstabilizerhybrid.hpp b/include/qstabilizerhybrid.hpp index 9d2bce9da..fdd4606b4 100644 --- a/include/qstabilizerhybrid.hpp +++ b/include/qstabilizerhybrid.hpp @@ -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 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 void CheckShots(unsigned shots, bitCapInt m, real1_f partProb, const std::vector& qPowers, std::vector& rng, F fn) @@ -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 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()