PennyLaneAI / pennylane

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.
https://pennylane.ai
Apache License 2.0
2.35k stars 603 forks source link

[BUG] `Adjoint.eigvals` does not return the correct value #3696

Closed AlbertMitjans closed 1 year ago

AlbertMitjans commented 1 year ago

Expected behavior

Both lines should return the same values:

>>> qml.adjoint(qml.RX(1, 0)).eigvals()
array([0.87758256+0.47942554j, 0.87758256-0.47942554j])
>>> qml.RX(1, 0).adjoint().eigvals()
array([0.87758256+0.47942554j, 0.87758256-0.47942554j])

Actual behavior

Both lines return different values:

>>> qml.adjoint(qml.RX(1, 0)).eigvals()
array([0.87758256+0.47942554j, 0.87758256-0.47942554j])
>>> qml.RX(1, 0).adjoint().eigvals()
array([0.87758256-0.47942554j, 0.87758256+0.47942554j])

Additional information

No response

Source code

No response

Tracebacks

No response

System information

Name: PennyLane
Version: 0.29.0.dev0
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: /Users/albertmitjans/Developer/pennylane/.venv/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, retworkx, scipy, semantic-version, toml
Required-by: PennyLane-Lightning

Platform info:           macOS-13.0.1-arm64-arm-64bit
Python version:          3.10.8
Numpy version:           1.23.5
Scipy version:           1.10.0
Installed devices:
- default.gaussian (PennyLane-0.29.0.dev0)
- default.mixed (PennyLane-0.29.0.dev0)
- default.qubit (PennyLane-0.29.0.dev0)
- default.qubit.autograd (PennyLane-0.29.0.dev0)
- default.qubit.jax (PennyLane-0.29.0.dev0)
- default.qubit.tf (PennyLane-0.29.0.dev0)
- default.qubit.torch (PennyLane-0.29.0.dev0)
- default.qutrit (PennyLane-0.29.0.dev0)
- null.qubit (PennyLane-0.29.0.dev0)
- lightning.qubit (PennyLane-Lightning-0.28.0)

Existing GitHub issues

albi3ro commented 1 year ago

Eigenvalues are unsorted. All that matters is that they have the same order as the diagonalizing gates.

In this case, the eigenvalues are even of the same magnitude, just phase differences. So we can't really establish a canonical "order" to them.

AlbertMitjans commented 1 year ago

Thanks! Closing issue.