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

Compute matrix of only the operators that act on overlapping wires #3084

Merged
merged 24 commits into from
Oct 28, 2022

Conversation

AlbertMitjans
Copy link
Contributor

@AlbertMitjans AlbertMitjans commented Sep 19, 2022

  • Add overlapping_ops property to the Composite class.
  • Improve performance of eigvals, diagonalizing_gates and Prod.matrix methods using the aforementioned property.
  • Move eigvals method to the Composite class. To do so I defined a new class attribute that defines the math operator that will be applied to the operands eigenvalues (math.prod for Prod and math.sum for Sum).

Notes:

When computing the eigvals or diagonalizing_gates of a Composite operator, we computed the whole matrix when the operands had overlapping wires.

Now we separate the operands into subgroups that commute with each other, and only compute the matrices of these subgroups.

@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 Sep 19, 2022

Codecov Report

Merging #3084 (91518f1) into master (a8a47d5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3084   +/-   ##
=======================================
  Coverage   99.69%   99.69%           
=======================================
  Files         276      276           
  Lines       24232    24273   +41     
=======================================
+ Hits        24159    24200   +41     
  Misses         73       73           
Impacted Files Coverage Δ
pennylane/ops/op_math/composite.py 100.00% <100.00%> (ø)
pennylane/ops/op_math/prod.py 100.00% <100.00%> (ø)
pennylane/ops/op_math/sum.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@AlbertMitjans
Copy link
Contributor Author

AlbertMitjans commented Sep 19, 2022

Sum operator

  • Before:
    image

  • After:

image

The wires of the summands are sampled randomly. We can see that there is a huge speedup when there is a subset of operators that act on overlapping wires.

@AlbertMitjans AlbertMitjans marked this pull request as draft September 19, 2022 14:42
@AlbertMitjans
Copy link
Contributor Author

Prod operator

  • Before:

image

  • After:

image

@AlbertMitjans AlbertMitjans marked this pull request as ready for review September 20, 2022 09:36
@AlbertMitjans
Copy link
Contributor Author

Prod operator matrix computation

  • Before

image

  • After

image

@AlbertMitjans
Copy link
Contributor Author

[sc-26176]

@AlbertMitjans AlbertMitjans added the review-ready 👌 PRs which are ready for review by someone from the core team. label Sep 20, 2022
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Looks good! Just a few comments regarding the implementation and it should be good to go 👍🏼

pennylane/ops/op_math/composite.py Show resolved Hide resolved
pennylane/ops/op_math/prod.py Show resolved Hide resolved
pennylane/ops/op_math/composite.py Show resolved Hide resolved
pennylane/ops/op_math/composite.py Outdated Show resolved Hide resolved
tests/ops/op_math/test_composite.py Show resolved Hide resolved
doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
@AlbertMitjans AlbertMitjans requested a review from Jaybsoni October 4, 2022 20:12
@Jaybsoni Jaybsoni added this to the v0.27.0 milestone Oct 27, 2022
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Looks good! Glad to have this in 💯

@AlbertMitjans AlbertMitjans merged commit afb2070 into master Oct 28, 2022
@AlbertMitjans AlbertMitjans deleted the non-overlapping-ops branch October 28, 2022 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants