pennylane icon indicating copy to clipboard operation
pennylane copied to clipboard

Compute matrix of only the operators that act on overlapping wires

Open AlbertMitjans opened this issue 2 years ago • 6 comments

  • 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.

AlbertMitjans avatar Sep 19 '22 13:09 AlbertMitjans

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.

github-actions[bot] avatar Sep 19 '22 13:09 github-actions[bot]

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.

codecov[bot] avatar Sep 19 '22 13:09 codecov[bot]

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 avatar Sep 19 '22 14:09 AlbertMitjans

Prod operator

  • Before: image

  • After: image

AlbertMitjans avatar Sep 20 '22 09:09 AlbertMitjans

Prod operator matrix computation

  • Before image

  • After image

AlbertMitjans avatar Sep 20 '22 10:09 AlbertMitjans

[sc-26176]

AlbertMitjans avatar Sep 20 '22 13:09 AlbertMitjans