-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update condition for swapping iterators in
PauliWord._matmul
(#5301)
**Context:** We found that the wire order in `Sum/Prod.terms` was being swapped for the first and second term in terms that were `Prod`s. This was due to the use of the `pauli_rep`. While building the pauli rep, we use `PauliWord._matmul` which swaps the order of `self` and `other` if `len(other) >= len(self)` so that we iterate through the larger `PauliWord`. Example: ```python H = qml.prod(X(0), X(1), X(2)) Sum_coeffs, Sum_ops = H.terms() ``` ```pycon >>> Sum_ops[0].wires, H.wires (<Wires = [1, 0, 2]>, <Wires = [0, 1, 2]>) ``` **Description of the Change:** Changed the condition for swapping from `len(other) >= len(self)` to `len(other) > len(self)`. **Benefits:** More consistent `Sum/Prod.pauli_rep`, and `Sum/Prod.terms()` with the original operands. The above example now behaves as follows: ```python H = qml.prod(X(0), X(1), X(2)) Sum_coeffs, Sum_ops = H.terms() ``` ```pycon >>> Sum_ops[0].wires, H.wires (<Wires = [0, 1, 2]>, <Wires = [0, 1, 2]>) ``` **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: qottmann <korbinian.kottmann@gmail.com>
- Loading branch information
Showing
8 changed files
with
47 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters