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

Support arbitrary generating terms in pulse Hamiltonians with stoch_pulse_grad #4132

Merged
merged 64 commits into from May 29, 2023

Conversation

dwierichs
Copy link
Contributor

@dwierichs dwierichs commented May 16, 2023

Context:
Thus far, the gradient transform stoch_pulse_grad only supports Pauli words as generating terms in the pulse Hamiltonian.

Description of the Change:
This PR generalizes the support to arbitrary generating terms, using the existing generalized shift rule framework.
The inserted operations are no longer PauliRot gates but Exp operators, because for non-Pauli word generators, the decomposition into Pauli rotation gates is not always desired.
Decomposing Exp operations with Pauli words in the exponent yields back the PauliRot operations used by stoch_pulse_grad until now.

Benefits:
Support many more pulse Hamiltonians, in particular e.g. neutral atom Hamiltonians.

Possible Drawbacks:
Breaking change: For Pauli word-generated terms, the inserted operations are now Exp operations instead of PauliRot gates.

Open TODOs

  • Add example of non-Pauli word generator to docstring.
  • Add JIT-compatibility test with non-Pauli word generator.

[sc-34236]

@codecov
Copy link

codecov bot commented May 16, 2023

Codecov Report

Merging #4132 (fc4adc5) into master (6ab9dda) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #4132   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files         340      340           
  Lines       30595    30607   +12     
=======================================
+ Hits        30525    30537   +12     
  Misses         70       70           
Impacted Files Coverage Δ
pennylane/gradients/pulse_gradient.py 100.00% <100.00%> (ø)
pennylane/ops/op_math/symbolicop.py 100.00% <100.00%> (ø)

Base automatically changed from hybrid-pulse-diff-0 to master May 18, 2023 09:37
@dwierichs dwierichs requested a review from Qottmann May 19, 2023 12:36
Copy link
Contributor

@Qottmann Qottmann left a comment

Choose a reason for hiding this comment

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

Very nice upgrade @dwierichs 💪

Much appreciate the developer comments 🤩

There is a slight performance regression on the first execution as ParametrizedHamiltonian gets jit compiled inside the ODE solver (because the ode fun is jit-compiled), most likely due to the extra steps from qml.exp, so dont think there is much we can do. Could short-cut the execution by checking whether it is a pauli word, but that might make the code significantly uglier.

Execution time seems unchanged 👍

tests/gradients/core/test_pulse_gradient.py Show resolved Hide resolved
@dwierichs
Copy link
Contributor Author

dwierichs commented May 20, 2023

Could short-cut the execution by checking whether it is a pauli word, but that might make the code significantly uglier.

I tried this and it seems to be fine to me, actually 😇 Let me know what you think :)

edit: The definition of qml.pauli.is_pauli_word includes rescaled Pauli words. Therefore, we will need a function that extracts a rescaling parameter from a Pauli word (which is allowed to be a Hamiltonian, SProd, Prod, Tensor or atomic Pauli operator). I think it's nice to add this, but I'd do it in a separate PR, in case we want the simplification Exp->PauliRot for the inserted operations.

Copy link
Contributor

@Qottmann Qottmann left a comment

Choose a reason for hiding this comment

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

Very neat upgrade with not many changes in code and tests, really nice work @dwierichs 👌

With the upcoming short-cutting for Pauli-words looks good to me 🙂

@dwierichs
Copy link
Contributor Author

@Qottmann while fixing the bug in #4156 I found a simple way to extract the prefactor of a Pauli word that I didn't see before. I used this to implement the PauliRot shortcut for Pauli words in this PR :)
This includes single-term Hamiltonians, SProd instances and (tensor products of) simple Pauli operators.

Copy link
Contributor

@rmoyard rmoyard left a comment

Choose a reason for hiding this comment

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

Couple of questions and suggestion, otherwise it looks good 💯

pennylane/gradients/pulse_gradient.py Outdated Show resolved Hide resolved
pennylane/gradients/pulse_gradient.py Show resolved Hide resolved
pennylane/gradients/pulse_gradient.py Show resolved Hide resolved
tests/gradients/core/test_pulse_gradient.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Qottmann Qottmann left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the short-cut for pauli words 👌 Jit times look much better compared to current master for those cases. Execution time is the same 👍

tests/gradients/core/test_pulse_gradient.py Show resolved Hide resolved
pennylane/gradients/pulse_gradient.py Show resolved Hide resolved
@dwierichs dwierichs requested a review from rmoyard May 24, 2023 11:55
Copy link
Contributor

@rmoyard rmoyard left a comment

Choose a reason for hiding this comment

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

Thanks a lot! 👍

@rmoyard rmoyard merged commit 64f561a into master May 29, 2023
43 checks passed
@rmoyard rmoyard deleted the pulse-diff-4 branch May 29, 2023 18:23
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.

None yet

3 participants