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

[BUG] probs doesn't work with Pauli words #6941

Open
1 task done
CatalinaAlbornoz opened this issue Feb 7, 2025 · 0 comments
Open
1 task done

[BUG] probs doesn't work with Pauli words #6941

CatalinaAlbornoz opened this issue Feb 7, 2025 · 0 comments
Labels
bug 🐛 Something isn't working

Comments

@CatalinaAlbornoz
Copy link
Contributor

Expected behavior

qml.probs() outputs the correct probabilities when using Pauli words as observables.

This is related to issue #6878 but in this case, because we're working with Pauli words, we may be able to find an easier solution.

Actual behavior

The probabilities are sometimes in the wrong order and sometimes just fully incorrect.

Additional information

For Pauli words, maybe we shouldn't need to take the tensor product of component eigvals, since we know a priori the correct eigenvalues and ordering of the full word.
E.g., this function https://docs.pennylane.ai/en/stable/code/api/pennylane.pauli.pauli_eigs.html should generate the correct eigenvalues in the correct order, the only input needed is the number of Pauli ops.
Optionally, you may then need to permute the list of eigenvalues if the wire order is not the same as the underlying device.

Source code

import pennylane as qml
import numpy as np

dev = qml.device("default.qubit", wires=3)

ob1 = qml.Y(0) @ qml.Y(1) @ qml.X(2)
ob2 = qml.X(2) @ qml.Y(0) @ qml.Y(1)

@qml.qnode(dev)
def circuit():
    qml.RX(0.4,wires=1)
    return qml.probs(op=ob1), qml.probs(op=ob2)

ans = circuit()
# In this case all the answers are different where they shouldn't be
print("ob1: ",ans[0],"ob2: ",ans[1],sep="\n")

Tracebacks

ob1: 
[0.07632271 0.07632271 0.17367729 0.17367729 0.07632271 0.07632271
 0.17367729 0.17367729]
ob2: 
[0.07632271 0.17367729 0.07632271 0.17367729 0.07632271 0.17367729
 0.07632271 0.17367729]

System information

Name: PennyLane
Version: 0.40.0
Summary: 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.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /usr/local/lib/python3.11/dist-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing-extensions
Required-by: PennyLane_Lightning

Platform info:           Linux-6.1.85+-x86_64-with-glibc2.35
Python version:          3.11.11
Numpy version:           1.26.4
Scipy version:           1.13.1
Installed devices:
- default.clifford (PennyLane-0.40.0)
- default.gaussian (PennyLane-0.40.0)
- default.mixed (PennyLane-0.40.0)
- default.qubit (PennyLane-0.40.0)
- default.qutrit (PennyLane-0.40.0)
- default.qutrit.mixed (PennyLane-0.40.0)
- default.tensor (PennyLane-0.40.0)
- null.qubit (PennyLane-0.40.0)
- reference.qubit (PennyLane-0.40.0)
- lightning.qubit (PennyLane_Lightning-0.40.0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant