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] qml.expval returns unexpected values #6017

Open
1 task done
yokkon opened this issue Jul 21, 2024 · 3 comments
Open
1 task done

[BUG] qml.expval returns unexpected values #6017

yokkon opened this issue Jul 21, 2024 · 3 comments
Labels
bug 🐛 Something isn't working

Comments

@yokkon
Copy link

yokkon commented Jul 21, 2024

Expected behavior

qml.expval(cost_h).process_counts({'000000':1}, wire_order=dev_shots_100.wires)

returns the largest eigenvalue of the cost_h Hamiltonian. probably because it sorts the eigenvalues and then it doesn't sort the counts / samples

Actual behavior

The provided code should return the eigenvalue corresponding to the eigenstate provided.

Additional information

No response

Source code

No response

Tracebacks

No response

System information

Python version:          3.9.12
Numpy version:           1.23.0
Scipy version:           1.8.0
Installed devices:
- default.clifford (PennyLane-0.37.0)
- default.gaussian (PennyLane-0.37.0)
- default.mixed (PennyLane-0.37.0)
- default.qubit (PennyLane-0.37.0)
- default.qubit.autograd (PennyLane-0.37.0)
- default.qubit.jax (PennyLane-0.37.0)
- default.qubit.legacy (PennyLane-0.37.0)
- default.qubit.tf (PennyLane-0.37.0)
- default.qubit.torch (PennyLane-0.37.0)
- default.qutrit (PennyLane-0.37.0)
- default.qutrit.mixed (PennyLane-0.37.0)
- default.tensor (PennyLane-0.37.0)
- null.qubit (PennyLane-0.37.0)
- lightning.qubit (PennyLane-Lightning-0.37.0)
- braket.aws.qubit (amazon-braket-pennylane-plugin-1.13.1)
- braket.local.qubit (amazon-braket-pennylane-plugin-1.13.1)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@yokkon yokkon added the bug 🐛 Something isn't working label Jul 21, 2024
@trbromley
Copy link
Contributor

Thanks for posting this but report @yokkon! We'll take a look and get back to you soon.

@albi3ro
Copy link
Contributor

albi3ro commented Jul 22, 2024

Both process_counts and process_samples assume that the diagonalizing gates have already been applied before the sampling was performed.

All we need is consistency between the eigenstates created by the diagonalizing gates and the eigenvalues returned by Operator.eigvals(). So the diagonalizing gates of cost_h should map the eigenstate with the largest eigenvalue to 000000. This can be double-checked with qml.ops.functions.assert_valid(cost_h).

If the eigenvalues and diagonalizing gates are indeed inconsistent, we'd be happy to look into fixing that.

@DSGuala
Copy link
Contributor

DSGuala commented Sep 6, 2024

Hi @yokkon, have you been able to test @albi3ro 's suggestion? Let us know if you're still having issues with this.

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

4 participants