-
Notifications
You must be signed in to change notification settings - Fork 82
Sparse state preparation via alias sampling #1067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
4a4d0a0 to
9370394
Compare
6d87202 to
b2a0fc2
Compare
|
@tanujkhattar PTAL |
qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py
Outdated
Show resolved
Hide resolved
qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py
Outdated
Show resolved
Hide resolved
tanujkhattar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start, left a round of comments.
| In particular, we take the zero state to: | ||
| $$ | ||
| \sum_{l=0}^{L-1} \sqrt{p_l} |\mathrm{ind}_l\rangle |\mathrm{temp}_\ell\rangle | ||
| $$ | ||
| where $\mathrm{ind}_l$ is the index of the $l$-th non-zero coefficient, | ||
| and the probabilities $p_\ell$ are $\mu$-bit binary approximations to the true values and | ||
| where the temporary register must be treated with care, see the details in Section 5 of | ||
| reference [1] and Section III.D. of the reference [2]. | ||
| The preparation is equivalent to [classical alias sampling] | ||
| (https://en.wikipedia.org/wiki/Alias_method): we sample `l` with probability `p[l]` by first | ||
| selecting `l` uniformly at random and then returning `ind[l]` with probability `keep[l] / 2**mu`; | ||
| otherwise returning `alt[l]`. | ||
| This bloq is nearly identical to :class:`StatePreparationByAliasSampling`, except that this loads | ||
| the non-zero coefficient indices as well from the QROM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should ask users to read docstring of StatePreparationAliasSampling to understand how alias sampling works and describe the reduction from sparse state preparation to dense state preparation in this docstring; similar to how its described in Ref[1].
We should explicitly define symbols for sparsity (S) and dimension n of the selection register (s.t. N = 2^n) and say how we wish to do state preparation that scales as S instead of N.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defined sparsity
qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py
Outdated
Show resolved
Hide resolved
| @classmethod | ||
| def from_lcu_probs( | ||
| cls, | ||
| lcu_probabilities: Sequence[float], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change the input format and expect a dictionary Dict[int, float] that specifies the coefficients for the sparse indices? We can construct a dense lcu_probabilities as part of the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this makes more sense, I added this as the default method
qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py
Outdated
Show resolved
Hide resolved
qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py
Outdated
Show resolved
Hide resolved
| mu = sub_bit_prec_from_epsilon(n_coeff, probability_epsilon) | ||
| selection_bitsize = bit_length(n_coeff - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this should be n_coeff and not n_nonzero_coeff ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is n_coeff. The selection register actually stays the same as the true LCU selection register (i.e. over [0, L)). I use an extra junk register called sparse_index which iterates over [0, d) (d = sparsity), which is used to prepare the state.

fixes #1059