Skip to content

Commit

Permalink
Hopefully this variant is better
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanro committed Feb 22, 2025
1 parent 68b7bed commit 37ea7b7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
7 changes: 1 addition & 6 deletions QCSim/QubitRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,7 @@ namespace QC {
const double prob = 1. - uniformZeroOne(rng); // this excludes 0 as probabiliy

if (firstQubit == secondQubit)
{
if (!BaseClass::GetMultithreading() || NrBasisStates < BaseClass::OneQubitOmpLimit)
return BaseClass::MeasureQubitNoCollapse(NrBasisStates, registerStorage, firstQubit, prob);

return BaseClass::MeasureQubitNoCollapseOmp(NrBasisStates, registerStorage, firstQubit, prob);
}
return BaseClass::MeasureQubitNoCollapse(NrBasisStates, registerStorage, firstQubit, prob);

return BaseClass::MeasureNoCollapse(NrBasisStates, registerStorage, firstQubit, secondQubit, prob);
}
Expand Down
31 changes: 1 addition & 30 deletions QCSim/QubitRegisterCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,13 @@ namespace QC {
const size_t measuredQubitMask = 1ULL << qubit;

size_t state = 0;
std::atomic_bool found = false;

#pragma omp parallel for reduction(+:accum) shared(found) num_threads(processor_count) schedule(static, OneQubitOmpLimit / divSchedule)
for (long long i = 0; i < NrBasisStates; ++i)
{
if (found) continue;
accum += std::norm(registerStorage(i));
if (prob <= accum)
{
state = i;
found = true;
break;
}
}

Expand Down Expand Up @@ -403,31 +399,6 @@ namespace QC {
return (state & measuredQubitMask) != 0 ? 1 : 0;
}

static inline size_t MeasureQubitNoCollapseOmp(size_t NrBasisStates, VectorClass& registerStorage, size_t qubit, const double prob)
{
double accum = 0;
const auto processor_count = GetNumberOfThreads();

const size_t measuredQubitMask = 1ULL << qubit;

size_t state = 0;
std::atomic_bool found = false;

#pragma omp parallel for reduction(+:accum) shared(found) num_threads(processor_count) schedule(static, OneQubitOmpLimit / divSchedule)
for (long long i = 0; i < NrBasisStates; ++i)
{
if (found) continue;
accum += std::norm(registerStorage(i));
if (prob <= accum)
{
state = i;
found = true;
}
}

return (state & measuredQubitMask) != 0 ? 1 : 0;
}

static inline double GetQubitProbability(size_t NrBasisStates, const VectorClass& registerStorage, size_t qubit)
{
double accum = 0;
Expand Down

0 comments on commit 37ea7b7

Please sign in to comment.