-
Notifications
You must be signed in to change notification settings - Fork 604
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.math.fidelity
is not differentiable for 2 or more wires
#4373
Comments
One extra thing: unfortunately tests for the gradient of the fidelity between pennylane/tests/qinfo/test_fidelity.py Lines 198 to 200 in 9c19af2
pennylane/tests/qinfo/test_fidelity.py Lines 246 to 248 in 9c19af2
pennylane/tests/qinfo/test_fidelity.py Lines 265 to 266 in 9c19af2
pennylane/tests/qinfo/test_fidelity.py Lines 690 to 692 in 9c19af2
|
Is this issue now closed? |
**Context:** It would be nice to have a function to calculate the expectation values of an operator $A$ given a state vector $\vert\psi\rangle$. This can be also used for computing the fidelity between a mixed and a pure state in simple way, avoiding eigendecomposition problems. **Description of the Change:** Added a overlap calculation between state vectors and density matrices **Benefits:** It is faster then computing $\text{Tr}(A \vert\psi\rangle\langle\psi\vert)$. No need for eigendecomposition, therefore, it is a way to avoid issues regarding differentiation as pointed on issue #4373. **Possible Drawbacks:** It does not work if the user pass as input two state vectors or two matrices. It is tailored to first input as (batched) matrices and the second one as (batched) state vectors. **Related GitHub Issues:** #4373 --------- Co-authored-by: Frederik Wilde <[email protected]> Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Matthew Silverman <[email protected]> Co-authored-by: Romain Moyard <[email protected]> Co-authored-by: Mudit Pandey <[email protected]> Co-authored-by: Olivia Di Matteo <[email protected]> Co-authored-by: Olivia Di Matteo <[email protected]> Co-authored-by: Jay Soni <[email protected]> Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Matthew Silverman <[email protected]> Co-authored-by: David Wierichs <[email protected]> Co-authored-by: Edward Jiang <[email protected]> Co-authored-by: Utkarsh <[email protected]> Co-authored-by: Korbinian Kottmann <[email protected]> Co-authored-by: Thomas R. Bromley <[email protected]> Co-authored-by: Astral Cai <[email protected]> Co-authored-by: Astral Cai <[email protected]>
Expected behavior
The fidelity should be differentiable. For
QNodes
with a single wire, the gradient of fidelity is computed:but returns some warnings, such as:
Actual behavior
For 2 or more wires, the gradient fails and returns
nan
.Additional information
This problem seems to be happening particularly for computing the gradient of fidelity between matrices with low rank, blocked, or sparse somehow. I also tried computing the gradient with
jax
but it didn't work:and the output:
Source code
Tracebacks
System information
Name: PennyLane Version: 0.31.0 Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc. Home-page: https://github.com/PennyLaneAI/pennylane Author: Author-email: License: Apache License 2.0 Location: ~/anaconda3/envs/qml/lib/python3.11/site-packages Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml Required-by: PennyLane-Lightning Platform info: macOS-13.4.1-arm64-arm-64bit Python version: 3.11.3 Numpy version: 1.23.5 Scipy version: 1.10.0 Installed devices: - default.gaussian (PennyLane-0.31.0) - default.mixed (PennyLane-0.31.0) - default.qubit (PennyLane-0.31.0) - default.qubit.autograd (PennyLane-0.31.0) - default.qubit.jax (PennyLane-0.31.0) - default.qubit.tf (PennyLane-0.31.0) - default.qubit.torch (PennyLane-0.31.0) - default.qutrit (PennyLane-0.31.0) - null.qubit (PennyLane-0.31.0) - lightning.qubit (PennyLane-Lightning-0.31.0)
Existing GitHub issues
The text was updated successfully, but these errors were encountered: