qml.select_sos_rows

select_sos_rows(bits)[source]

Select rows of a bit array of differing columns such that the stacked array of the selected rows still contains differing columns. Also memorizes the row indices of the input array that were selected.

Parameters:

bits (np.ndarray) – Bit array with differing columns

Returns:

Selected row indices to obtain the reduced bit array, and the reduced bit array itself. If bits had shape (n_rows, n_cols) and the list of row indices has length r, the reduced bit array has shape (r, n_cols).

Return type:

tuple[list[int], np.ndarray]

Note

This function does not come with an optimality guarantee about the number of selected rows. That is, there may be selections of fewer rows that maintain differing columns.

Under the hood, this method is not selecting rows, but instead greedily removes rows from the input. We first attempt to remove rows with a mean weight far away from 0.5, as they are generically less likely to differentiate many columns from each other.

Example

Let’s generate a random bit array of D = 8 differing columns of length n = 6, by first sampling unique integers from the range (0, 2**n) and converting them to bitstrings.

>>> np.random.seed(31)
>>> D = 8
>>> n = 6
>>> ids = np.random.choice(2**n, size=D, replace=False)
>>> bitstrings = qml.math.int_to_binary(ids, width=n).T
>>> print(bitstrings)
[[0 0 0 1 0 0 1 0]
 [0 0 0 1 0 1 1 1]
 [0 0 0 0 0 1 0 0]
 [0 1 1 1 1 1 1 1]
 [1 0 0 1 1 1 0 0]
 [0 0 1 1 1 0 1 1]]

Then let’s select rows that maintain the uniqueness of the rows:

>>> from pennylane.templates.state_preparations.sum_of_slaters import select_sos_rows
>>> selectors, new_bits = select_sos_rows(bitstrings)
>>> selectors
[0, 1, 4, 5]

Indeed, selecting the indicated rows of bitstrings, we still find unique columns:

>>> print(new_bits)
[[0 0 0 1 0 0 1 0]
 [0 0 0 1 0 1 1 1]
 [1 0 0 1 1 1 0 0]
 [0 0 1 1 1 0 1 1]]

In general, the number of rows \(r\) selected by the method will satisfy \(\log_2(n_{\text{col}})\leq r\leq \min(n_{\text{row}}, n_{\text{col}})\) if \((n_{\text{row}}, n_{\text{col}})\) is the shape of the input array.

Contents

Using PennyLane

Release news

Development

API

Internals