Skip to content

Commit

Permalink
Merge pull request #663 from quantumlib/fix-sampling
Browse files Browse the repository at this point in the history
Fix sampling.
  • Loading branch information
sergeisakov authored Mar 26, 2024
2 parents e581751 + 003eba3 commit cf69fde
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
12 changes: 8 additions & 4 deletions lib/statespace_avx.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ class StateSpaceAVX :

for (uint64_t k = 0; k < size; ++k) {
for (unsigned j = 0; j < 8; ++j) {
auto re = p[16 * k + j];
auto im = p[16 * k + 8 + j];
double re = p[16 * k + j];
double im = p[16 * k + 8 + j];
norm += re * re + im * im;
}
}
Expand All @@ -396,15 +396,19 @@ class StateSpaceAVX :

for (uint64_t k = 0; k < size; ++k) {
for (unsigned j = 0; j < 8; ++j) {
auto re = p[16 * k + j];
auto im = p[16 * k + 8 + j];
double re = p[16 * k + j];
double im = p[16 * k + 8 + j];
csum += re * re + im * im;
while (rs[m] < csum && m < num_samples) {
bitstrings.emplace_back(8 * k + j);
++m;
}
}
}

for (; m < num_samples; ++m) {
bitstrings.emplace_back((uint64_t{1} << state.num_qubits()) - 1);
}
}

return bitstrings;
Expand Down
12 changes: 8 additions & 4 deletions lib/statespace_avx512.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ class StateSpaceAVX512 :

for (uint64_t k = 0; k < size; ++k) {
for (unsigned j = 0; j < 16; ++j) {
auto re = p[32 * k + j];
auto im = p[32 * k + 16 + j];
double re = p[32 * k + j];
double im = p[32 * k + 16 + j];
norm += re * re + im * im;
}
}
Expand All @@ -347,15 +347,19 @@ class StateSpaceAVX512 :

for (uint64_t k = 0; k < size; ++k) {
for (unsigned j = 0; j < 16; ++j) {
auto re = p[32 * k + j];
auto im = p[32 * k + 16 + j];
double re = p[32 * k + j];
double im = p[32 * k + 16 + j];
csum += re * re + im * im;
while (rs[m] < csum && m < num_samples) {
bitstrings.emplace_back(16 * k + j);
++m;
}
}
}

for (; m < num_samples; ++m) {
bitstrings.emplace_back((uint64_t{1} << state.num_qubits()) - 1);
}
}

return bitstrings;
Expand Down
12 changes: 8 additions & 4 deletions lib/statespace_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ class StateSpaceBasic :
const fp_type* p = state.get();

for (uint64_t k = 0; k < size; ++k) {
auto re = p[2 * k];
auto im = p[2 * k + 1];
double re = p[2 * k];
double im = p[2 * k + 1];
norm += re * re + im * im;
}

Expand All @@ -215,14 +215,18 @@ class StateSpaceBasic :
bitstrings.reserve(num_samples);

for (uint64_t k = 0; k < size; ++k) {
auto re = p[2 * k];
auto im = p[2 * k + 1];
double re = p[2 * k];
double im = p[2 * k + 1];
csum += re * re + im * im;
while (rs[m] < csum && m < num_samples) {
bitstrings.emplace_back(k);
++m;
}
}

for (; m < num_samples; ++m) {
bitstrings.emplace_back((uint64_t{1} << state.num_qubits()) - 1);
}
}

return bitstrings;
Expand Down
12 changes: 8 additions & 4 deletions lib/statespace_sse.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ class StateSpaceSSE :

for (uint64_t k = 0; k < size; ++k) {
for (unsigned j = 0; j < 4; ++j) {
auto re = p[8 * k + j];
auto im = p[8 * k + 4 + j];
double re = p[8 * k + j];
double im = p[8 * k + 4 + j];
norm += re * re + im * im;
}
}
Expand All @@ -356,15 +356,19 @@ class StateSpaceSSE :

for (uint64_t k = 0; k < size; ++k) {
for (unsigned j = 0; j < 4; ++j) {
auto re = p[8 * k + j];
auto im = p[8 * k + 4 + j];
double re = p[8 * k + j];
double im = p[8 * k + 4 + j];
csum += re * re + im * im;
while (rs[m] < csum && m < num_samples) {
bitstrings.emplace_back(4 * k + j);
++m;
}
}
}

for (; m < num_samples; ++m) {
bitstrings.emplace_back((uint64_t{1} << state.num_qubits()) - 1);
}
}

return bitstrings;
Expand Down

0 comments on commit cf69fde

Please sign in to comment.