# ms_infidelity

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

and `ms_displacements`

to calculate the infidelity tensor.

### Parameters

**phases**(*np.ndarray**(**real**) or**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**(**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(real)

### SEE ALSO

`Graph.ions.ms_dephasing_robust_cost`

: Cost for robust optimization of a Mølmer–Sørensen gate.

`Graph.ions.ms_displacements`

: Displacements for each mode/ion combination.

`Graph.ions.ms_phases`

: Relative phases for all pairs of ions.

## Notes

The infidelity is calculated according to ^{1}

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`

or
`Graph.ions.ms_phases_multitone`

for the
relevant definitions.

## References

## Examples

Refer to the How to optimize error-robust Mølmer–Sørensen gates for trapped ions user guide to find how to use this and related nodes.