# 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$(..., 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$(..., 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.

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.

Graph.infidelity_pwc : Total infidelity of a system with a piecewise-constant Hamiltonian.

Graph.infidelity_stf : Total infidelity of a system with a sampleable Hamiltonian.

Graph.state_infidelity : Infidelity between two quantum states.

Graph.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 = bo.execute_graph(graph=graph, output_node_names="infidelity")
>>> result["output"]["infidelity"]["value"]
0.5