# ms_simulate

Source: https://docs.q-ctrl.com/references/boulder-opal/boulderopal/ions/ms_simulate

```python
boulderopal.ions.ms_simulate(drives, duration, lamb_dicke_parameters, relative_detunings, target_phases=None, sample_count=128)
```

Simulate a Mølmer–Sørensen-type operation on a system composed of ions.

This function builds a graph describing the Mølmer–Sørensen operation
and calls boulderopal.execute_graph to simulate the ion dynamics.

### Parameters
* **drives** (*list* *[*[*Drive*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/ions/Drive.md#boulderopal.ions.Drive) *]*) – A list of drives addressing the ions.
  Each ion can only be addressed by a single drive,
  but there may be ions not addressed by any drive.
* **duration** (*float*) – The duration, in seconds, of the dynamics to be simulated, $T$.
  It must be greater than zero.
* **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.
* **target_phases** (*np.ndarray* *or* *None* *,* *optional*) – The target total relative phases between ion pairs, $\{\Psi_{ln}\}$,
  as a strictly lower triangular matrix of shape `(N, N)`.
  $\Psi_{ln}$ with $l > n$ indicates the relative phase between ions
  $l$ and $n$, while $\Psi_{ln} = 0$ for $l \leq n$.
  If not provided, the function does not return the operational infidelities.
* **sample_count** (*int* *,* *optional*) – The number of times $T$ between 0 and duration (included)
  at which the evolution is sampled.
  Defaults to 128.
### Returns
The result of the execute_graph call.
Its `output` item is a dictionary containing information about
the evolution of the system, with the following keys:
> `sample_times`
> : The times at which the evolution is sampled, as an array of shape `(T,)`.

  > `phases`
  > : Acquired phases $\{\Phi_{ln}(t_i) = \phi_{ln}(t_i) + \phi_{nl}(t_i)\}$
  >   for each sample time and for all ion pairs, as a strictly lower triangular
  >   matrix of shape `(T, N, N)`.
  >   $\Phi_{ln}(t_i)$ with $l > n$ indicates the relative phase between ions
  >   $l$ and $n$, while $\Phi_{ln}(t_i) = 0$ for $l \leq n$.

  > `displacements`
  > : Displacements $\{\eta_{jkl}\alpha_{jkl}(t_i)\}$ for all mode-ion combinations,
  >   as an array of shape `(T, 3, N, N)`, where the dimensions indicate, respectively,
  >   time, axis, collective mode, and ion.

  > `infidelities`
  > : A 1D array of length `T` with the operational infidelities of
  >   the Mølmer–Sørensen gate at each sample time, $\mathcal{I}(t_i)$.
  >   Only returned if target relative phases are provided.
### Return type
dict

### SEE ALSO
[`boulderopal.ions.Drive`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/ions/Drive.md#boulderopal.ions.Drive)
: Class describing non-optimizable drives.

[`boulderopal.ions.ms_optimize`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/ions/ms_optimize.md#boulderopal.ions.ms_optimize)
: Find optimal pulses to perform Mølmer–Sørensen-type operations on trapped ions systems.

[`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)
: Calculate the properties of an ion chain.

## Notes

The internal and motional Hamiltonian of $N$ ions is

$$
H_0 = \sum_{j=1}^{3} \sum_{k=1}^{N} \hbar\nu_{jk} \left(a_{jk}^\dagger a_{jk}
    + \frac{1}{2}\right) + \sum_{l=1}^N \frac{\hbar \omega_0}{2} \sigma_{z,l} ,
$$

where $j$ indicates axis dimension ($x$, $y$, or $z$),
$k$ indicates collective mode, $a_{jk}$ is the annihilation operator,
and $\sigma_{z,l}$ is the Pauli $Z$ operator for ion $l$.

The interaction Hamiltonian for Mølmer–Sørensen-type
operations in the rotating frame with respect to $H_0$ is

$$
H_I(t) = i\hbar \sum_{j=1}^{3} \sum_{k=1}^{N} \sum_{l=1}^N
    \sigma_{x,l} \left(-\beta_{jkl}^*(t)a_{jk} + \beta_{jkl}(t) a_{jk}^\dagger\right) ,
$$

where $\sigma_{x,l}$ is the Pauli $X$ operator for ion $l$ and

$$
\beta_{jkl}(t) = \eta_{jkl} \frac{\gamma_l(t)}{2} \exp(i 2 \pi \delta_{jk} t)
$$

indicates the coupling between ion $l$ and motional mode $(j,k)$.

The corresponding unitary operation is given by <sup>[1](#id3)</sup>

$$
U(t) = \exp\left[ \sum_{l=1}^N \sigma_{x,l} B_l(t)
    + i\sum_{l=1}^N\sum_{n=1}^{l-1} (\phi_{ln}(t) + \phi_{nl}(t))
    \sigma_{x,l} \sigma_{x,n} \right] ,
$$

where

$$
B_l(t) \equiv \sum_{j=1}^{3} \sum_{k=1}^{N}
    \left(\eta_{jkl}\alpha_{jkl}(t)a_{jk}^\dagger
    - \eta_{jkl}^{\ast}\alpha_{jkl}^\ast(t)a_{jk} \right) ,
$$
\phi_{ln}(t) \equiv \mathrm{Im} \left[ \sum_{j=1}^{3} \sum_{k=1}^{N}
    \int_{0}^{t} d \tau_1 \int_{0}^{\tau_1} d \tau_2
    \beta_{jkl}(\tau_1)\beta_{jkn}^{\ast}(\tau_2) \right] ,
$$
\alpha_{jkl}(t) \equiv \int_0^t d\tau \frac{\gamma_l(\tau)}{2}
    \exp(i 2 \pi \delta_{jk} \tau) .
$$

The operational infidelity of the Mølmer–Sørensen gate is defined as <sup>[1](#id3)</sup>:

$$
\mathcal{I} = 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 ,
$$

## References

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