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
10 changes: 5 additions & 5 deletions qctrlopencontrols/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import numpy as np

SIGMA_X = np.array([[0.0, 1.0], [1.0, 0.0]], dtype=np.complex)
SIGMA_Y = np.array([[0.0, -1.0j], [1.0j, 0.0]], dtype=np.complex)
SIGMA_Z = np.array([[1.0, 0.0], [0.0, -1.0]], dtype=np.complex)
SIGMA_M = np.array([[0.0, 1.0], [0.0, 0.0]], dtype=np.complex)
SIGMA_P = np.array([[0.0, 0.0], [1.0, 0.0]], dtype=np.complex)
SIGMA_X = np.array([[0.0, 1.0], [1.0, 0.0]], dtype=complex)
SIGMA_Y = np.array([[0.0, -1.0j], [1.0j, 0.0]], dtype=complex)
SIGMA_Z = np.array([[1.0, 0.0], [0.0, -1.0]], dtype=complex)
SIGMA_M = np.array([[0.0, 1.0], [0.0, 0.0]], dtype=complex)
SIGMA_P = np.array([[0.0, 0.0], [1.0, 0.0]], dtype=complex)

# Matplotlib format of data for plotting
MATPLOTLIB = "matplotlib"
11 changes: 6 additions & 5 deletions qctrlopencontrols/driven_controls/driven_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(

self.name = name

durations = np.asarray(durations, dtype=np.float)
durations = np.asarray(durations, dtype=float)

# check if all the durations are greater than zero
check_arguments(
Expand Down Expand Up @@ -139,9 +139,10 @@ def __init__(
if detunings is None:
detunings = np.zeros(duration_count)

rabi_rates = np.asarray(rabi_rates, dtype=np.float64)
azimuthal_angles = np.asarray(azimuthal_angles, dtype=np.float64)
detunings = np.asarray(detunings, dtype=np.float64)
# for backward compatibility as these variable could be list
rabi_rates = np.asarray(rabi_rates, dtype=float)
azimuthal_angles = np.asarray(azimuthal_angles, dtype=float)
detunings = np.asarray(detunings, dtype=float)

# check if all the rabi_rates are greater than zero
check_arguments(
Expand Down Expand Up @@ -362,7 +363,7 @@ def resample(self, time_step: float, name: Optional[str] = None) -> "DrivenContr
)

count = int(np.ceil(self.duration / time_step))
durations = [time_step] * count
durations = np.repeat(time_step, count)
times = np.arange(count) * time_step

indices = np.digitize(times, bins=np.cumsum(self.durations))
Expand Down
164 changes: 92 additions & 72 deletions qctrlopencontrols/driven_controls/predefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def new_primitive_control(
)

return DrivenControl(
rabi_rates=[maximum_rabi_rate],
azimuthal_angles=[azimuthal_angle],
detunings=[0],
durations=[rabi_rotation / maximum_rabi_rate],
rabi_rates=np.array([maximum_rabi_rate]),
azimuthal_angles=np.array([azimuthal_angle]),
detunings=np.array([0]),
durations=np.array([rabi_rotation / maximum_rabi_rate]),
name=name,
)

Expand Down Expand Up @@ -216,15 +216,19 @@ def new_bb1_control(
phi_p = _get_transformed_rabi_rotation_wimperis(rabi_rotation)
rabi_rotations = [rabi_rotation, np.pi, 2 * np.pi, np.pi]

rabi_rates = [maximum_rabi_rate] * 4
azimuthal_angles = [
azimuthal_angle,
azimuthal_angle + phi_p,
azimuthal_angle + 3 * phi_p,
azimuthal_angle + phi_p,
]
detunings = [0] * 4
durations = [rabi_rotation / maximum_rabi_rate for rabi_rotation in rabi_rotations]
rabi_rates = np.repeat(maximum_rabi_rate, 4)
azimuthal_angles = np.asarray(
[
azimuthal_angle,
azimuthal_angle + phi_p,
azimuthal_angle + 3 * phi_p,
azimuthal_angle + phi_p,
]
)
detunings = np.repeat(0, 4)
durations = np.asarray(
[rabi_rotation / maximum_rabi_rate for rabi_rotation in rabi_rotations]
)

return DrivenControl(
rabi_rates=rabi_rates,
Expand Down Expand Up @@ -294,16 +298,18 @@ def new_sk1_control(
phi_p = _get_transformed_rabi_rotation_wimperis(rabi_rotation)
rabi_rotations = [rabi_rotation, 2 * np.pi, 2 * np.pi]

rabi_rates = [maximum_rabi_rate] * 3
azimuthal_angles = [
azimuthal_angle,
azimuthal_angle - phi_p,
azimuthal_angle + phi_p,
]
detunings = [0] * 3
durations = [
rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations
]
rabi_rates = np.repeat(maximum_rabi_rate, 3)
azimuthal_angles = np.asarray(
[
azimuthal_angle,
azimuthal_angle - phi_p,
azimuthal_angle + phi_p,
]
)
detunings = np.repeat(0, 3)
durations = np.asarray(
[rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations]
)

return DrivenControl(
rabi_rates=rabi_rates,
Expand Down Expand Up @@ -414,16 +420,18 @@ def degrees_to_radians(angle_in_degrees):

rabi_rotations = [theta_1, theta_2, theta_3]

rabi_rates = [maximum_rabi_rate] * 3
azimuthal_angles = [
azimuthal_angle + phi_1,
azimuthal_angle + phi_2,
azimuthal_angle + phi_3,
]
detunings = [0] * 3
durations = [
rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations
]
rabi_rates = np.repeat(maximum_rabi_rate, 3)
azimuthal_angles = np.asarray(
[
azimuthal_angle + phi_1,
azimuthal_angle + phi_2,
azimuthal_angle + phi_3,
]
)
detunings = np.repeat(0, 3)
durations = np.asarray(
[rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations]
)

return DrivenControl(
rabi_rates=rabi_rates,
Expand Down Expand Up @@ -500,12 +508,14 @@ def new_corpse_control(
rabi_rotation / 2.0 - k,
]

rabi_rates = [maximum_rabi_rate] * 3
azimuthal_angles = [azimuthal_angle, azimuthal_angle + np.pi, azimuthal_angle]
detunings = [0] * 3
durations = [
rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations
]
rabi_rates = np.repeat(maximum_rabi_rate, 3)
azimuthal_angles = np.asarray(
[azimuthal_angle, azimuthal_angle + np.pi, azimuthal_angle]
)
detunings = np.repeat(0, 3)
durations = np.asarray(
[rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations]
)

return DrivenControl(
rabi_rates=rabi_rates,
Expand Down Expand Up @@ -598,19 +608,21 @@ def new_corpse_in_bb1_control(
np.pi,
]

rabi_rates = [maximum_rabi_rate] * 6
azimuthal_angles = [
azimuthal_angle,
azimuthal_angle + np.pi,
azimuthal_angle,
azimuthal_angle + phi_p,
azimuthal_angle + 3 * phi_p,
azimuthal_angle + phi_p,
]
detunings = [0] * 6
durations = [
rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations
]
rabi_rates = np.repeat(maximum_rabi_rate, 6)
azimuthal_angles = np.asarray(
[
azimuthal_angle,
azimuthal_angle + np.pi,
azimuthal_angle,
azimuthal_angle + phi_p,
azimuthal_angle + 3 * phi_p,
azimuthal_angle + phi_p,
]
)
detunings = np.repeat(0, 6)
durations = np.asarray(
[rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations]
)

return DrivenControl(
rabi_rates=rabi_rates,
Expand Down Expand Up @@ -701,18 +713,20 @@ def new_corpse_in_sk1_control(
2 * np.pi,
]

rabi_rates = [maximum_rabi_rate] * 5
azimuthal_angles = [
azimuthal_angle,
azimuthal_angle + np.pi,
azimuthal_angle,
azimuthal_angle - phi_p,
azimuthal_angle + phi_p,
]
detunings = [0] * 5
durations = [
rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations
]
rabi_rates = np.repeat(maximum_rabi_rate, 5)
azimuthal_angles = np.asarray(
[
azimuthal_angle,
azimuthal_angle + np.pi,
azimuthal_angle,
azimuthal_angle - phi_p,
azimuthal_angle + phi_p,
]
)
detunings = np.repeat(0, 5)
durations = np.asarray(
[rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations]
)

return DrivenControl(
rabi_rates=rabi_rates,
Expand Down Expand Up @@ -867,10 +881,12 @@ def degrees_to_radians(angle_in_degrees):
total_angles = np.vstack(_total_angles)
rabi_rotations = total_angles[:, 0]

rabi_rates = [maximum_rabi_rate] * 9
rabi_rates = np.repeat(maximum_rabi_rate, 9)
azimuthal_angles = total_angles[:, 1]
detunings = [0] * 9
durations = [rabi_rotation / maximum_rabi_rate for rabi_rotation in rabi_rotations]
detunings = np.repeat(0, 9)
durations = np.asarray(
[rabi_rotation / maximum_rabi_rate for rabi_rotation in rabi_rotations]
)

return DrivenControl(
rabi_rates=rabi_rates,
Expand Down Expand Up @@ -959,10 +975,12 @@ def new_wamf1_control(
rabi_rotations = [theta_plus, theta_minus, theta_minus, theta_plus]
segment_duration = theta_plus / maximum_rabi_rate

rabi_rates = [rabi_rotation / segment_duration for rabi_rotation in rabi_rotations]
azimuthal_angles = [azimuthal_angle] * 4
detunings = [0] * 4
durations = [segment_duration] * 4
rabi_rates = np.asarray(
[rabi_rotation / segment_duration for rabi_rotation in rabi_rotations]
)
azimuthal_angles = np.repeat(azimuthal_angle, 4)
detunings = np.repeat(0, 4)
durations = np.repeat(segment_duration, 4)

return DrivenControl(
rabi_rates=rabi_rates,
Expand Down Expand Up @@ -1199,7 +1217,9 @@ def new_modulated_gaussian_control(
* (maximum_full_rotation_angle / maximum_rotation_angle)
)

azimuthal_angles = [0 if v >= 0 else np.pi for v in modulated_gaussian_segments]
azimuthal_angles = np.asarray(
[0 if v >= 0 else np.pi for v in modulated_gaussian_segments]
)

return DrivenControl(
rabi_rates=np.abs(modulated_gaussian_segments),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(
{"offsets": offsets, "duration": duration},
)

rabi_rotations = np.asarray(rabi_rotations, dtype=np.float)
rabi_rotations = np.asarray(rabi_rotations, dtype=float)
check_arguments(
np.all(rabi_rotations >= 0),
"Rabi rotations must be non-negative.",
Expand Down Expand Up @@ -125,8 +125,8 @@ def __init__(
self.duration = duration
self.offsets = offsets
self.rabi_rotations = rabi_rotations
self.azimuthal_angles = np.asarray(azimuthal_angles, dtype=np.float)
self.detuning_rotations = np.asarray(detuning_rotations, dtype=np.float)
self.azimuthal_angles = np.asarray(azimuthal_angles, dtype=float)
self.detuning_rotations = np.asarray(detuning_rotations, dtype=float)
self.name = name

def export(self) -> Dict:
Expand Down Expand Up @@ -474,10 +474,10 @@ def convert_dds_to_driven_control(
if np.allclose(pulse_start_ends, 0.0):
# the original sequence should be a free evolution
return DrivenControl(
rabi_rates=[0.0],
azimuthal_angles=[0.0],
detunings=[0.0],
durations=[sequence_duration],
rabi_rates=np.array([0.0]),
azimuthal_angles=np.array([0.0]),
detunings=np.array([0.0]),
durations=np.array([sequence_duration]),
name=name,
)

Expand Down
22 changes: 11 additions & 11 deletions qctrlopencontrols/dynamic_decoupling_sequences/predefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def _add_pre_post_rotations(

# parameters for pre-post pulses
rabi_value = np.pi / 2
detuning_value = 0
initial_azimuthal = 0 # for pre-pulse
final_azimuthal = 0 # for post-pulse
detuning_value = 0.0
initial_azimuthal = 0.0 # for pre-pulse
final_azimuthal = 0.0 # for post-pulse

# The sequence will preserve the state |0> is it has an even number
# of X and Y pi-pulses
Expand Down Expand Up @@ -183,16 +183,16 @@ def new_ramsey_sequence(duration, pre_post_rotation=False, name=None):
{"duration": duration},
)

offsets = []
rabi_rotations = []
azimuthal_angles = []
detuning_rotations = []

if pre_post_rotation:
offsets = duration * np.array([0.0, 1.0])
rabi_rotations = np.array([np.pi / 2, np.pi / 2])
azimuthal_angles = np.array([0.0, np.pi])
detuning_rotations = np.zeros((2,))
else:
offsets = np.array([])
rabi_rotations = np.array([])
azimuthal_angles = np.array([])
detuning_rotations = np.array([])

return DynamicDecouplingSequence(
duration=duration,
Expand Down Expand Up @@ -682,11 +682,11 @@ def new_walsh_sequence(duration, paley_order, pre_post_rotation=False, name=None
** binary_order[hamming_weight - 1 - i]
)

walsh_relative_offsets = []
_walsh_relative_offsets = []
for i in range(samples - 1):
if walsh_array[i] != walsh_array[i + 1]:
walsh_relative_offsets.append((i + 1) * (1.0 / samples))
walsh_relative_offsets = np.array(walsh_relative_offsets, dtype=np.float)
_walsh_relative_offsets.append((i + 1) * (1.0 / samples))
walsh_relative_offsets = np.array(_walsh_relative_offsets, dtype=float)

offsets = duration * walsh_relative_offsets
rabi_rotations = np.full(offsets.shape, np.pi)
Expand Down
Loading