View source on GitHub |
Fidelity of two quantum states.
cirq.fidelity(
state1: 'cirq.QUANTUM_STATE_LIKE',
state2: 'cirq.QUANTUM_STATE_LIKE',
qid_shape: Optional[Tuple[int, ...]] = None,
validate: bool = True,
atol: float = 1e-07
) -> float
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.
Returns | |
---|---|
The value of the fidelity, as a float. |
Raises | |
---|---|
ValueError
|
The qid shape of the given states was not specified and could not be inferred. |
ValueError
|
Invalid quantum state. |