Skip to content

Commit

Permalink
Optimize ProbMask()
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Feb 23, 2023
1 parent 2867733 commit 388b29d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/pinvoke_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2050,9 +2050,6 @@ MICROSOFT_QUANTUM_DECL double PermutationProb(

try {
QInterfacePtr simulator = simulators[sid];
if ((simulator->GetMaxQPower() - 1U) == mask) {
return (double)simulator->ProbAll(perm);
}
return (double)simulator->ProbMask(mask, perm);
} catch (...) {
simulatorErrors[sid] = 1;
Expand Down
4 changes: 4 additions & 0 deletions src/qinterface/qinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ real1_f QInterface::ProbReg(bitLenInt start, bitLenInt length, bitCapInt permuta
/// Returns probability of permutation of the mask
real1_f QInterface::ProbMask(bitCapInt mask, bitCapInt permutation)
{
if ((maxQPower - 1U) == mask) {
return ProbAll(permutation);
}

real1 prob = ZERO_R1;
for (bitCapInt lcv = 0U; lcv < maxQPower; ++lcv) {
if ((lcv & mask) == permutation) {
Expand Down

0 comments on commit 388b29d

Please sign in to comment.