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)
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 inbitstring_matrix
. - ValueError – Samples per batch and number of batches must be positive integers.
Return type
postselect_and_subsample
postselect_and_subsample(bitstring_matrix, probabilities, *, hamming_right, hamming_left, samples_per_batch, num_batches, rand_seed=None)
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.
The function qiskit_addon_sqd.subsampling.postselect_and_subsample()
is deprecated as of qiskit-addon-sqd 0.12.0. It will be removed no earlier than v0.13.0. Instead, use the postselect_by_hamming_right_and_left
and subsample
functions.
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 inbitstring_matrix
. - ValueError – Hamming weights must be non-negative integers.
- ValueError – Samples per batch and number of batches must be positive integers.
Return type
postselect_by_hamming_right_and_left
postselect_by_hamming_right_and_left(bitstring_matrix, probabilities, *, hamming_right, hamming_left)
Postselect bitstrings based on desired Hamming weight on right and left halves.
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
Returns
Postselected bitstring matrix and probabilities. The new bitstring matrix contains only those bitstrings from the original matrix that have the desired Hamming weight on the right and left halves, and the new probabilities are constructed by taking the original probabilities corresponding to the postselected bitstrings and rescaling them to sum to one.
Raises
- ValueError – Hamming weights must be non-negative integers.
- ValueError – The number of columns in
bitstring_matrix
must be even. - ValueError – The number of elements in
probabilities
must equal the number of rows inbitstring_matrix
.
Return type