Skip to content

Commit

Permalink
Slight optimization: transpose sample
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Howe <[email protected]>
  • Loading branch information
bmhowe23 committed Oct 15, 2024
1 parent 588770e commit 24ed900
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions runtime/nvqir/stim/StimCircuitSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,15 @@ class StimCircuitSimulator : public nvqir::CircuitSimulatorBase<double> {
// Now XOR results on a per-shot basis
stim::simd_bit_table<W> sample = sampleSim->m_record.storage;
auto nShots = sampleSim->batch_size;
if (ref.not_zero()) {
sample = stim::transposed_vs_ref(nShots, sample, ref);
sample = sample.transposed();
}

// This is a slightly modified version of `sample_batch_measurements`, where
// we already have the `sample` from the frame simulator. It also places the
// `sample` in a layout amenable to the order of the loops below (shot
// major).
sample = sample.transposed();
if (ref.not_zero())
for (size_t s = 0; s < nShots; s++)
sample[s].word_range_ref(0, ref.num_simd_words) ^= ref;

size_t bits_per_sample = num_measurements;
std::vector<std::string> sequentialData;
Expand All @@ -282,7 +287,7 @@ class StimCircuitSimulator : public nvqir::CircuitSimulatorBase<double> {
for (std::size_t shot = 0; shot < shots; shot++) {
std::string aShot(qubits.size(), '0');
for (std::size_t b = first_bit_to_save; b < bits_per_sample; b++)
aShot[b - first_bit_to_save] = sample[b][shot] ? '1' : '0';
aShot[b - first_bit_to_save] = sample[shot][b] ? '1' : '0';
counts[aShot]++;
sequentialData.push_back(std::move(aShot));
}
Expand Down

0 comments on commit 24ed900

Please sign in to comment.