build_counts_histogram¶
from cascaqit import build_counts_histogram
build_counts_histogram ¶
build_counts_histogram(
result: ResultIR,
*,
measurement_key: str | None = None,
visualization_id: str | None = None,
title: str = "Counts histogram",
) -> CountsHistogramVisualizationIR
Extract histogram data from ResultIR, returning CountsHistogramVisualizationIR. This does not open a window, save an image or resample. Use visualize for an HTML report.
Omit measurement_key for one explicit register; multiple registers require it. If no explicit measurement records exist, use top-level counts. A wrong result type raises TypeError, missing a key for multiple registers raises ValueError, and an unknown key propagates measurement()'s KeyError.
Bars are sorted by bitstring, with bitstring, count and probability fields. Here probability means recorded frequency count / result.shots. Zero shots produce 0, and absent bitstrings are not filled in. Spec retains title, axes and the source result hash; metadata retains measurement selection and bit order. visualization_id can be explicit or derived from result_id.
from cascaqit import Circuit, build_counts_histogram
result = Circuit(1).x(0).measure_all().run(shots=16, seed=7)
histogram = build_counts_histogram(result)
assert histogram.bars[0]["bitstring"] == "1"
assert histogram.bars[0]["count"] == 16
assert histogram.bars[0]["probability"] == 1.0
See Execution records for the distinction between plotting data and physical probabilities.