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

Make Exp.decomposition jit compatible #6082

Merged
merged 12 commits into from
Aug 9, 2024
Merged

Make Exp.decomposition jit compatible #6082

merged 12 commits into from
Aug 9, 2024

Conversation

astralcai
Copy link
Contributor

@astralcai astralcai commented Aug 7, 2024

Context:
The result of Exp.decomposition depends whether the coefficient is purely imaginary or not, which makes it incompatible with qjit.

Description of the Change:

Change Exp.decomposition to queue decomposed operations in a temporary queueing context, and then convert it to a list of operations, making it compatible with qml.cond

Change Exp.decomposition to not raise an error when the coefficient is real.

Benefits:
Workflows that involve Exp are now compatible with qjit and jax.jit

Possible Drawbacks:
This is a very hacky solution.
Exp.decomposition is still not compatible with jax.jit.

When applying qml.exp on an operator with real coefficients, in a jitted context, no error is thrown.

Related GitHub Issues:
Fixes PennyLaneAI/catalyst#923
Also Fixes #5993
[sc-68711]

Copy link

codecov bot commented Aug 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.65%. Comparing base (6e05a16) to head (0c7ec41).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6082      +/-   ##
==========================================
- Coverage   99.66%   99.65%   -0.01%     
==========================================
  Files         430      430              
  Lines       41836    41548     -288     
==========================================
- Hits        41697    41406     -291     
- Misses        139      142       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@astralcai astralcai requested a review from dime10 August 8, 2024 14:15
@astralcai astralcai marked this pull request as ready for review August 8, 2024 14:29
@astralcai astralcai changed the title Make Exp.decomposition qjit compatible Make Exp.decomposition jit compatible Aug 8, 2024
Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Few comments and questions. Overall looking good :)

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/devices/default_qubit.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
tests/ops/op_math/test_exp.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

Thanks @astralcai for providing this fix 💯

pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
@astralcai astralcai merged commit 50dbd38 into master Aug 9, 2024
40 checks passed
@astralcai astralcai deleted the exp-decomp branch August 9, 2024 21:01
dime10 added a commit to PennyLaneAI/catalyst that referenced this pull request Aug 29, 2024
PennyLaneAI/pennylane#6082 unearthed that in an
attempt to be more lenient with user supplied types, Catalyst eagerly
converts any type to the required float64 type for gate parameters,
including when this results in a loss of data (like converting complex
numbers to floats).

This fixes the issue as well as providing some minor code cleanup, and
fixing a long-standing issue of potentially undefined variables in the
Python code.

In order to help users with the proposed fix in [#pennylane/6082
](PennyLaneAI/pennylane#6082) for the
decomposition of `Exp`, the error message for complex gate parameters
mentions potential non-unitary operators like the exponential with real
exponent.

[sc-71066]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants