Skip to content

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

@CatalinaAlbornoz

Description

@CatalinaAlbornoz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions