Skip to content

Commit

Permalink
Faster/safer sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Oct 5, 2024
1 parent 4e42ae5 commit c959241
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 3.9)
project (Qrack VERSION 9.9.62 DESCRIPTION "High Performance Quantum Bit Simulation" LANGUAGES CXX)
project (Qrack VERSION 9.9.65 DESCRIPTION "High Performance Quantum Bit Simulation" LANGUAGES CXX)

# Installation commands
include (GNUInstallDirs)
Expand Down
24 changes: 24 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
libqrack (9.9.65) bionic; urgency=medium

* Debug QBDD high rounding (Bionic 4/4)

-- Daniel Strano <dan@unitary.fund> Fri, 04 Oct 2024 07:14:05 -0400

libqrack (9.9.64) focal; urgency=medium

* Debug QBDD high rounding (Focal 3/4)

-- Daniel Strano <dan@unitary.fund> Fri, 04 Oct 2024 07:12:25 -0400

libqrack (9.9.63) jammy; urgency=medium

* Debug QBDD high rounding (Jammy 2/4)

-- Daniel Strano <dan@unitary.fund> Fri, 04 Oct 2024 07:10:54 -0400

libqrack (9.9.62) noble; urgency=medium

* Debug QBDD high rounding (Noble 1/4)

-- Daniel Strano <dan@unitary.fund> Fri, 04 Oct 2024 06:56:49 -0400

libqrack (9.9.61) bionic; urgency=medium

* Debug QBDD sampling (Bionic 4/4)
Expand Down
29 changes: 23 additions & 6 deletions src/qengine/qengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,22 @@ std::map<bitCapInt, int> QEngine::MultiShotMeasureMask(const std::vector<bitCapI
std::discrete_distribution<bitCapIntOcl> dist(maskProbsVec.begin(), maskProbsVec.end());

std::random_device rd;
std::mt19937 gen(rd());
std::vector<std::mt19937> genVec;
const unsigned numThreads = GetConcurrencyLevel();
genVec.reserve(numThreads);
for (unsigned i = 0U; i < numThreads; ++i) {
genVec.emplace_back(rd());
}
std::vector<std::map<bitCapInt, int>> resultsVec(numThreads);

par_for(0, shots, [&](const bitCapIntOcl& shot, const unsigned& cpu) { ++(resultsVec[cpu][dist(genVec[cpu])]); });

std::map<bitCapInt, int> results;
for (unsigned int shot = 0U; shot < shots; ++shot) {
++(results[dist(gen)]);
std::map<bitCapInt, int> results(resultsVec[0U]);
for (size_t i = 1U; i < resultsVec.size(); ++i) {
const std::map<bitCapInt, int>& toAdd = resultsVec[i];
for (auto const& kv : toAdd) {
results[kv.first] += kv.second;
}
}

return results;
Expand All @@ -600,9 +611,15 @@ void QEngine::MultiShotMeasureMask(
std::discrete_distribution<bitCapIntOcl> dist(maskProbsVec.begin(), maskProbsVec.end());

std::random_device rd;
std::mt19937 gen(rd());
std::vector<std::mt19937> genVec;
const unsigned numThreads = GetConcurrencyLevel();
genVec.reserve(numThreads);
for (unsigned i = 0U; i < numThreads; ++i) {
genVec.emplace_back(rd());
}

par_for(0, shots, [&](const bitCapIntOcl& shot, const unsigned& cpu) { shotsArray[shot] = (unsigned)dist(gen); });
par_for(0, shots,
[&](const bitCapIntOcl& shot, const unsigned& cpu) { shotsArray[shot] = (unsigned)dist(genVec[cpu]); });
}

} // namespace Qrack

0 comments on commit c959241

Please sign in to comment.