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.

Subsampling

qiskit_addon_sqd.subsampling

Functions for creating batches of samples from a bitstring matrix.

subsample

subsample(bitstring_matrix, probabilities, samples_per_batch, num_batches, rand_seed=None)

GitHub

Subsample batches of bit arrays from an input bitstring_matrix.

Each individual batch will be sampled without replacement from the input bitstring_matrix. Samples will be replaced after creation of each batch, so different batches may contain identical samples.

Parameters

  • bitstring_matrix (ndarray) – A 2D array of bool representations of bit values such that each row represents a single bitstring.
  • probabilities (ndarray) – A 1D array specifying a probability distribution over the bitstrings
  • samples_per_batch (int) – The number of samples to draw for each batch
  • num_batches (int) – The number of batches to generate
  • rand_seed (Generator |int | None) – A seed to control random behavior

Returns

A list of bitstring matrices subsampled from the input bitstring matrix.

Raises

  • ValueError – The number of elements in probabilities must equal the number of rows in bitstring_matrix.
  • ValueError – Samples per batch and number of batches must be positive integers.

Return type

list[ndarray]

postselect_and_subsample

postselect_and_subsample(bitstring_matrix, probabilities, *, hamming_right, hamming_left, samples_per_batch, num_batches, rand_seed=None)

GitHub

Subsample batches of bit arrays with correct hamming weight from an input bitstring_matrix.

Bitstring samples with incorrect hamming weight on either their left or right half will not be sampled.

Each individual batch will be sampled without replacement from the input bitstring_matrix. Samples will be replaced after creation of each batch, so different batches may contain identical samples.

Parameters

  • bitstring_matrix (ndarray) – A 2D array of bool representations of bit values such that each row represents a single bitstring.
  • probabilities (ndarray) – A 1D array specifying a probability distribution over the bitstrings
  • hamming_right (int) – The target hamming weight for the right half of sampled bitstrings
  • hamming_left (int) – The target hamming weight for the left half of sampled bitstrings
  • samples_per_batch (int) – The number of samples to draw for each batch
  • num_batches (int) – The number of batches to generate
  • rand_seed (Generator |int | None) – A seed to control random behavior

Returns

A list of bitstring matrices with correct hamming weight subsampled from the input bitstring matrix

Raises

  • ValueError – The number of elements in probabilities must equal the number of rows in bitstring_matrix.
  • ValueError – Hamming weights must be non-negative integers.
  • ValueError – Samples per batch and number of batches must be positive integers.

Return type

list[ndarray]

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