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

QubitizationWalkOperator add attribute: sum of LCU coefficients #890

Merged
merged 8 commits into from
Apr 29, 2024

Conversation

anurudhp
Copy link
Contributor

fixes #868

The sum of coefficients determines the complexity of hamiltonian simulation. This will also enable us to propagate symbolic values to the prepare gate.

@tanujkhattar could you review this? Also it would be great if someone with qchem expertise checks whether the sum of coeffs for the Hubbard gate is correct.

@@ -64,6 +67,7 @@ class QubitizationWalkOperator(GateWithRegisters):

select: SelectOracle
prepare: PrepareOracle
sum_of_ham_coeffs: Optional[float]
Copy link
Collaborator

Choose a reason for hiding this comment

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

The default value here should be 1 or something else?

Copy link
Contributor Author

@anurudhp anurudhp Apr 25, 2024

Choose a reason for hiding this comment

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

I didn't set a default to avoid accidentally forgetting it while building walk ops

But as the sum_of_ham_coeffs attribute is not needed in the decomposition/call-graph, it won't break anything. It's only needed for Hamiltonian simulation, in which case it needs to be correctly calculated anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

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

right, I think Optional[float] = None in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would it be better to not have a default, and let the user explicitly specify None when they don't know the value? (just to make sure it's not accidentally omitted)

@fdmalone
Copy link
Collaborator

It's typically called lambda in the literature which is problematic in python as a variable name I know. Maybe sum_of_lcu_coeffs?

@tanujkhattar
Copy link
Collaborator

Is QubitizationWalkOperator the right place to add this attribute? Should we instead add it to the PrepareOracle and just export it as a property in the QubitizationWalkOperator ?

@anurudhp anurudhp force-pushed the 2024-04-qwalkop-scale-factor branch from c8c6269 to aff2de8 Compare April 25, 2024 19:07
@anurudhp
Copy link
Contributor Author

Yes I think that makes sense. That way we can also implicitly compute this value because we usually pass the exact coeffs to Prepare (which are normalized there).

For ex. it would simplify this (we can drop L93)

coeffs = np.array([term.coefficient.real for term in ham])
lcu_coeffs = coeffs / np.sum(abs(coeffs))
return lcu_coeffs

@anurudhp anurudhp force-pushed the 2024-04-qwalkop-scale-factor branch from cc39c78 to cde48eb Compare April 25, 2024 21:07
@anurudhp
Copy link
Contributor Author

@tanujkhattar PTAL

@anurudhp anurudhp force-pushed the 2024-04-qwalkop-scale-factor branch from bd58405 to d84fde2 Compare April 26, 2024 22:16
@anurudhp anurudhp force-pushed the 2024-04-qwalkop-scale-factor branch from cf873a9 to 1d1612f Compare April 27, 2024 12:10
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.

LGTM % nits

@@ -92,6 +94,11 @@ def signature(self) -> Signature:
def reflect(self) -> ReflectionUsingPrepare:
return ReflectionUsingPrepare(self.prepare, control_val=self.control_val, global_phase=-1)

@cached_property
def sum_of_lcu_coefficients(self) -> Optional[float]:
r"""value of $\lambda$, i.e. sum of the coefficients $w_l$."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's clarify by writing "sum of absolute values of coefficients. " instead. In this case, the docstring of the class does clarify that each $w_l$ is a positive integer so it's just a sum of coefficients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

a selection register $|i\rangle$. In order to prepare such a state, the PREPARE circuit is also
allowed to use a junk register that is entangled with selection register.
the coefficients as amplitudes of a state $|\Psi\rangle = \sum_{i=0}^{N-1} \sqrt{\frac{c_{i}}{\lambda}} |i\rangle$
where $\lambda = \sum_i c_i$, using a selection register $|i\rangle$. In order to prepare such
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
where $\lambda = \sum_i c_i$, using a selection register $|i\rangle$. In order to prepare such
where $\lambda = \sum_i | c_i |$, using a selection register $|i\rangle$. In order to prepare such

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


@property
def l1_norm_of_coeffs(self) -> Optional['SymbolicFloat']:
r"""Sum of the coefficients $c_i$.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
r"""Sum of the coefficients $c_i$.
r"""Sum of the absolute values of coefficients $c_i$.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@tanujkhattar tanujkhattar enabled auto-merge (squash) April 29, 2024 20:14
@tanujkhattar tanujkhattar merged commit e6d6e01 into quantumlib:main Apr 29, 2024
6 checks passed
@anurudhp anurudhp deleted the 2024-04-qwalkop-scale-factor branch April 29, 2024 20:40
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.

QubitizationWalkOperator: add normalization factor to the API
3 participants