Skip to main contentIBM Quantum Documentation
Important

IBM Quantum Platform is moving and this version will be sunset on July 1. To get started on the new platform, read the migration guide.

Counts

qiskit_addon_sqd.counts

Functions for transforming counts dictionaries.

counts_to_arrays

counts_to_arrays(counts)

GitHub

Convert a counts dictionary into a bitstring matrix and a probability array.

Parameters

counts (Mapping[str, float |int]) – The counts dictionary to convert

Returns

  • A 2D array representing the sampled bitstrings. Each row represents a bitstring, and each element is a bool representation of the bit’s value
  • A 1D array containing the probability with which each bitstring was sampled

Return type

tuple[ndarray, ndarray]

generate_counts_uniform

generate_counts_uniform(num_samples, num_bits, rand_seed=None)

GitHub

Generate a bitstring counts dictionary of samples drawn from the uniform distribution.

Parameters

  • num_samples (int) – The number of samples to draw
  • num_bits (int) – The number of bits in the bitstrings
  • rand_seed (Generator |int | None) – A seed for controlling randomness

Returns

A dictionary mapping bitstrings of length num_bits to the number of times they were sampled.

Raises

ValueErrornum_samples and num_bits must be positive integers.

Return type

dict[str, int]

generate_counts_bipartite_hamming

generate_counts_bipartite_hamming(num_samples, num_bits, *, hamming_right, hamming_left, rand_seed=None)

GitHub

Generate a bitstring counts dictionary with specified bipartite hamming weight.

Parameters

  • num_samples (int) – The number of samples to draw
  • num_bits (int) – The number of bits in the bitstrings
  • hamming_right (int) – The hamming weight on the right half of each bitstring
  • hamming_left (int) – The hamming weight on the left half of each bitstring
  • rand_seed (Generator |int | None) – A seed for controlling randomness

Returns

A dictionary mapping bitstrings to the number of times they were sampled. Each half of each bitstring in the output dictionary will have a hamming weight as specified by the inputs.

Raises

  • ValueErrornum_bits and num_samples must be positive integers.
  • ValueError – Hamming weights must be specified as non-negative integers.
  • ValueErrornum_bits must be even.

Return type

dict[str, int]

normalize_counts_dict

normalize_counts_dict(counts)

GitHub

Convert a counts dictionary into a probability dictionary.

Parameters

counts (Mapping[str, float |int])

Return type

Mapping[str, float]

Was this page helpful?
Report a bug or request content on GitHub.