Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shape error for tensor-like parameters in pauli arithmetic fixed (Addition to PR: #6562) #6681

Closed
wants to merge 23 commits into from

Conversation

ldi18
Copy link
Contributor

@ldi18 ldi18 commented Dec 5, 2024

Context:
I added Pauli string decompositions for non-parametrized gates in PR: #6562. In the initial version of PR: #6562 also included Pauli string decompositions for single-qubit parametrized gates - they had to be removed for now because of issues in CI testing - but the bug below remains relevant as it might surface again once more Pauli-reps are added:

Pennylane can exploit Pauli string representations when, for example, computing

(qml.RX(1.11, wires=0) @ qml.RY(1.23, wires=0)).matrix()

The example above works as intended, but for tensor-like parameters as in

(qml.RX([1.11, 2.11, 3.11], wires=0) @ qml.RY([1.23, 2.23, 3.23], wires=0)).matrix()     # shape error

or

(qml.RX(np.array([1.11, 2.11, 3.11]), wires=0) @ qml.RY(np.array([1.23, 2.23, 3.23]), wires=0)).matrix()     # shape error

a shape error is returned. The code above should work since RXand RYsupport tensor-like (flattened) parameters as it can be seen from

qml.RX([1.11, 2.11, 3.11], wires=0).matrix()    # works!

Description of the Change:

I added an outer product in pauli_arithmetic.

Benefits:

  • (Future) Pauli representations of parametrized gates can be leveraged for the matrix conversion of products of ops.
  • A Pauli representation of the PhaseShift gate could be added - this was not possible before as the PCPhase gate used the pauli_arithmetic, which gave an error in the pytests.

Possible Drawbacks:
None

Related GitHub Issues:
#6243 and PR: #6562

Lasse Dierich and others added 23 commits November 10, 2024 00:47
Co-authored-by: David Wierichs <[email protected]>
Co-authored-by: David Wierichs <[email protected]>
Co-authored-by: David Wierichs <[email protected]>
@ldi18 ldi18 closed this Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants