Skip to content

Commit 787aaab

Browse files
authored
feat: Enforce non-negativity of Rabi rotations (#179)
Changes proposed in this pull request: - Enforce non-negativity of Rabi rotations during creation of a `DynamicDecouplingSequence` object
1 parent 16ab132 commit 787aaab

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ def __init__(
9595
{"offsets": offsets, "duration": duration},
9696
)
9797

98+
rabi_rotations = np.asarray(rabi_rotations, dtype=np.float)
99+
check_arguments(
100+
np.all(rabi_rotations >= 0),
101+
"Rabi rotations must be non-negative.",
102+
{"rabi_rotations": rabi_rotations},
103+
)
104+
98105
_offset_count = len(offsets)
99106

100107
check_arguments(
@@ -117,7 +124,7 @@ def __init__(
117124

118125
self.duration = duration
119126
self.offsets = offsets
120-
self.rabi_rotations = np.asarray(rabi_rotations, dtype=np.float)
127+
self.rabi_rotations = rabi_rotations
121128
self.azimuthal_angles = np.asarray(azimuthal_angles, dtype=np.float)
122129
self.detuning_rotations = np.asarray(detuning_rotations, dtype=np.float)
123130
self.name = name

tests/test_dynamical_decoupling.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ def test_dynamical_decoupling_sequence():
126126
detuning_rotations=np.zeros((2000, 1)),
127127
)
128128

129+
with pytest.raises(ArgumentsValueError):
130+
131+
# rabi rotations cannot be negative
132+
_ = DynamicDecouplingSequence(
133+
duration=2.0,
134+
offsets=np.ones((2, 1)),
135+
rabi_rotations=np.asarray([1, -1]),
136+
azimuthal_angles=np.ones((2, 1)),
137+
detuning_rotations=np.zeros((2, 1)),
138+
)
139+
129140

130141
def test_sequence_plot():
131142
"""

0 commit comments

Comments
 (0)