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

Add pauli_rep property to Adjoint when possible #6876

Closed
albi3ro opened this issue Jan 23, 2025 · 8 comments
Closed

Add pauli_rep property to Adjoint when possible #6876

albi3ro opened this issue Jan 23, 2025 · 8 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@albi3ro
Copy link
Contributor

albi3ro commented Jan 23, 2025

Context:

The Operator.pauli_rep property is a provides an efficient representation of an operator as a linear combination of pauli's, if the operator is an obvious linear combination of pauli's.

>>> (qml.X(0) + 2 * qml.Y(0)).pauli_rep
1.0 * X(0)
+ 2.0 * Y(0)
>>> (qml.X(0) ** 3).pauli_rep
1.0 * X(0)
>>> qml.RX(0.5, 0).pauli_rep is None
True

The returned object is a special dictionary mapping pauli words to coefficients, the PauliSentence

Currently, the pauli_rep for any Adjoint class is None.

>>> qml.adjoint(qml.X(0)).pauli_rep  is None
True

But if the target has a pauli rep, we should be able to provide one on the Adjoint class. We only need to take the conjugate of all the coefficients. You can see similar "modify pauli rep of target" behavior in our SProd (scalar product) class:

pr = {pw: qnp.dot(coeff, scalar) for pw, coeff in base_pauli_rep.items()}

The task

This issue would require initializing the _pauli_rep during initialization of all Adjoint operators to be the adjoint of the target's pauli rep.

The PR should also:

@albi3ro albi3ro added the good first issue Good for newcomers label Jan 23, 2025
@vivek-kumar9696
Copy link

Hi! I would like to take up this issue. Is there anyone else working on it ?
This is my first time trying to contribute to open source codebase and I wanted to know if issues are only assigned after a PR has been raised.

Thanks!!

@albi3ro
Copy link
Contributor Author

albi3ro commented Jan 24, 2025

Thanks for reaching out @vivek-kumar9696 . I've assigned you the issue.

If you have any questions, feel free to either reach out here, or open up a draft PR to start a discussion there.

@vivek-kumar9696
Copy link

@albi3ro Thanks for the reply. I will provide biweekly updates regularly.
Excited to work on this and close my first issue!!

@Hazarre
Copy link
Contributor

Hazarre commented Feb 16, 2025

Hi @albi3ro,

Love to give this a try as well. Would that be cool?

@Hazarre
Copy link
Contributor

Hazarre commented Feb 16, 2025

@albi3ro I created a draft PR for your review.

@albi3ro
Copy link
Contributor Author

albi3ro commented Feb 18, 2025

@vivek-kumar9696 since @Hazarre has already opened a PR, I'm going to go ahead and review that one. I'll try and come up with some more issues for external contributions.

Hazarre added a commit to Hazarre/pennylane that referenced this issue Feb 20, 2025
albi3ro added a commit that referenced this issue Feb 20, 2025
**Context:** #6876

**Description of the Change:** add pauli_rep property for adjoint
operation

**Benefits:** pauli_rep property is available after adjoint operation

**Possible Drawbacks:** impact downstream functions that relies on
pauli_rep

**Related GitHub Issues:** #6876

---------

Co-authored-by: Christina Lee <[email protected]>
@vivek-kumar9696
Copy link

@vivek-kumar9696 since @Hazarre has already opened a PR, I'm going to go ahead and review that one. I'll try and come up with some more issues for external contributions.

@albi3ro No problem. I'll try working on some other issue. Thanks!!

@albi3ro
Copy link
Contributor Author

albi3ro commented Feb 24, 2025

Cloed by #6971 .

@albi3ro albi3ro closed this as completed Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants