question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fidelity calculation for density matrices improvement

See original GitHub issue

https://github.com/quantumlib/Cirq/blob/782c14e0cc821794d21e82f30df8e6998f4b9992/cirq-core/cirq/qis/measures.py#L239-L242

The current implementation uses the direct definition of fidelity, which works well for small dimensions. From my experience, I was getting values significantly greater than 1. For the fidelity between rho1 and rho2, I found that squaring the sum of the singular values of the product of square_root(rho1) and square_root(rho2) gives a more accurate calculation. This equation is equal to fidelity. The idea is not mine and came from qutip.

This is my version of the implementation that I use.

import scipy
def get_fidelity(rho1, rho2):
    rho1_sqrt=scipy.linalg.sqrtm(rho1)
    rho2_sqrt=scipy.linalg.sqrtm(rho2)
    return scipy.linalg.svdvals(rho1_sqrt @ rho2_sqrt).sum()**2

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tanujkhattarcommented, Mar 14, 2022

@anonymousr007 Yes, the issue is still open.

The goal is to replace the current implementation of calculating fidelity of two density matrices with the improved implementation that has lower numerical error.

Current implementation: https://github.com/quantumlib/Cirq/blob/782c14e0cc821794d21e82f30df8e6998f4b9992/cirq-core/cirq/qis/measures.py#L239-L242

New implementation:

def get_fidelity(rho1, rho2):
    rho1_sqrt=scipy.linalg.sqrtm(rho1)
    rho2_sqrt=scipy.linalg.sqrtm(rho2)
    return scipy.linalg.svdvals(rho1_sqrt @ rho2_sqrt).sum()**2

The PR implementing the change should also add a unit test demonstrating improved numerical stability of the new implementation, s.t. the current implementation fails but the new one passes.

0reactions
daxfohlcommented, Apr 20, 2022

Nice, I noticed pretty bad rounding errors when testing https://github.com/quantumlib/Cirq/pull/5265 and wasn’t sure what to make of it. (I had to reduce the atol in my tests to just 1e-2)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quantum fidelity simplified formula while both of the density ...
I'm wondering how to prove this formula and is it always safe to use it while one of the density matrices is in...
Read more >
Improved Quantum Algorithms for Fidelity Estimation - arXiv
Our algorithms use advanced quantum linear algebra techniques, such as the quantum singular value transformation, as well as density matrix ...
Read more >
(a) Average fidelity of the reconstructed density matrices (DM ...
Specifically, the average fidelity improves from 0.751 to 0.982 with a standard deviation of 1.04 × 10 −3 , and 0.88 to 0.996...
Read more >
On the learnability of quantum state fidelity
The correlation factor substantially improved to 0.82 and 0.74 for the ... They then use convex optimization to estimate the density matrix.
Read more >
`qutip.metrics.fidelity` needs fix for pure states represented by ...
I found an instance where putting two kets in fidelity function gives nonphysical result while inputting corresponding density matrices ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found