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

fix and enable pulse gradient with broadcasting on new device #4620

Merged
merged 4 commits into from Sep 21, 2023

Conversation

timmysilv
Copy link
Contributor

Context:
Enabling this was missed in the DQ2 switch-over. We originally said that ParametrizedEvolution should fail to apply to broadcasted states, but pulse_generator and stoch_pulse_grad have custom handling for certain cases, so we ought not be so decisive in apply_operation. That said, if the inputted state is batched but the operator is not, then we're in trouble.

Description of the Change:

  • Only raise the batched-state-ParametrizedEvolution error when the op is not itself batched
  • put shots on tapes created by pulse_generator (missed in gradient uses tape shots upgrade)
  • change test_jax at the bottom of each gradient test file to use "backprop" instead of None for the gradient_fn. This worked as-is on DefaultQubitJax because it has a passthru_interface set, but really it's using backprop. Maybe that boolean needs more work, but this seemed like a niche-enough test case, so I fixed the test instead of the code.

Benefits:
pulse gradients work with the new device and use_broadcasting=True!

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (e67ad81) 99.62% compared to head (91a7f0e) 99.62%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4620   +/-   ##
=======================================
  Coverage   99.62%   99.62%           
=======================================
  Files         375      375           
  Lines       33486    33486           
=======================================
+ Hits        33361    33362    +1     
+ Misses        125      124    -1     
Files Changed Coverage Δ
pennylane/gradients/pulse_generator_gradient.py 100.00% <ø> (ø)
pennylane/devices/qubit/apply_operation.py 99.21% <100.00%> (+0.78%) ⬆️

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

@timmysilv timmysilv requested a review from a team September 20, 2023 21:34
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

👍

@timmysilv timmysilv enabled auto-merge (squash) September 21, 2023 19:06
@timmysilv timmysilv merged commit f2d784d into master Sep 21, 2023
39 checks passed
@timmysilv timmysilv deleted the fix-pulse-new-device branch September 21, 2023 19:44
mudit2812 pushed a commit that referenced this pull request Sep 22, 2023
**Context:**
Enabling this was missed in the DQ2 switch-over. We originally said that
`ParametrizedEvolution` should fail to apply to broadcasted states, but
`pulse_generator` and `stoch_pulse_grad` have custom handling for
certain cases, so we ought not be so decisive in `apply_operation`. That
said, if the inputted state is batched but the operator is not, then
we're in trouble.

**Description of the Change:**
- Only raise the batched-state-ParametrizedEvolution error when the op
is not itself batched
- put shots on tapes created by `pulse_generator` (missed in gradient
uses tape shots upgrade)
- change `test_jax` at the bottom of each gradient test file to use
`"backprop"` instead of `None` for the `gradient_fn`. This worked as-is
on `DefaultQubitJax` because it has a [passthru_interface
set](https://github.com/PennyLaneAI/pennylane/blob/e909e56a197cbdea772449e972a12da4931cf2b8/pennylane/interfaces/execution.py#L581),
but really it's using backprop. Maybe that boolean needs more work, but
this seemed like a niche-enough test case, so I fixed the test instead
of the code.

**Benefits:**
pulse gradients work with the new device and `use_broadcasting=True`!
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