Skip to content
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

Sparse state preparation via alias sampling #1067

Merged
merged 25 commits into from
Jul 17, 2024

Conversation

anurudhp
Copy link
Contributor

@anurudhp anurudhp commented Jun 12, 2024

fixes #1059

@anurudhp anurudhp force-pushed the 2024-06-sparse-SP branch from 4a4d0a0 to 9370394 Compare June 12, 2024 20:20
@anurudhp anurudhp force-pushed the 2024-06-sparse-SP branch from 6d87202 to b2a0fc2 Compare June 13, 2024 22:52
@anurudhp anurudhp changed the title [WIP] sparse state preparation via alias sampling sparse state preparation via alias sampling Jun 13, 2024
@anurudhp anurudhp changed the title sparse state preparation via alias sampling Sparse state preparation via alias sampling Jun 13, 2024
@anurudhp anurudhp marked this pull request as ready for review June 13, 2024 23:00
@anurudhp
Copy link
Contributor Author

@tanujkhattar PTAL

@tanujkhattar tanujkhattar self-assigned this Jun 24, 2024
Copy link
Collaborator

@tanujkhattar tanujkhattar left a 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.

Comment on lines 242 to 258
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.
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defined sparsity $d$ and total size $L$, and updated explanation

@classmethod
def from_lcu_probs(
cls,
lcu_probabilities: Sequence[float],
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Comment on lines 353 to 354
mu = sub_bit_prec_from_epsilon(n_coeff, probability_epsilon)
selection_bitsize = bit_length(n_coeff - 1)
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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.

@anurudhp
Copy link
Contributor Author

Symbolic costs for sparsity $d$ out of $L$ and precision $\epsilon$:
image

(from the _sparse_state_prep_alias_symb bloq example)

@anurudhp anurudhp requested a review from tanujkhattar July 16, 2024 07:46
@tanujkhattar tanujkhattar merged commit 301e3cf into quantumlib:main Jul 17, 2024
7 checks passed
@anurudhp anurudhp deleted the 2024-06-sparse-SP branch July 17, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

State preparation via alias sampling for sparse state preparation
3 participants