# ms_dephasing_robust_cost

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

```python
ions.ms_dephasing_robust_cost(drives, lamb_dicke_parameters, relative_detunings, *, name=None)
```

Calculate the cost for robust optimization of a Mølmer–Sørensen gate.

Add the tensor that this function returns to the infidelity of your
target operation to obtain a cost that you can use to create a
Mølmer–Sørensen gate that is robust against dephasing noise. You can
further multiply the robust cost by a scaling factor to weigh how much
importance you give to the robustness compared to the original cost.

### Parameters
* **drives** (*list* *[*[*Pwc*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc) *or* *None* *]*) – The piecewise-constant drives, $\{\gamma_j\}$, one for each of the $N$ ions.
  Drive values must be in rad/s and durations must be in seconds.
  All drives must have the same total duration, but can have different segmentations.
  If an ion is not addressed, you can pass None for its drive (this leads to a
  more efficient calculation than passing a zero drive).
* **lamb_dicke_parameters** (*np.ndarray*) – The laser-ion coupling strength, $\{\eta_{jkl}\}$.
  Its shape must be `(3, N, N)`, where the dimensions indicate,
  respectively, axis, collective mode, and ion.
* **relative_detunings** (*np.ndarray*) – The difference $\{\delta_{jk} = \nu_{jk} - \delta\}$ (in Hz) between each motional
  mode frequency and the laser detuning from the qubit transition frequency
  $\omega_0$. Its shape must be `(3, N)`, where the dimensions indicate,
  respectively, axis and collective mode.
* **name** (*str* *or* *None* *,* *optional*) – The name of the node.
### Returns
The cost term that you can use to optimize a Mølmer–Sørensen gate
that is robust against dephasing noise. The cost is the sum of the
square moduli of the time-averaged positions of the phase-space
trajectories, weighted by the corresponding Lamb–Dicke parameters.
### Return type
[Tensor](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)(scalar, real)

### SEE ALSO
[`Graph.ions.ms_infidelity`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/ions/ms_infidelity.md#boulderopal.graph.ions.ms_infidelity)
: Final operational infidelity of a Mølmer–Sørensen gate.

[`boulderopal.ions.obtain_ion_chain_properties`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/ions/obtain_ion_chain_properties.md#boulderopal.ions.obtain_ion_chain_properties)
: Function to calculate the properties of an ion chain.

## Notes

You can construct a Mølmer–Sørensen gate that is robust against
dephasing noise by a combination of minimizing the time-averaged
positions of the phase-space trajectories and imposing a symmetry in
each ion’s drive <sup>[1](#id3)</sup>.

The displacement of the $l$-th ion in the $k$-th mode of
oscillation in dimension $j$ is <sup>[2](#id4)</sup>

$$
\alpha_{jkl}(t) = \int_0^t d\tau \frac{\gamma_l(\tau)}{2}
        \exp(i 2 \pi \delta_{jk} \tau) .
$$

For a gate of duration $t_\text{gate}$, the time-averaged displacement is

$$
\langle \alpha_{jkl} \rangle = \frac{1}{t_\text{gate}}
        \int_0^{t_\text{gate}} \alpha_{jkl}(t) \mathrm{d} t .
$$

This function returns the sum of the square moduli of the time-averaged
positions multiplied by the corresponding Lamb–Dicke parameters. These
parameters weight the time-averaged positions in the same way that the
$\alpha_{jkl}(t)$ are weighted in the formula for the infidelity
of a Mølmer–Sørensen gate (see [`Graph.ions.ms_infidelity`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/ions/ms_infidelity.md#boulderopal.graph.ions.ms_infidelity)).

In other words, the robust cost that this function returns is

$$
C_\text{robust} = \sum_{j=1}^{3} \sum_{k=1}^{N} \sum_{l=1}^{N}
    \left| \eta_{jkl} \langle \alpha_{jkl} \rangle \right|^2 .
$$

You can add this to the infidelity with the respect to the target gate
to create the cost function that optimizes a gate that is also robust
against dephasing. You can further multiply $C_\text{robust}$ by
a scaling factor to weigh how much importance you give to robustness.

## References

* <a id='id3'>**[1]**</a> [A. R. Milne, C. L. Edmunds, C. Hempel, F. Roy, S. Mavadia, and M. J. Biercuk, Phys. Rev. Appl. 13, 024022 (2020).](https://doi.org/10.1103/PhysRevApplied.13.024022)
* <a id='id4'>**[2]**</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.
