pennylane icon indicating copy to clipboard operation
pennylane copied to clipboard

[BUG] `qml.probs` incorrect output order when using custom eigendecomposition

Open antalszava opened this issue 2 years ago • 0 comments

Expected behavior

Providing an observable to qml.probs works all the time, even with observables like qml.Hermitian.

Actual behavior

Using qml.probs(op=qml.Hadamard(0)) we get [0.14644661 0.85355339], whereas with

mx = qml.matrix(qml.Hadamard(0))
had = qml.Hermitian(mx, wires=[0])
qml.probs(op=had)

we get [0.85355339 0.14644661] (probs reversed).

Additional information

qml.Hermitian is an example of an observable that computes its eigendecomposition on the fly to create its diagonalizing gates. However, the order in which the eigenvectors and eigenvalues are computed may not correspond to the order of basis states that we assume in PennyLane.

Source code

dev = qml.device("default.qubit", wires=1)
    
mx = qml.matrix(qml.Hadamard(0))
had = qml.Hermitian(mx, wires=[0])
    
@qml.qnode(dev)
def my_circ(hadamard_direct):
    qml.PauliX(0)
    if hadamard_direct:
        return qml.probs(op=qml.Hadamard(0))

    return qml.probs(op=had)

print(my_circ(True), my_circ(False))

my_circ(False)
print(list(my_circ.qtape))

Tracebacks

No response

System information

Name: PennyLane
Version: 0.24.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /anaconda3/lib/python3.8/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, retworkx, scipy, semantic-version, toml
Required-by: amazon-braket-pennylane-plugin, PennyLane-AQT, PennyLane-Cirq, PennyLane-Forest, PennyLane-Honeywell, PennyLane-IonQ, PennyLane-Lightning, PennyLane-Orquestra, PennyLane-PQ, PennyLane-Qchem, PennyLane-qiskit, PennyLane-qsharp, pennylane-qulacs, PennyLane-SF

Platform info:           Linux-5.13.0-51-generic-x86_64-with-glibc2.10
Python version:          3.8.5
Numpy version:           1.22.4
Scipy version:           1.8.1
Installed devices:
- lightning.qubit (PennyLane-Lightning-0.24.0)
- default.gaussian (PennyLane-0.24.0)
- default.mixed (PennyLane-0.24.0)
- default.qubit (PennyLane-0.24.0)
- default.qubit.autograd (PennyLane-0.24.0)
- default.qubit.jax (PennyLane-0.24.0)
- default.qubit.tf (PennyLane-0.24.0)
- default.qubit.torch (PennyLane-0.24.0)
- orquestra.forest (PennyLane-Orquestra-0.15.0)
- orquestra.ibmq (PennyLane-Orquestra-0.15.0)
- orquestra.qiskit (PennyLane-Orquestra-0.15.0)
- orquestra.qulacs (PennyLane-Orquestra-0.15.0)
- qulacs.simulator (pennylane-qulacs-0.17.0.dev0)
- aqt.noisy_sim (PennyLane-AQT-0.18.0)
- aqt.sim (PennyLane-AQT-0.18.0)
- projectq.classical (PennyLane-PQ-0.18.0.dev0)
- projectq.ibm (PennyLane-PQ-0.18.0.dev0)
- projectq.simulator (PennyLane-PQ-0.18.0.dev0)
- microsoft.QuantumSimulator (PennyLane-qsharp-0.19.0)
- strawberryfields.fock (PennyLane-SF-0.21.0.dev0)
- strawberryfields.gaussian (PennyLane-SF-0.21.0.dev0)
- strawberryfields.gbs (PennyLane-SF-0.21.0.dev0)
- strawberryfields.remote (PennyLane-SF-0.21.0.dev0)
- strawberryfields.tf (PennyLane-SF-0.21.0.dev0)
- ionq.qpu (PennyLane-IonQ-0.21.0.dev0)
- ionq.simulator (PennyLane-IonQ-0.21.0.dev0)
- honeywell.hqs (PennyLane-Honeywell-0.19.0.dev0)
- qiskit.aer (PennyLane-qiskit-0.23.0.dev0)
- qiskit.basicaer (PennyLane-qiskit-0.23.0.dev0)
- qiskit.ibmq (PennyLane-qiskit-0.23.0.dev0)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.23.0.dev0)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.23.0.dev0)
- forest.numpy_wavefunction (PennyLane-Forest-0.21.0.dev0)
- forest.qvm (PennyLane-Forest-0.21.0.dev0)
- forest.wavefunction (PennyLane-Forest-0.21.0.dev0)
- cirq.mixedsimulator (PennyLane-Cirq-0.23.0.dev0)
- cirq.pasqal (PennyLane-Cirq-0.23.0.dev0)
- cirq.qsim (PennyLane-Cirq-0.23.0.dev0)
- cirq.qsimh (PennyLane-Cirq-0.23.0.dev0)
- cirq.simulator (PennyLane-Cirq-0.23.0.dev0)
- braket.aws.qubit (amazon-braket-pennylane-plugin-1.6.8.dev0)
- braket.local.qubit (amazon-braket-pennylane-plugin-1.6.8.dev0)

Existing GitHub issues

  • [X] I have searched existing GitHub issues to make sure the issue does not already exist.

antalszava avatar Jun 21 '22 15:06 antalszava