Skip to content

Commit

Permalink
misc: Fix code format (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
tachikoma-li authored Jan 14, 2022
1 parent fd8b154 commit b8079e0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 175 deletions.
4 changes: 1 addition & 3 deletions qctrlopencontrols/driven_controls/driven_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ def resample(self, time_step: float, name: Optional[str] = None) -> "DrivenContr
original duration.
"""
check_arguments(
time_step > 0,
"Time step must be positive.",
{"time_step": time_step},
time_step > 0, "Time step must be positive.", {"time_step": time_step}
)
check_arguments(
time_step <= self.duration,
Expand Down
17 changes: 3 additions & 14 deletions qctrlopencontrols/driven_controls/predefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,7 @@ def new_sk1_control(

rabi_rates = np.repeat(maximum_rabi_rate, 3)
azimuthal_angles = np.asarray(
[
azimuthal_angle,
azimuthal_angle - phi_p,
azimuthal_angle + phi_p,
]
[azimuthal_angle, azimuthal_angle - phi_p, azimuthal_angle + phi_p]
)
detunings = np.repeat(0, 3)
durations = np.asarray(
Expand Down Expand Up @@ -422,11 +418,7 @@ def degrees_to_radians(angle_in_degrees):

rabi_rates = np.repeat(maximum_rabi_rate, 3)
azimuthal_angles = np.asarray(
[
azimuthal_angle + phi_1,
azimuthal_angle + phi_2,
azimuthal_angle + phi_3,
]
[azimuthal_angle + phi_1, azimuthal_angle + phi_2, azimuthal_angle + phi_3]
)
detunings = np.repeat(0, 3)
durations = np.asarray(
Expand Down Expand Up @@ -1145,10 +1137,7 @@ def new_modulated_gaussian_control(
check_arguments(
duration > minimum_segment_duration,
"Total duration must be greater than minimum segment duration.",
{
"duration": duration,
"minimum_segment_duration": minimum_segment_duration,
},
{"duration": duration, "minimum_segment_duration": minimum_segment_duration},
)

# default spread of the gaussian shaped pulse as a fraction of its duration
Expand Down
16 changes: 3 additions & 13 deletions qctrlopencontrols/dynamic_decoupling_sequences/predefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,9 @@ def _add_pre_post_rotations(
if (preserves_10 and preserves_11) or (not preserves_10 and not preserves_11):
final_azimuthal = np.pi

offsets = np.insert(
offsets,
[0, offsets.shape[0]],
[0, duration],
)
offsets = np.insert(offsets, [0, offsets.shape[0]], [0, duration])
rabi_rotations = np.insert(
rabi_rotations,
[0, rabi_rotations.shape[0]],
[rabi_value, rabi_value],
rabi_rotations, [0, rabi_rotations.shape[0]], [rabi_value, rabi_value]
)
azimuthal_angles = np.insert(
azimuthal_angles,
Expand Down Expand Up @@ -714,11 +708,7 @@ def new_walsh_sequence(duration, paley_order, pre_post_rotation=False, name=None


def new_quadratic_sequence(
duration,
inner_offset_count,
outer_offset_count,
pre_post_rotation=False,
name=None,
duration, inner_offset_count, outer_offset_count, pre_post_rotation=False, name=None
):
r"""
Creates the quadratic sequence.
Expand Down
51 changes: 13 additions & 38 deletions tests/test_predefined_driven_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def test_scofulous_control():

# Construct SCROFULOUS controls for target rotations pi/4, pi/2 and pi
scrofulous_pi = new_scrofulous_control(
rabi_rotation=np.pi,
azimuthal_angle=0.5,
maximum_rabi_rate=2 * np.pi,
rabi_rotation=np.pi, azimuthal_angle=0.5, maximum_rabi_rate=2 * np.pi
)

pi_segments = np.vstack(
Expand All @@ -192,9 +190,7 @@ def test_scofulous_control():
assert np.allclose(pi_segments, _pi_segments)

scrofulous_pi2 = new_scrofulous_control(
rabi_rotation=np.pi / 2,
azimuthal_angle=-0.5,
maximum_rabi_rate=2 * np.pi,
rabi_rotation=np.pi / 2, azimuthal_angle=-0.5, maximum_rabi_rate=2 * np.pi
)

pi_on_2_segments = np.vstack(
Expand All @@ -217,9 +213,7 @@ def test_scofulous_control():
assert np.allclose(pi_on_2_segments, _pi_on_2_segments)

scrofulous_pi4 = new_scrofulous_control(
rabi_rotation=np.pi / 4,
azimuthal_angle=0,
maximum_rabi_rate=2 * np.pi,
rabi_rotation=np.pi / 4, azimuthal_angle=0, maximum_rabi_rate=2 * np.pi
)

pi_on_4_segments = np.vstack(
Expand Down Expand Up @@ -251,9 +245,7 @@ def test_corpse_in_scrofulous_control():
"""
# Test pi and pi/2 rotations
cs_pi = new_corpse_in_scrofulous_control(
rabi_rotation=np.pi,
azimuthal_angle=0.5,
maximum_rabi_rate=2 * np.pi,
rabi_rotation=np.pi, azimuthal_angle=0.5, maximum_rabi_rate=2 * np.pi
)

pi_segments = np.vstack(
Expand All @@ -277,9 +269,7 @@ def test_corpse_in_scrofulous_control():
assert np.allclose(pi_segments, _pi_segments)

cs_pi_on_2 = new_corpse_in_scrofulous_control(
rabi_rotation=np.pi / 2,
azimuthal_angle=0.25,
maximum_rabi_rate=np.pi,
rabi_rotation=np.pi / 2, azimuthal_angle=0.25, maximum_rabi_rate=np.pi
)

pi_on_2_segments = np.vstack(
Expand Down Expand Up @@ -367,9 +357,7 @@ def test_cinbb_control():
Tests the segments of the CinBB (BB1 made up of CORPSEs) driven control.
"""
cinbb = new_corpse_in_bb1_control(
rabi_rotation=np.pi / 3,
azimuthal_angle=0.25,
maximum_rabi_rate=np.pi,
rabi_rotation=np.pi / 3, azimuthal_angle=0.25, maximum_rabi_rate=np.pi
)

segments = np.vstack(
Expand All @@ -390,9 +378,7 @@ def test_cinbb_control():
assert np.allclose(segments, _segments)

cinbb = new_corpse_in_bb1_control(
rabi_rotation=np.pi / 5,
azimuthal_angle=-0.25,
maximum_rabi_rate=np.pi,
rabi_rotation=np.pi / 5, azimuthal_angle=-0.25, maximum_rabi_rate=np.pi
)

segments = np.vstack(
Expand All @@ -418,9 +404,7 @@ def test_cinsk1_control():
Tests the segments of the CinSK1 (SK1 made up of CORPSEs) driven control.
"""
cinsk = new_corpse_in_sk1_control(
rabi_rotation=np.pi / 2,
azimuthal_angle=0.5,
maximum_rabi_rate=2 * np.pi,
rabi_rotation=np.pi / 2, azimuthal_angle=0.5, maximum_rabi_rate=2 * np.pi
)

segments = np.vstack(
Expand All @@ -440,9 +424,7 @@ def test_cinsk1_control():
assert np.allclose(segments, _segments)

cinsk = new_corpse_in_sk1_control(
rabi_rotation=2 * np.pi,
azimuthal_angle=-0.5,
maximum_rabi_rate=2 * np.pi,
rabi_rotation=2 * np.pi, azimuthal_angle=-0.5, maximum_rabi_rate=2 * np.pi
)

segments = np.vstack(
Expand Down Expand Up @@ -473,9 +455,7 @@ def test_walsh_control():

# test pi rotation
walsh_pi = new_wamf1_control(
rabi_rotation=np.pi,
azimuthal_angle=-0.35,
maximum_rabi_rate=2 * np.pi,
rabi_rotation=np.pi, azimuthal_angle=-0.35, maximum_rabi_rate=2 * np.pi
)

pi_segments = np.vstack(
Expand All @@ -500,9 +480,7 @@ def test_walsh_control():

# test pi/2 rotation
walsh_pi_on_2 = new_wamf1_control(
rabi_rotation=np.pi / 2.0,
azimuthal_angle=0.57,
maximum_rabi_rate=2 * np.pi,
rabi_rotation=np.pi / 2.0, azimuthal_angle=0.57, maximum_rabi_rate=2 * np.pi
)

pi_on_2_segments = np.vstack(
Expand All @@ -527,9 +505,7 @@ def test_walsh_control():

# test pi/4 rotation
walsh_pi_on_4 = new_wamf1_control(
rabi_rotation=np.pi / 4.0,
azimuthal_angle=-0.273,
maximum_rabi_rate=2 * np.pi,
rabi_rotation=np.pi / 4.0, azimuthal_angle=-0.273, maximum_rabi_rate=2 * np.pi
)
pi_on_4_segments = np.vstack(
(
Expand Down Expand Up @@ -698,8 +674,7 @@ def test_modulated_gaussian_control_give_identity_gate():
[
np.cos(d * v) * np.eye(2) + 1j * np.sin(d * v) * SIGMA_X
for d, v in zip(
p.durations,
p.rabi_rates * np.exp(1j * p.azimuthal_angles),
p.durations, p.rabi_rates * np.exp(1j * p.azimuthal_angles)
)
]
)
Expand Down
Loading

0 comments on commit b8079e0

Please sign in to comment.