Skip to content

Fidelity calculation for density matrices improvement #4819

Open
@alvinquantum

Description

@alvinquantum

state1_sqrt = _sqrt_positive_semidefinite_matrix(state1)
eigs = scipy.linalg.eigvalsh(state1_sqrt @ state2 @ state1_sqrt)
trace = np.sum(np.sqrt(np.abs(eigs)))
return trace ** 2

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

Metadata

Metadata

Assignees

Labels

area/accuracyarea/qiskind/bug-reportSomething doesn't seem to work.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions