qiskit_addon_sqd.subsampling.postselect_and_subsample

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

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 (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]