MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / get_marginal

Method get_marginal

runtime/common/SampleResult.cpp:399–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397}
398
399sample_result
400sample_result::get_marginal(const std::vector<std::size_t> &marginalIndices,
401 const std::string_view registerName) const {
402 const auto &counts = retrieve_result(registerName.data()).counts;
403 auto mutableIndices = marginalIndices;
404
405 std::sort(mutableIndices.begin(), mutableIndices.end());
406
407 ExecutionResult sr;
408 for (auto &[bits, count] : counts) {
409 std::string newBits;
410 for ([[maybe_unused]] auto &m : mutableIndices)
411 newBits += "0";
412 for (int counter = 0; auto &index : mutableIndices) {
413 if (index > bits.size())
414 throw std::runtime_error("Invalid marginal index (" +
415 std::to_string(index) +
416 ", size=" + std::to_string(bits.size()));
417
418 newBits[counter++] = bits[index];
419 }
420 sr.appendResult(newBits, count);
421 }
422
423 return sample_result(sr);
424}
425
426void sample_result::clear() {
427 sampleResults.clear();

Callers 6

processResultsMethod · 0.45
processResultsMethod · 0.45
processResultsMethod · 0.45
processResultsMethod · 0.45
processResultsMethod · 0.45
validateMarginalsFunction · 0.45

Calls 7

to_stringFunction · 0.85
appendResultMethod · 0.80
sample_resultClass · 0.70
dataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected