Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions examples/creating-a-driven-control.ipynb

Large diffs are not rendered by default.

32 changes: 7 additions & 25 deletions examples/creating-a-dynamical-decoupling-sequence.ipynb

Large diffs are not rendered by default.

43 changes: 21 additions & 22 deletions qctrlopencontrols/driven_controls/driven_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def export(
self, coordinates=Coordinate.CYLINDRICAL.value, dimensionless_rabi_rate=True
) -> dict[str, Any]:
"""
Returns a dictionary formatted for plotting using the ``qctrl-visualizer`` package.
Returns a dictionary formatted for plotting using the Q-CTRL Visualizer package.

Parameters
----------
Expand All @@ -569,7 +569,7 @@ def export(
-------
dict
Dictionary with plot data that can be used by the `plot_controls`
method of the ``qctrl-visualizer`` package. It has keywords 'Rabi rate'
method of the Q-CTRL Visualizer package. It has keywords 'Rabi rate'
and 'Detuning' for 'cylindrical' coordinates and 'X amplitude', 'Y amplitude',
and 'Detuning' for 'cartesian' coordinates.
"""
Expand All @@ -587,30 +587,29 @@ def export(

plot_dictionary = {}

plot_x = self.amplitude_x / normalizer
plot_y = self.amplitude_y / normalizer
plot_r = self.rabi_rates / normalizer
plot_theta = self.azimuthal_angles
plot_durations = self.durations
plot_detunings = self.detunings

if coordinates == Coordinate.CARTESIAN.value:
plot_dictionary["X amplitude"] = [
{"value": v, "duration": t} for v, t in zip(plot_x, plot_durations)
]
plot_dictionary["Y amplitude"] = [
{"value": v, "duration": t} for v, t in zip(plot_y, plot_durations)
]
plot_dictionary["X amplitude"] = {
"values": self.amplitude_x / normalizer,
"durations": self.durations,
}
plot_dictionary["Y amplitude"] = {
"values": self.amplitude_y / normalizer,
"durations": self.durations,
}

if coordinates == Coordinate.CYLINDRICAL.value:
plot_dictionary["Rabi rate"] = [
{"value": r * np.exp(1.0j * theta), "duration": t}
for r, theta, t in zip(plot_r, plot_theta, plot_durations)
]
values = (self.rabi_rates / normalizer) * np.exp(
1.0j * self.azimuthal_angles
)
plot_dictionary["Rabi rate"] = {
"values": values,
"durations": self.durations,
}

plot_dictionary["Detuning"] = [
{"value": v, "duration": t} for v, t in zip(plot_detunings, plot_durations)
]
plot_dictionary["Detuning"] = {
"values": self.detunings,
"durations": self.durations,
}

return plot_dictionary

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,22 @@ def __init__(

def export(self) -> dict[str, Any]:
"""
Returns a dictionary for plotting using the qctrl-visualizer package.
Returns a dictionary for plotting using the Q-CTRL Visualizer package.

Returns
-------
dict
Dictionary with plot data that can be used by the plot_sequences
method of the qctrl-visualizer package. It has keywords 'Rabi'
Dictionary with plot data that can be used by the `plot_sequences`
method of the Q-CTRL Visualizer package. It has keywords 'Rabi'
and 'Detuning'.
"""

return {
"Rabi": [
{"rotation": rabi * np.exp(1.0j * theta), "offset": offset}
for rabi, theta, offset in zip(
self.rabi_rotations, self.azimuthal_angles, self.offsets
)
],
"Detuning": [
{"rotation": rotation, "offset": offset}
for rotation, offset in zip(self.detuning_rotations, self.offsets)
],
"Rabi": {
"rotations": self.rabi_rotations * np.exp(1.0j * self.azimuthal_angles),
"offsets": self.offsets,
},
"Detuning": {"rotations": self.detuning_rotations, "offsets": self.offsets},
}

def __repr__(self):
Expand Down
22 changes: 6 additions & 16 deletions tests/test_driven_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,13 @@ def test_plot_data():
dimensionless_rabi_rate=False, coordinates="cartesian"
)

assert np.allclose(
[point["duration"] for point in plot_data["X amplitude"]], _durations
)
assert np.allclose(
[point["duration"] for point in plot_data["Y amplitude"]], _durations
)
assert np.allclose(
[point["duration"] for point in plot_data["Detuning"]], _durations
)
assert np.allclose(plot_data["X amplitude"]["durations"], _durations)
assert np.allclose(plot_data["Y amplitude"]["durations"], _durations)
assert np.allclose(plot_data["Detuning"]["durations"], _durations)

assert np.allclose(
[point["value"] for point in plot_data["X amplitude"]], x_amplitude
)
assert np.allclose(
[point["value"] for point in plot_data["Y amplitude"]], y_amplitude
)
assert np.allclose([point["value"] for point in plot_data["Detuning"]], _detunings)
assert np.allclose(plot_data["X amplitude"]["values"], x_amplitude)
assert np.allclose(plot_data["Y amplitude"]["values"], y_amplitude)
assert np.allclose(plot_data["Detuning"]["values"], _detunings)


def test_pretty_print():
Expand Down
30 changes: 10 additions & 20 deletions tests/test_dynamical_decoupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,13 @@ def test_sequence_plot():

plot_data = seq.export()

_plot_rabi_offsets = [pulse["offset"] for pulse in plot_data["Rabi"]]
_plot_detuning_offsets = [pulse["offset"] for pulse in plot_data["Detuning"]]
_plot_rabi_rotations = [pulse["rotation"] for pulse in plot_data["Rabi"]]
_plot_detuning_rotations = [pulse["rotation"] for pulse in plot_data["Detuning"]]
assert np.allclose(plot_data["Rabi"]["offsets"], _offsets)
assert np.allclose(plot_data["Detuning"]["offsets"], _offsets)

assert np.allclose(_plot_rabi_offsets, _offsets)
assert np.allclose(_plot_detuning_offsets, _offsets)
assert np.allclose(np.abs(plot_data["Rabi"]["rotations"]), _rabi_rotations)
assert np.allclose(np.angle(plot_data["Rabi"]["rotations"]), _azimuthal_angle)

assert np.allclose(np.abs(_plot_rabi_rotations), _rabi_rotations)
assert np.allclose(np.angle(_plot_rabi_rotations), _azimuthal_angle)

assert np.allclose(_plot_detuning_rotations, _detuning_rotations)
assert np.allclose(plot_data["Detuning"]["rotations"], _detuning_rotations)

# with both X and Y pi
_offsets = np.array([0, 0.25, 0.5, 0.75, 1.00])
Expand All @@ -185,18 +180,13 @@ def test_sequence_plot():

plot_data = seq.export()

_plot_rabi_offsets = [pulse["offset"] for pulse in plot_data["Rabi"]]
_plot_detuning_offsets = [pulse["offset"] for pulse in plot_data["Detuning"]]
_plot_rabi_rotations = [pulse["rotation"] for pulse in plot_data["Rabi"]]
_plot_detuning_rotations = [pulse["rotation"] for pulse in plot_data["Detuning"]]

assert np.allclose(_plot_rabi_offsets, _offsets)
assert np.allclose(_plot_detuning_offsets, _offsets)
assert np.allclose(plot_data["Rabi"]["offsets"], _offsets)
assert np.allclose(plot_data["Detuning"]["offsets"], _offsets)

assert np.allclose(np.abs(_plot_rabi_rotations), _rabi_rotations)
assert np.allclose(np.angle(_plot_rabi_rotations), _azimuthal_angle)
assert np.allclose(np.abs(plot_data["Rabi"]["rotations"]), _rabi_rotations)
assert np.allclose(np.angle(plot_data["Rabi"]["rotations"]), _azimuthal_angle)

assert np.allclose(_plot_detuning_rotations, _detuning_rotations)
assert np.allclose(plot_data["Detuning"]["rotations"], _detuning_rotations)


def test_pretty_string_format():
Expand Down