# ms_infidelity

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

```python
ions.ms_infidelity(phases, displacements, target_phases, mean_phonon_numbers=None, *, name=None)
```

Calculate the final operational infidelity of the Mølmer–Sørensen gate.

This function calculates the operational infidelity with respect to the target phases
that you specify in the target_phases array. It can use the tensors returned from
[`ms_phases`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/ions/ms_phases.md#boulderopal.graph.ions.ms_phases) and [`ms_displacements`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/ions/ms_displacements.md#boulderopal.graph.ions.ms_displacements) to calculate the infidelity tensor.

### Parameters
* **phases** (*np.ndarray* *(* *real* *) or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor) *(* *real* *)*) – The acquired phases between ion pairs, $\{\Phi_{ln}\}$.
  Its shape must be `(N, N)` without time samples or `(T, N, N)` with them,
  where `T` is the number of samples and `N` is the number of ions.
  For each sample, the phases array must be a strictly lower triangular matrix.
* **displacements** (*np.ndarray* *(* *complex* *) or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor) *(* *complex* *)*) – The motional displacements in phase-space, $\{\eta_{jkl} \alpha_{jkl}\}$.
  Its shape must be `(3, N, N_d)` without time samples or `(T, 3, N, N_d)` with them,
  where the dimensions indicate, respectively, (time,) axis, collective mode, and ion.
  Here, `N_d` is the number of addressed ions.
* **target_phases** (*np.ndarray* *(* *real* *)*) – The target total relative phases between ion pairs, $\{\Psi_{ln}\}$,
  as a strictly lower triangular matrix of shape `(N, N)`.
* **mean_phonon_numbers** (*np.ndarray* *or* *None* *,* *optional*) – The mean phonon occupation of motional modes, $\{\bar{n}_{jk}\}$.
  Its shape must be `(3, N)`, where the dimensions indicate, respectively,
  axis and collective mode.
  If provided, must contain positive real numbers.
  If not provided, $\bar{n}_{jk} = 0$, meaning no occupation of each mode.
* **name** (*str* *or* *None* *,* *optional*) – The name of the node.
### Returns
A scalar or 1D tensor of infidelities with shape `(T,)`.
### Return type
[Tensor](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)(real)

### SEE ALSO
[`Graph.ions.ms_dephasing_robust_cost`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/ions/ms_dephasing_robust_cost.md#boulderopal.graph.ions.ms_dephasing_robust_cost)
: Cost for robust optimization of a Mølmer–Sørensen gate.

[`Graph.ions.ms_displacements`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/ions/ms_displacements.md#boulderopal.graph.ions.ms_displacements)
: Displacements for each mode/ion combination.

[`Graph.ions.ms_phases`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/ions/ms_phases.md#boulderopal.graph.ions.ms_phases)
: Relative phases for all pairs of ions.

## Notes

The infidelity is calculated according to <sup>[1](#id2)</sup>

$$
1 - \mathcal{F}_\mathrm{av} = 1 - \left| \left( \prod_{n=1}^N \prod_{l=n+1}^N
    \cos ( \Phi_{ln} - \Psi_{ln}) \right)
    \left( 1 - \sum_{j=1}^3 \sum_{k=1}^N \sum_{l=1}^N \left[ |\eta_{jkl} \alpha_{jkl}|^2
    \left(\bar{n}_{jk}+\frac{1}{2} \right) \right] \right) \right|^2 ,
$$

which assumes that the displacements $\alpha_{jkl}$ are
small and eliminates terms of the fourth or higher order in them.

See the notes of [`Graph.ions.ms_phases`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/ions/ms_phases.md#boulderopal.graph.ions.ms_phases) or
[`Graph.ions.ms_phases_multitone`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/ions/ms_phases_multitone.md#boulderopal.graph.ions.ms_phases_multitone) for the
relevant definitions.

## References

* <a id='id2'>**[1]**</a> [C. D. B. Bentley, H. Ball, M. J. Biercuk, A. R. R. Carvalho, M. R. Hush, and H. J. Slatyer, Adv. Quantum Technol. 3, 2000044 (2020).](https://doi.org/10.1002/qute.202000044)

## Examples

Refer to the [How to optimize error-robust Mølmer–Sørensen gates for trapped ions](https://docs.q-ctrl.com/boulder-opal/user-guides/how-to-optimize-error-robust-molmer-sorensen-gates-for-trapped-ions) user guide to find how to use this and related nodes.
