# density_matrix_infidelity

Graph.density_matrix_infidelity(x, y, *, name=None)

Calculate the infidelity between two states represented by density matrices.

Parameters:
• x (np.ndarray or Tensor) – The density matrix $$x$$ with shape (..., D, D). The last two dimensions must have the same size for both matrices, and its batch dimensions must be broadcastable.

• y (np.ndarray or Tensor) – The density matrix $$y$$ with shape (..., D, D). The last two dimensions must have the same size for both matrices, and its batch dimensions must be broadcastable.

• name (str or None, optional) – The name of the node.

Returns:

The state infidelity of the density matrices with respect to each other. Its shape is the broadcasted value of the batch shapes of the two input parameters.

Return type:

Tensor

Warning

This function assumes that the parameters are density matrices and therefore are positive definite. Passing matrices that have negative or complex eigenvalues will result in wrong values for the infidelity.

infidelity_pwc

Total infidelity of a system with a piecewise-constant Hamiltonian.

infidelity_stf

Total infidelity of a system with a sampleable Hamiltonian.

state_infidelity

Infidelity between two quantum states.

unitary_infidelity

Infidelity between a unitary and target operators.

Notes

The general formula for the infidelity of two density matrices is

$I = 1 - \left[ \mathrm{Tr}\left( \sqrt{\sqrt{x} y \sqrt{x}} \right) \right]^2$

Examples

>>> infidelity = graph.density_matrix_infidelity(
...     np.array([[0.5, 0], [0, 0.5]]),
...     np.array([[1, 0], [0, 0]]),
...     name="infidelity",
... )
>>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["infidelity"])
>>> result.output["infidelity"]["value"]
0.5