# density_matrix_infidelity

Source: https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/density_matrix_infidelity

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

Calculate the infidelity between two states represented by density matrices.

### Parameters
* **x** (*np.ndarray* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.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*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.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](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.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.

### SEE ALSO
[`Graph.infidelity_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/infidelity_pwc.md#boulderopal.graph.Graph.infidelity_pwc)
: Total infidelity of a system with a piecewise-constant Hamiltonian.

[`Graph.infidelity_stf`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/infidelity_stf.md#boulderopal.graph.Graph.infidelity_stf)
: Total infidelity of a system with a sampleable Hamiltonian.

[`Graph.state_infidelity`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/state_infidelity.md#boulderopal.graph.Graph.state_infidelity)
: Infidelity between two quantum states.

[`Graph.unitary_infidelity`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/unitary_infidelity.md#boulderopal.graph.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

```pycon
>>> 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
```
