PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.36k stars 604 forks source link

Fix sparse matrix with global phase #6197

Closed albi3ro closed 2 months ago

albi3ro commented 2 months ago

Calculating the sparse matrix for a product containing a global phase was causing an error:

op = qml.GlobalPhase(0.5) @ qml.X(0) @ qml.X(0)
op.sparse_matrix(wire_order=(0,1))

expand_matrix was not able to handle an operator with no wires. So this is just a little patch for that case.

github-actions[bot] commented 2 months ago

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

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (v0.38.0-rc0@39220ed). Learn more about missing BASE report.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## v0.38.0-rc0 #6197 +/- ## ============================================== Coverage ? 99.66% ============================================== Files ? 445 Lines ? 42389 Branches ? 0 ============================================== Hits ? 42247 Misses ? 142 Partials ? 0 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.