• Boulder Opal
• User guides
• Calculate system dynamics for arbitrary Mølmer–Sørensen gates

# How to calculate system dynamics for arbitrary Mølmer–Sørensen gates

Calculate the Mølmer–Sørensen gate evolution characteristics for trapped ions

Boulder Opal enables you to optimize, explore and validate the dynamics induced by Mølmer–Sørensen-type operations. In this notebook, we begin with an optimized control and show how to obtain the evolution dynamics of the entangling phase and the motional trajectories in phase space, using convenience functions designed for trapped-ion experiments.

You can learn how to optimize error-robust Mølmer–Sørensen gates for trapped ions in our user guide, or perform complex operations by designing robust, configurable, parallel gates for large trapped-ion arrays using our application note.

## Summary workflow

### 1. Define and calculate ion properties

To find optimized drives, you first need to know the physical properties of the ions, namely the Lamb–Dicke parameters and mode frequencies. You can calculate these values using the function qctrl.ions.obtain_ion_chain_properties by providing basic parameters of your ion trap, specifically the mass of the ions, center of mass frequencies, and laser wave numbers along different axes. The function returns the Lamb–Dicke parameters and relative detunings as 3D and 2D arrays, respectively, which will be used in the phase and displacement calculations.

### 2. Calculate motional displacement trajectories and phase dynamics

Given the controls, you can obtain the gate dynamics. In particular, you can visualize the trajectory of the center of a coherent state in (rotating) optical phase space for each mode. The closure of these trajectories is a necessary condition for an effective operation. You can also obtain the phase accumulation during the gate operation for each pair of ions, and the target phases should be achieved at the end of a successful operation.

You can utilize our flexible qctrl.functions.calculate_graph function to track how displacements and phases change during the gate operational time. Within a graph, you can include the graph.ms_phases and graph.ms_displacements operations that take the control drives and ion properties as inputs. You can simply provide the sample_times parameter with your desired time sampling for the evolution, and use qctrl.functions.calculate_graph to return the dynamics.

Note that the results of the graph.ms_displacements function describe contributions to each mode from each ion. To get the overall displacement for each mode, you need to sum over the ion dimension (see the notes of graph.ms_displacements for details).

## Example: GHZ state on a chain of three ions

In this example we consider a chain of three ions (${}^{171}{\rm Yb}^{+}$), and the goal is to examine the dynamics induced by drives that have been optimized to generate a relative phase of $\pi/4$ between each ion pair. Note that you can perform $X_{\pi/2}$ rotations for all ions after applying the optimal drives to create the GHZ state, as shown in Kim et al. (2009).

### Define and calculate ion properties

We begin by calculating ion properties based on inputs relevant to the system under examination.

import jsonpickle
import matplotlib.pyplot as plt
import numpy as np
from qctrlvisualizer import get_qctrl_style, plot_controls

plt.style.use(get_qctrl_style())

from qctrl import Qctrl

# Start a Boulder Opal session.
qctrl = Qctrl()

"""
Load a variable from a file encoded with jsonpickle.
"""
with open(file_name, "r+") as file:

data_folder = "./resources/"
# Specify ion trap parameters.
ion_count = 3
atomic_mass = 171
center_of_mass_frequencies = [1.6e6, 1.5e6, 0.3e6]

# Define laser characteristics.
wave_numbers = [1.8e7, 1.8e7, 0]
laser_detuning = 1.6047e6
maximum_rabi_rate = 2 * np.pi * 100e3

# Calculate the ion chain properties:
# Lamb–Dicke parameters as an array of shape [<axis>, <collective_mode>, <ion>],
# Relative detunings as an array of shape [<axis>, <collective_mode>].
lamb_dicke_parameters, relative_detunings = qctrl.ions.obtain_ion_chain_properties(
atomic_mass=atomic_mass,
ion_count=ion_count,
center_of_mass_frequencies=center_of_mass_frequencies,
wave_numbers=wave_numbers,
laser_detuning=laser_detuning,
)
Your task calculate_ion_chain_properties (action_id="1599146") has completed.


### Import optimized drives

Next, we import the optimized drive data. The drives have been optimized to generate $\pi/4$ relative phase between each ion pair in a chain of three ions.

drive_data = load_variable(data_folder + "optimized_drives")
plot_controls(drive_data) The drives are displayed above, where an individual drive, drive_j, is applied to each ion j with optimized modulation in the modulus and phase (or angle).

