From a6e981c08caa4cbe429801d92fc16cae3bb3d974 Mon Sep 17 00:00:00 2001 From: Li Li Date: Fri, 18 Dec 2020 11:15:55 +1100 Subject: [PATCH 1/2] default --- .../driven_controls/predefined.py | 42 +++++++------------ tests/test_predefined_driven_controls.py | 2 +- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/qctrlopencontrols/driven_controls/predefined.py b/qctrlopencontrols/driven_controls/predefined.py index 3ba518df..1156533a 100644 --- a/qctrlopencontrols/driven_controls/predefined.py +++ b/qctrlopencontrols/driven_controls/predefined.py @@ -3,8 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -871,9 +870,7 @@ def degrees_to_radians(angle_in_degrees): rabi_rates = [maximum_rabi_rate] * 9 azimuthal_angles = total_angles[:, 1] detunings = [0] * 9 - durations = [ - rabi_rotation_ / maximum_rabi_rate for rabi_rotation_ in rabi_rotations - ] + durations = [rabi_rotation / maximum_rabi_rate for rabi_rotation in rabi_rotations] return DrivenControl( rabi_rates=rabi_rates, @@ -886,9 +883,9 @@ def degrees_to_radians(angle_in_degrees): def new_wamf1_control( rabi_rotation: float, + maximum_rabi_rate: float, azimuthal_angle: float = 0.0, - maximum_rabi_rate: float = 2.0 * np.pi, - **kwargs + name: Optional[str] = None, ) -> DrivenControl: r""" Creates a first-order Walsh amplitude-modulated filter (WAMF1) driven control. @@ -900,24 +897,18 @@ def new_wamf1_control( rabi_rotation : float The total Rabi rotation :math:`\theta` to be performed by the driven control. Must be either :math:`\pi/4`, :math:`\pi/2`, or :math:`\pi`. - maximum_rabi_rate : float, optional + maximum_rabi_rate : float The maximum Rabi frequency :math:`\Omega_{\rm max}` for the driven control. - Defaults to :math:`2\pi`. azimuthal_angle : float, optional The azimuthal angle :math:`\phi` for the rotation. Defaults to 0. - kwargs : dict - Other keywords required to make a :py:obj:`DrivenControl`. + name : str, optional + An optional string to name the control. Defaults to ``None``. Returns ------- DrivenControl The driven control :math:`\{(\delta t_n, \Omega_n, \phi_n, \Delta_n)\}`. - Raises - ------ - ArgumentsValueError - Raised when an argument is invalid. - Notes ----- A WAMF1 [#]_ driven control consists of four control segments: @@ -949,27 +940,26 @@ def new_wamf1_control( rabi_rotation=rabi_rotation, maximum_rabi_rate=maximum_rabi_rate ) + check_arguments( + np.any(np.isclose(rabi_rotation, [np.pi, np.pi / 2, np.pi / 4])), + "rabi_rotation angle must be either pi, pi/2 or pi/4", + {"rabi_rotation": rabi_rotation}, + ) + if np.isclose(rabi_rotation, np.pi): theta_plus = np.pi theta_minus = np.pi / 2.0 elif np.isclose(rabi_rotation, 0.5 * np.pi): theta_plus = np.pi * (2.5 + 0.65667825) / 4.0 theta_minus = np.pi * (2.5 - 0.65667825) / 4.0 - elif np.isclose(rabi_rotation, 0.25 * np.pi): + else: theta_plus = np.pi * (2.25 + 0.36256159) / 4.0 theta_minus = np.pi * (2.25 - 0.36256159) / 4.0 - else: - raise ArgumentsValueError( - "rabi_rotation angle must be either pi, pi/2 or pi/4", - {"rabi_rotation": rabi_rotation}, - ) 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 - ] + rabi_rates = [rabi_rotation / segment_duration for rabi_rotation in rabi_rotations] azimuthal_angles = [azimuthal_angle] * 4 detunings = [0] * 4 durations = [segment_duration] * 4 @@ -979,7 +969,7 @@ def new_wamf1_control( azimuthal_angles=azimuthal_angles, detunings=detunings, durations=durations, - **kwargs, + name=name, ) diff --git a/tests/test_predefined_driven_controls.py b/tests/test_predefined_driven_controls.py index 5f8f54bb..1353a8c4 100644 --- a/tests/test_predefined_driven_controls.py +++ b/tests/test_predefined_driven_controls.py @@ -449,7 +449,7 @@ def test_walsh_control(): # Test that exceptions are raised upon wrong inputs for rabi_rotation # (WALSH control is only defined for pi/4, pi/2 and pi pulses) with pytest.raises(ArgumentsValueError): - _ = new_wamf1_control(rabi_rotation=0.3) + _ = new_wamf1_control(rabi_rotation=0.3, maximum_rabi_rate=np.pi) # test pi rotation walsh_pi = new_wamf1_control( From 8bdfa33dcc5ec9d05853a70544d0baeffbb97ce0 Mon Sep 17 00:00:00 2001 From: Li Li Date: Fri, 18 Dec 2020 11:28:55 +1100 Subject: [PATCH 2/2] lint --- qctrlopencontrols/driven_controls/predefined.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qctrlopencontrols/driven_controls/predefined.py b/qctrlopencontrols/driven_controls/predefined.py index 1156533a..525344b3 100644 --- a/qctrlopencontrols/driven_controls/predefined.py +++ b/qctrlopencontrols/driven_controls/predefined.py @@ -3,7 +3,8 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 +# +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +23,6 @@ import numpy as np -from ..exceptions import ArgumentsValueError from ..utils import check_arguments from .driven_control import DrivenControl