workbench_algorithms.experimental.utils.alias_sampling_utils
Utilities for alias sampling state prep.
AliasSamplingStatePrepDataProtocol
Bases: Protocol
Protocol for alias sampling state preparation data containers.
is_positive_real
property
Determines whether coefficients are all positive, real values.
probabilities
property
Converts coefficients to corresponding probabilities.
validate_inputs
Check that all input coefficients and types are valid for alias sampling.
trim_register_if_needed
Trim register to appropriate size if too many qubits were provided.
combined_data_list
Helper to combine data output by QROM in alias sampling.
NumericAliasSamplingStatePrepData
dataclass
NumericAliasSamplingStatePrepData(
coeffs: Iterable[float | complex],
bits_of_precision: int | None = None,
lambda_val: int | None = None,
error_param: int | None = None,
)
Numeric implementation of alias sampling state preparation data.
is_positive_real
property
Determines whether self.coeffs are all positive, real values.
probabilities
cached
property
Converts self.coeffs to the corresponding probabilities.
validate_inputs
Check that all input coefficients and types are valid for alias sampling.
trim_register_if_needed
Trim register to appropriate size if too many qubits were provided.
combined_data_list
Helper to combine data output by QROM in alias sampling.
SymbolicAliasSamplingStatePrepData
dataclass
SymbolicAliasSamplingStatePrepData(
coeffs: SymbolicArray,
bits_of_precision: Parameter | None = None,
lambda_val: Parameter | None = None,
error_param: Parameter | None = None,
)
Symbolic implementation of alias sampling state preparation data.
is_positive_real
property
Determines whether self.coeffs are all positive, real values.
probabilities
cached
property
Converts self.coeffs to the corresponding probabilities.
validate_inputs
Check that all input coefficients and types are valid for alias sampling.
trim_register_if_needed
Trim register to appropriate size if too many qubits were provided.
combined_data_list
Helper to combine data output by QROM in alias sampling.
alias_sampling_state_prep_data
alias_sampling_state_prep_data(
coeffs: Iterable[float | complex] | SymbolicArray,
bits_of_precision: int | Parameter | None = None,
lambda_val: int | Parameter | None = None,
error_param: int | Parameter | None = None,
) -> AliasSamplingStatePrepDataProtocol
Create appropriate alias sampling state prep data based on input type.
discretized_prob_distribution_improved
discretized_prob_distribution_improved(
probabilities_list: Iterable[float], bit_precision: int
) -> np.array
Discretizes a probability distribution while preserving the total sum using a rounding correction.
Warning: this function now takes the input parameter in the form of the probabilities (amplitude square) rather than the state vector. This is compatible with the implementation in the experimental branch, and will cause conflict with the original Alias Sampling implementation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probabilities_list
|
Iterable[float]
|
List of non-negative values representing probabilities of coefficients (don't have to be normalized) |
required |
bit_precision
|
int
|
Number of bits to determine the number of discrete levels. |
required |
Returns:
| Type | Description |
|---|---|
array
|
Discretized values that sum to the expected total. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input contains negative values. |
alias_sampling_get_b_from_epsilon
alias_sampling_get_b_from_epsilon(
inputs: Iterable[float],
epsilon: float,
b_upper_bound: int = 1000,
return_theory_bound_and_actual_diff: bool = False,
) -> int | tuple[int, float, float]
Get the number of bits of precision needed for alias sampling to achieve an accuracy epsilon.
Finds the minimum bit precision required such that the 2-norm difference between the normalized input and its discretized version is below an epsilon threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Iterable[float]
|
Input list of values to be normalized and discretized. |
required |
epsilon
|
float
|
Threshold for acceptable 2-norm difference. |
required |
b_upper_bound
|
int
|
Maximum bit precision to search. Default is 1000. |
1000
|
return_theory_bound_and_actual_diff
|
bool
|
a boolean the user to set if they want to return the theory bound and actual l2-norm difference |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
(bit_precision, norm_diff) if a suitable precision is found. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no suitable bit precision is found within the range. |