### Calculate relative phase and motional displacement dynamics

Here we apply our qctrl.functions.calculate_graph function to obtain the motional displacement trajectories and the relative phases for the duration of the given drives, with specified sample_times.

drive_names = list(drive_data.keys())
duration = np.sum([seg["duration"] for seg in drive_data[drive_names]])
sample_times = np.linspace(0, duration, 100)

graph = qctrl.create_graph()

# Collect optimized drives.
drives = [
graph.pwc(*qctrl.utils.pwc_pairs_to_arrays(drive_data[name]))
for name in drive_names
]

# Calculate phases and displacements.
ms_phases = graph.ms_phases(
drives=drives,
lamb_dicke_parameters=lamb_dicke_parameters,
relative_detunings=relative_detunings,
sample_times=sample_times,
name="phases",
)
ms_displacements = graph.ms_displacements(
drives=drives,
lamb_dicke_parameters=lamb_dicke_parameters,
relative_detunings=relative_detunings,
sample_times=sample_times,
name="displacements",
)

# Execute the graph.
result = qctrl.functions.calculate_graph(
graph=graph, output_node_names=["phases", "displacements"]
)
Your task calculate_graph (action_id="1599149") has completed.


Now we can calculate the contribution of each ion to the mode displacements, and plot the mode displacement trajectories.

trajectories = np.sum(result.output["displacements"]["value"], axis=3)
plot_range = 1.05 * np.max(np.abs(trajectories))

fig, axs = plt.subplots(1, 2, figsize=(10, 5))
fig.suptitle("Phase space trajectories", y=1.1)

for k in range(2):
for mode in range(ion_count):
axs[k].plot(
np.real(trajectories[:, k, mode]),
np.imag(trajectories[:, k, mode]),
label=f"mode {mode % 3}",
)
axs[k].plot(
np.real(trajectories[-1, k, mode]),
np.imag(trajectories[-1, k, mode]),
"kx",
markersize=15,
)

axs[k].set_xlim(-plot_range, plot_range)
axs[k].set_ylim(-plot_range, plot_range)
axs[k].set_aspect("equal")
axs[k].set_xlabel("q")

axs.set_title("$x$-axis")
axs.set_ylabel("p")
axs.set_title("$y$-axis")
axs.yaxis.set_ticklabels([])

hs, ls = axs.get_legend_handles_labels()
fig.legend(handles=hs, labels=ls, loc="center", bbox_to_anchor=(0.5, 1), ncol=ion_count)

plt.tight_layout()
plt.show() Here, $q \equiv q_m = (a_m^\dagger + a_m)/\sqrt{2}$ and $p \equiv p_m = i (a_m^\dagger - a_m)/\sqrt{2}$ are the dimensionless quadratures for each mode $m$ and its corresponding annihilation operator $a_m$. The black cross marks the final displacement for each mode. These are overlapping at zero, indicating no residual state-motional entanglement and no motional heating caused by the operations. The z-axis modes are not addressed, and thus have no excursions in phase space.

Next we obtain and visualize the relative phase dynamics for each pair of ions.

# Recall that the phases are stored as a strictly lower triangular matrix.
# See the notes of the ms_phases graph operation.
phases = result.output["phases"]["value"]

# Plot phase dynamics.
plt.plot([0, sample_times[-1] * 1e3], [np.pi / 4, np.pi / 4], "k--")
for ion_1 in range(3):
for ion_2 in range(ion_1):
plt.plot(sample_times * 1e3, phases[:, ion_1, ion_2], label=f"{ion_2, ion_1}")

plt.legend(title="Ion pair")
plt.xlabel("Time (ms)")
plt.ylabel("Relative phase")
plt.show() The figure shows the dynamics of the relative phase between the three pairs of ions, over the duration of the gate. Under the optimized controls, the relative phases evolve from 0 to the target phase of $\pi/4$ at the end of the operation (marked by the horizontal dashed line). This indicates a successful operation.

This notebook was run using the following package versions. It should also be compatible with newer versions of the Q-CTRL Python package.

PackageVersion
Python3.10.8
jsonpickle3.0.1
matplotlib3.6.3
numpy1.24.1
scipy1.10.0
qctrl20.1.1
qctrl-commons17.7.0
boulder-opal-toolkits2.0.0-beta.3
qctrl-visualizer4.4.0