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

Removing ambiguity in `PauliRot` error message. #6298

Closed willjmax closed 1 month ago

willjmax commented 1 month ago

Context: For the input of PauliRot the number of wires given must equal the length of the given Pauli word. Otherwise a ValueError is raised. For example, op = qml.PauliRot(0.5, "XY", wires=[0,1,2]) results in ValueError: The given Pauli word has length 2, length 3 was expected for wires [0,1,2].

However, this message can be ambiguous. op = qml.PauliRot(0.5, "XYZZXYI", wires=[0]) raises the exception ValueError: The given Pauli word has length 7, length 1 was expected for wires [0]. It's unclear if "length 1" refers to the length of the Pauli word or the length of the wires.

Description of the Change: This PR changes the error message to remove the ambiguity. Now it will say ValueError: The number of wires must be equal to the length of the Pauli Word. The Pauli word XY has length 2, and 3 wires were given [0, 1, 2].

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:

Project coverage is 99.70%. Comparing base (d892b10) to head (b16b9ff). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #6298 +/- ## ======================================= Coverage 99.70% 99.70% ======================================= Files 444 444 Lines 42235 42235 ======================================= Hits 42112 42112 Misses 123 123 ```

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