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.29k stars 590 forks source link

Treat batch size of 1 as a batch size #6147

Closed albi3ro closed 1 month ago

albi3ro commented 1 month ago

Context:

Our result type spec does often squeeze out singleton dimensions, such as those arising from a single measurement, or a shot vector of length 1.

But we have an inconsistency around whether or not a batch size of 1, op.batch_size == 1 is considered an actual batch size or a dimension to squeeze out. I would consider a batch size of 1 different than a batch_size of None, and worth maintaining. This was already the behaviour of default.qubit, and is generally how parameter broadcasting works.

Description of the Change:

Eliminates squeezing steps from broadcast_expand.

Benefits:

Consistent, predictable handling of batch dimensions.

Possible Drawbacks:

Someone might have been depending on the squeezing behaviour. That code might now break. This may be risky, especially this close to the release.

Related GitHub Issues:

[sc-68244] Fixes #5977

github-actions[bot] commented 1 month ago

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

codecov[bot] commented 1 month ago

Codecov Report

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

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

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

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