mindquantum.simulator.fidelity
- mindquantum.simulator.fidelity(rho: np.ndarray, sigma: np.ndarray)[source]
Calculate the fidelity of two quantum states.
Definition of quantum state fidelity shown as below.
where
and are density matrices.If both
and are pure, and , thenBesides, mixing state vector with density matrix as input is also supported.
- Parameters
rho (np.ndarray) – One of the quantum state. Support both state vector and density matrix.
sigma (np.ndarray) – Another quantum state. Support both state vector and density matrix.
- Returns
numbers.Number, the fidelity of two quantum states.
Examples
>>> from mindquantum.core.circuit import Circuit >>> from mindquantum.simulator import Simulator, fidelity >>> circ = Circuit().h(0).x(1, 0) >>> sim = Simulator('mqmatrix', 2) >>> sim.apply_circuit(circ) >>> rho = sim.get_qs() >>> sim.reset() >>> sigma = sim.get_qs() >>> fidelity(rho, sigma) 0.5000000000000001