cirq.fidelity

Fidelity of two quantum states.

The fidelity of two density matrices ρ and σ is defined as:

\[ trace(\sqrt{\sqrt{\rho} \hspace{0.5em} \sigma \sqrt{\rho} })^2 \]

The given states can be state vectors or density matrices.

state1 The first state.
state2 The second state.
qid_shape The qid shape of the given states.
validate Whether to check if the given states are valid quantum states.
atol Absolute numerical tolerance to use for validation.

The value of the fidelity, as a float.

ValueError The qid shape of the given states was not specified and could not be inferred.
ValueError Invalid quantum state.