Skip to content

Commit 7a6db59

Browse files
committed
reshap to use different vars
1 parent bf87eb4 commit 7a6db59

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

qctrlopencontrols/dynamic_decoupling_sequences/predefined.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def new_ramsey_sequence(
181181
offsets = duration * np.array([0.0, 1.0])
182182
rabi_rotations = np.array([np.pi / 2, np.pi / 2])
183183
azimuthal_angles = np.array([0.0, np.pi])
184-
detuning_rotations = np.zeros((2,))
184+
detuning_rotations = np.array([0, 0])
185185
else:
186186
offsets = np.array([])
187187
rabi_rotations = np.array([])
@@ -812,27 +812,27 @@ def new_quadratic_sequence(
812812

813813
# remove the last entry corresponding to the duration
814814
offsets = offsets[:-1]
815-
rabi_rotations = rabi_rotations[:-1]
816-
detuning_rotations = detuning_rotations[:-1]
815+
_rabi_rotations = rabi_rotations[:-1]
816+
_detuning_rotations = detuning_rotations[:-1]
817817

818818
azimuthal_angles = np.zeros(offsets.shape)
819819

820820
if pre_post_rotation:
821821
(
822822
offsets,
823-
rabi_rotations,
823+
_rabi_rotations,
824824
azimuthal_angles,
825-
detuning_rotations,
825+
_detuning_rotations,
826826
) = _add_pre_post_rotations(
827-
duration, offsets, rabi_rotations, azimuthal_angles, detuning_rotations
827+
duration, offsets, _rabi_rotations, azimuthal_angles, _detuning_rotations
828828
)
829829

830830
return DynamicDecouplingSequence(
831831
duration=duration,
832832
offsets=offsets,
833-
rabi_rotations=rabi_rotations,
833+
rabi_rotations=_rabi_rotations,
834834
azimuthal_angles=azimuthal_angles,
835-
detuning_rotations=detuning_rotations,
835+
detuning_rotations=_detuning_rotations,
836836
name=name,
837837
)
838838

tests/test_predefined_dynamical_decoupling.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -393,20 +393,15 @@ def test_quadratic_sequence():
393393
_rabi_rotations[0:outer_offset_count, -1] = np.pi
394394
_detuning_rotations[0 : (outer_offset_count + 1), 0:inner_offset_count] = np.pi
395395

396-
_offsets = np.reshape(_offsets, (-1,))
397-
_rabi_rotations = np.reshape(_rabi_rotations, (-1,))
398-
_detuning_rotations = np.reshape(_detuning_rotations, (-1,))
396+
_reshaped_offsets = np.reshape(_offsets, (-1,))[0:-1]
397+
_reshaped_rabi_rotations = np.reshape(_rabi_rotations, (-1,))[0:-1]
398+
_reshaped_detuning_rotations = np.reshape(_detuning_rotations, (-1,))[0:-1]
399+
_azimuthal_angles = np.zeros(_reshaped_offsets.shape)
399400

400-
_offsets = _offsets[0:-1]
401-
_rabi_rotations = _rabi_rotations[0:-1]
402-
_detuning_rotations = _detuning_rotations[0:-1]
403-
404-
_azimuthal_angles = np.zeros(_offsets.shape)
405-
406-
assert np.allclose(_offsets, sequence.offsets)
407-
assert np.allclose(_rabi_rotations, sequence.rabi_rotations)
401+
assert np.allclose(_reshaped_offsets, sequence.offsets)
402+
assert np.allclose(_reshaped_rabi_rotations, sequence.rabi_rotations)
408403
assert np.allclose(_azimuthal_angles, sequence.azimuthal_angles)
409-
assert np.allclose(_detuning_rotations, sequence.detuning_rotations)
404+
assert np.allclose(_reshaped_detuning_rotations, sequence.detuning_rotations)
410405

411406
sequence = new_quadratic_sequence(
412407
duration=duration,
@@ -415,21 +410,25 @@ def test_quadratic_sequence():
415410
pre_post_rotation=True,
416411
)
417412

418-
_offsets = np.insert(_offsets, [0, _offsets.shape[0]], [0, duration])
419-
_rabi_rotations = np.insert(
420-
_rabi_rotations, [0, _rabi_rotations.shape[0]], [np.pi / 2, np.pi / 2]
413+
_reshaped_offsets = np.insert(
414+
_reshaped_offsets, [0, _reshaped_offsets.shape[0]], [0, duration]
421415
)
422-
_detuning_rotations = np.insert(
423-
_detuning_rotations, [0, _detuning_rotations.shape[0]], [0, 0]
416+
_reshaped_rabi_rotations = np.insert(
417+
_reshaped_rabi_rotations,
418+
[0, _reshaped_rabi_rotations.shape[0]],
419+
[np.pi / 2, np.pi / 2],
420+
)
421+
_reshaped_detuning_rotations = np.insert(
422+
_reshaped_detuning_rotations, [0, _reshaped_detuning_rotations.shape[0]], [0, 0]
424423
)
425424

426-
_azimuthal_angles = np.zeros(_offsets.shape)
425+
_azimuthal_angles = np.zeros(_reshaped_offsets.shape)
427426
_azimuthal_angles[-1] = np.pi
428427

429-
assert np.allclose(_offsets, sequence.offsets)
430-
assert np.allclose(_rabi_rotations, sequence.rabi_rotations)
428+
assert np.allclose(_reshaped_offsets, sequence.offsets)
429+
assert np.allclose(_reshaped_rabi_rotations, sequence.rabi_rotations)
431430
assert np.allclose(_azimuthal_angles, sequence.azimuthal_angles)
432-
assert np.allclose(_detuning_rotations, sequence.detuning_rotations)
431+
assert np.allclose(_reshaped_detuning_rotations, sequence.detuning_rotations)
433432

434433

435434
def test_x_concatenated_sequence():

0 commit comments

Comments
 (0)