Skip to content

Latest commit

 

History

History
99 lines (66 loc) · 2.55 KB

File metadata and controls

99 lines (66 loc) · 2.55 KB

SoftDispatchResult API Deep Dive

This page documents the public lindblad::SoftDispatchResult API.

Header and Namespace

  • Header: include/lindblad/dispatch.hpp
  • Namespace: lindblad

Type Overview

SoftDispatchResult summarizes a sampler count distribution into:

  • a fractional soft assignment per bit
  • a best bitstring with its probability
  • optional rounded or greedy dispatch outputs

The constructor computes total_shots and calls compute() immediately.

Fields

  • counts: raw sampled counts (bitstring -> count)
  • total_shots: sum of all counts
  • soft_assignment: fractional assignment per bit
  • best_bitstring: most probable bitstring
  • best_probability: probability of best_bitstring

Construction

explicit SoftDispatchResult(const std::unordered_map<std::string, int>& counts_in);

Behavior:

  • sums counts into total_shots
  • calls compute() to fill derived fields

Methods

compute()

  • infers bitstring length from the first key in counts
  • populates soft_assignment, best_bitstring, and best_probability
  • returns early if counts is empty or total_shots == 0

threshold_round(double threshold = 0.5)

  • returns an MSB-first bitstring
  • uses >= threshold to mark a bit as 1

greedy_dispatch(const std::vector<double>& generator_capacities, double demand)

  • orders indices by descending soft_assignment
  • selects until supplied >= demand
  • returns selected indices in the chosen order
  • throws std::invalid_argument if capacity size does not match assignment size

expected_cost(const std::function<double(const std::string&)>& cost_fn)

  • returns 0.0 if total_shots == 0
  • otherwise computes the expected value under the sampled distribution

top_k(int k)

  • returns the k most probable bitstrings and their probabilities
  • assumes total_shots > 0 to avoid division by zero

Exceptions and Preconditions

  • greedy_dispatch throws std::invalid_argument if the capacity vector length does not match the bitstring length
  • top_k expects total_shots > 0 (non-empty counts)

Example

#include "lindblad/dispatch.hpp"

using namespace lindblad;

int main() {
    std::unordered_map<std::string, int> counts = {
        {"110", 30},
        {"100", 20}
    };

    SoftDispatchResult result(counts);
    std::string rounded = result.threshold_round(0.5);
    auto top = result.top_k(2);
    (void)rounded;
    (void)top;
    return 0;
}

Related Pages