Skip to content

Unnecessary warning of non-trace-1 argument to psd_square_root in fidelity function #581

@rileyjmurray

Description

@rileyjmurray

The fidelity function contains a helper function called psd_square_root, which currently raises a warning if the input argument isn't trace-1:

def psd_square_root(mat):
evals, U = _np.linalg.eigh(mat)
if _np.min(evals) < -__SCALAR_TOL__:
message = f"""
Input matrix is not PSD up to tolerance {__SCALAR_TOL__}.
We'll project out the bad eigenspaces to only work with the PSD part.
"""
_warnings.warn(message)
evals[evals < 0] = 0.0
tr = _np.sum(evals)
if abs(tr - 1) > __VECTOR_TOL__:
message = f"""
The PSD part of the input matrix is not trace-1 up to tolerance {__VECTOR_TOL__}.
Beware result!
"""
_warnings.warn(message)
sqrt_mat = U @ (_np.sqrt(evals).reshape((-1, 1)) * U.T.conj())
return sqrt_mat
sqrt_a = psd_square_root(a)
tr_arg = psd_square_root(sqrt_a @ b @ sqrt_a)
f = _np.trace(tr_arg).real ** 2 # Tr( sqrt{ sqrt(a) * b * sqrt(a) } )^2

This function is called twice, immediately after its definition. But the trace check should only really be applied the first time that psd_square_root is called. Warnings raised in the second call are entirely unnecessary.

An obvious fix is to remove this check from psd_square_root and just check if the first input argument is trace-1 before calling psd_square_root. The reason for including the trace check inside psd_square_root was because we compute the trace after projecting out negative eigenspaces.

This is an easy fix for me but I'm in the middle of other work so I'm leaving a note to fix later.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions