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

Introduce device capability flag and default handler for parameter broadcasting #2590

Merged
merged 53 commits into from
Jun 3, 2022

Conversation

dwierichs
Copy link
Contributor

@dwierichs dwierichs commented May 18, 2022

Context:
This PR is the second one to introduce parameter broadcasting, following up on #2575.

Description of the Change:
Here we introduce the device capability flag "supports_broadcasting" and a tape expansion function unbroadcast_expand (a batch_transform) that expands broadcasted tapes into unbroadcasted ones. This function is then used in device.batch_transform to expand broadcasted tapes whenever the device does not support broadcasting.

Benefits:

  • Devices know whether they support broadcasting.
  • Devices can handle broadcasted tapes even if they do not support broadcasting, simply by expanding such tapes into multiple tapes.

Possible Drawbacks:

  • (unlikely:) Performance decrease when using broadcasted tapes due to additional transform efforts.

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov
Copy link

codecov bot commented May 18, 2022

Codecov Report

Merging #2590 (2259ce0) into master (3344c77) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           master    #2590    +/-   ##
========================================
  Coverage   99.58%   99.58%            
========================================
  Files         245      246     +1     
  Lines       19724    19874   +150     
========================================
+ Hits        19642    19792   +150     
  Misses         82       82            
Impacted Files Coverage Δ
pennylane/_device.py 98.11% <100.00%> (+0.03%) ⬆️
pennylane/math/single_dispatch.py 98.85% <100.00%> (+<0.01%) ⬆️
pennylane/operation.py 96.58% <100.00%> (+0.04%) ⬆️
pennylane/ops/functions/matrix.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/attributes.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/matrix_ops.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/parametric_ops.py 100.00% <100.00%> (ø)
pennylane/transforms/__init__.py 100.00% <100.00%> (ø)
pennylane/transforms/broadcast_expand.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3344c77...2259ce0. Read the comment docs.

@dwierichs dwierichs requested a review from josh146 May 19, 2022 23:37
Copy link
Member

@josh146 josh146 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 and clean PR @dwierichs! Mostly left questions, but don't forget to also (a) add this PR to the changelog, and (b) ensure the new docstring appears in the docs

pennylane/_device.py Show resolved Hide resolved
pennylane/_device.py Show resolved Hide resolved
pennylane/_device.py Outdated Show resolved Hide resolved
pennylane/_device.py Outdated Show resolved Hide resolved
pennylane/transforms/unbroadcast_expand.py Outdated Show resolved Hide resolved
pennylane/transforms/unbroadcast_expand.py Outdated Show resolved Hide resolved
pennylane/transforms/unbroadcast_expand.py Outdated Show resolved Hide resolved
tests/devices/test_default_qubit.py Show resolved Hide resolved
tests/devices/test_default_qubit.py Show resolved Hide resolved
tests/transforms/test_unbroadcast_expand.py Outdated Show resolved Hide resolved
@dwierichs
Copy link
Contributor Author

[sc-19789]

pennylane/_device.py Outdated Show resolved Hide resolved
Base automatically changed from parameter-broadcasting-0 to master May 24, 2022 14:13
@dwierichs dwierichs requested a review from josh146 May 24, 2022 14:59
Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

Thanks @dwierichs!

pennylane/transforms/broadcast_expand.py Outdated Show resolved Hide resolved
requirements-ci.txt Outdated Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
dwierichs and others added 9 commits June 2, 2022 17:11
…tions (#2609)

* commit old changes

* intermed

* clean up, move broadcast dimension first

* update tests that manually set ndim_params for default ops

* pin protobuf<4.21.0

* improve shape coersion order

* changelog formatting

* broadcasted pow tests

* attribute test, ControlledQubitUnitary update

* test kwargs attributes

* Apply suggestions from code review

Co-authored-by: Josh Izaac <josh146@gmail.com>

* changelog

* review

* remove prints

* explicit attribute supports_broadcasting tests

* tests disentangle

* fix

* PauliRot broadcasted identity compatible with TF

* rename "batched" into "broadcasted" for uniform namespace

* old TF version support in qubitunitary unitarity check

* python3.7 support

* Apply suggestions from code review

Co-authored-by: Josh Izaac <josh146@gmail.com>

* linebreak

Co-authored-by: Josh Izaac <josh146@gmail.com>
@dwierichs dwierichs merged commit 85cc93f into master Jun 3, 2022
@dwierichs dwierichs deleted the parameter-broadcasting-1 branch June 3, 2022 08:24
@ankit27kh ankit27kh mentioned this pull request Jun 11, 2022
1 task
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.

2 participants