def test_conversion_to_driven_controls(): """Tests the method to convert a DDS to Driven Control """ _duration = 2. _offsets = 2 * np.array([0.25, 0.5, 0.75]) _rabi_rotations = np.array([np.pi, 0., np.pi]) _azimuthal_angles = np.array([np.pi / 2, 0., 0.]) _detuning_rotations = np.array([0., np.pi, 0.]) _name = 'test_sequence' dd_sequence = DynamicDecouplingSequence( duration=_duration, offsets=_offsets, rabi_rotations=_rabi_rotations, azimuthal_angles=_azimuthal_angles, detuning_rotations=_detuning_rotations, name=_name) _maximum_rabi_rate = 20 * np.pi _maximum_detuning_rate = 20 * np.pi driven_control = convert_dds_to_driven_control( dd_sequence, maximum_rabi_rate=_maximum_rabi_rate, maximum_detuning_rate=_maximum_detuning_rate, name=_name) assert np.allclose( driven_control.rabi_rates, np.array([0., _maximum_rabi_rate, 0., 0., 0., _maximum_rabi_rate, 0.])) assert np.allclose( driven_control.azimuthal_angles, np.array( [0., _azimuthal_angles[0], 0., 0., 0., _azimuthal_angles[2], 0.])) assert np.allclose(driven_control.detunings, np.array([0., 0., 0., np.pi, 0., 0., 0])) assert np.allclose( driven_control.durations, np.array([4.75e-1, 5e-2, 4.5e-1, 5e-2, 4.5e-1, 5e-2, 4.75e-1]))
def test_conversion_of_z_pi_2_pulses_at_extremities(): """ Tests if the method to convert a DDS to driven controls handles properly Z pi/2-pulses in inverse directions, in the beginning and end of the sequence. """ _duration = 1.0 _offsets = np.array([0.0, _duration]) _rabi_rotations = np.array([0, 0]) _azimuthal_angles = np.array([0, 0]) _detuning_rotations = np.array([-np.pi / 2, np.pi / 2]) _name = "z_pi2_pulse_sequence" dd_sequence = DynamicDecouplingSequence( duration=_duration, offsets=_offsets, rabi_rotations=_rabi_rotations, azimuthal_angles=_azimuthal_angles, detuning_rotations=_detuning_rotations, name=_name, ) _maximum_rabi_rate = 20 * np.pi _maximum_detuning_rate = 20 * np.pi driven_control = convert_dds_to_driven_control( dd_sequence, maximum_rabi_rate=_maximum_rabi_rate, maximum_detuning_rate=_maximum_detuning_rate, name=_name, ) assert np.allclose(driven_control.rabi_rates, np.array([0, 0.0, 0])) assert np.allclose(driven_control.azimuthal_angles, np.array([0, 0.0, 0])) assert np.allclose( driven_control.detunings, np.array([-_maximum_detuning_rate, 0.0, _maximum_detuning_rate]), ) assert np.allclose(driven_control.durations, np.array([2.5e-2, _duration - 2 * 2.5e-2, 2.5e-2]))
def test_free_evolution_conversion(): """Tests the conversion of free evolution """ _duration = 10. _name = 'test_sequence' _offsets = [] _rabi_rotations = [] _azimuthal_angles = [] _detuning_rotations = [] dd_sequence = DynamicDecouplingSequence( duration=_duration, offsets=_offsets, rabi_rotations=_rabi_rotations, azimuthal_angles=_azimuthal_angles, detuning_rotations=_detuning_rotations, name=_name) _maximum_rabi_rate = 20 * np.pi _maximum_detuning_rate = 20 * np.pi driven_control = convert_dds_to_driven_control( dd_sequence, maximum_rabi_rate=_maximum_rabi_rate, maximum_detuning_rate=_maximum_detuning_rate, name=_name) _rabi_rates = np.array([0.]) _azimuthal_angles = np.array([0.]) _detunings = np.array([0.]) _durations = np.array([_duration]) assert np.allclose(driven_control.rabi_rates, _rabi_rates) assert np.allclose(driven_control.azimuthal_angles, _azimuthal_angles) assert np.allclose(driven_control.detunings, _detunings) assert np.allclose(driven_control.durations, _durations) _duration = 10. _name = 'test_sequence' _offsets = [0, _duration] _rabi_rotations = [np.pi / 2, np.pi / 2] _azimuthal_angles = [0, 0] _detuning_rotations = [0, 0] dd_sequence = DynamicDecouplingSequence( duration=_duration, offsets=_offsets, rabi_rotations=_rabi_rotations, azimuthal_angles=_azimuthal_angles, detuning_rotations=_detuning_rotations, name=_name) _maximum_rabi_rate = 20 * np.pi _maximum_detuning_rate = 20 * np.pi driven_control = convert_dds_to_driven_control( dd_sequence, maximum_rabi_rate=_maximum_rabi_rate, maximum_detuning_rate=_maximum_detuning_rate, name=_name) _rabi_rates = np.array([_maximum_rabi_rate, 0., _maximum_rabi_rate]) _azimuthal_angles = np.array([0, 0, 0]) _detunings = np.array([0, 0, 0]) _durations = np.array([0.025, 9.95, 0.025]) assert np.allclose(driven_control.rabi_rates, _rabi_rates) assert np.allclose(driven_control.azimuthal_angles, _azimuthal_angles) assert np.allclose(driven_control.detunings, _detunings) assert np.allclose(driven_control.durations, _durations)
def test_export_to_file(): """ Tests exporting to file. """ _duration = 2.0 _offsets = 2 * np.array([0.0, 0.25, 0.5, 0.75, 1.0]) _rabi_rotations = np.array([0.0, np.pi, 0.0, np.pi, 0.0]) _azimuthal_angles = np.array([0.0, np.pi / 2, 0.0, 0.0, 0.0]) _detuning_rotations = np.array([0.0, 0.0, np.pi, 0.0, 0.0]) _name = "test_sequence" dd_sequence = DynamicDecouplingSequence( duration=_duration, offsets=_offsets, rabi_rotations=_rabi_rotations, azimuthal_angles=_azimuthal_angles, detuning_rotations=_detuning_rotations, name=_name, ) _maximum_rabi_rate = 20 * np.pi _maximum_detuning_rate = 20 * np.pi driven_control = convert_dds_to_driven_control( dd_sequence, maximum_rabi_rate=_maximum_rabi_rate, maximum_detuning_rate=_maximum_detuning_rate, name=_name, ) _filename = "dds_qctrl_cylindrical.csv" driven_control.export_to_file( filename=_filename, file_format="Q-CTRL expanded", file_type="CSV", coordinates="cylindrical", ) _filename = "dds_qctrl_cartesian.csv" driven_control.export_to_file( filename=_filename, file_format="Q-CTRL expanded", file_type="CSV", coordinates="cartesian", ) _filename = "dds_qctrl_cylindrical.json" driven_control.export_to_file( filename=_filename, file_format="Q-CTRL expanded", file_type="JSON", coordinates="cylindrical", ) _filename = "dds_qctrl_cartesian.json" driven_control.export_to_file( filename=_filename, file_format="Q-CTRL expanded", file_type="JSON", coordinates="cartesian", ) _remove_file("dds_qctrl_cylindrical.csv") _remove_file("dds_qctrl_cartesian.csv") _remove_file("dds_qctrl_cylindrical.json") _remove_file("dds_qctrl_cartesian.json")
def test_conversion_of_pi_2_pulses_to_driven_controls(): """ Tests if the method to convert a DDS to driven controls handles properly pi/2-pulses in the x, y, and z directions. """ _duration = 6.0 _offsets = np.array([0.5, 1.5, 2.5, 3.5, 4.5, 5.5]) _rabi_rotations = np.array( [np.pi / 2, 0.0, np.pi / 2, np.pi / 2, 0.0, np.pi / 2]) _azimuthal_angles = np.array([np.pi / 2, 0.0, 0.0, -np.pi / 2, 0, np.pi]) _detuning_rotations = np.array([0.0, np.pi / 2, 0.0, 0.0, -np.pi / 2, 0]) _name = "pi2_pulse_sequence" dd_sequence = DynamicDecouplingSequence( duration=_duration, offsets=_offsets, rabi_rotations=_rabi_rotations, azimuthal_angles=_azimuthal_angles, detuning_rotations=_detuning_rotations, name=_name, ) _maximum_rabi_rate = 20 * np.pi _maximum_detuning_rate = 20 * np.pi driven_control = convert_dds_to_driven_control( dd_sequence, maximum_rabi_rate=_maximum_rabi_rate, maximum_detuning_rate=_maximum_detuning_rate, name=_name, ) assert np.allclose( driven_control.rabi_rates, np.array([ 0.0, _maximum_rabi_rate, 0.0, 0.0, 0.0, _maximum_rabi_rate, 0.0, _maximum_rabi_rate, 0.0, 0.0, 0.0, _maximum_rabi_rate, 0.0, ]), ) assert np.allclose( driven_control.azimuthal_angles, np.array([ 0.0, _azimuthal_angles[0], 0.0, 0.0, 0.0, _azimuthal_angles[2], 0.0, _azimuthal_angles[3], 0.0, 0.0, 0.0, _azimuthal_angles[5], 0.0, ]), ) assert np.allclose( driven_control.detunings, np.array([ 0.0, 0.0, 0.0, _maximum_detuning_rate, 0.0, 0.0, 0.0, 0.0, 0.0, -_maximum_detuning_rate, 0.0, 0.0, 0.0, ]), ) assert np.allclose( driven_control.durations, np.array([ 4.875e-1, 2.5e-2, 9.75e-1, 2.5e-2, 9.75e-1, 2.5e-2, 9.75e-1, 2.5e-2, 9.75e-1, 2.5e-2, 9.75e-1, 2.5e-2, 4.875e-1, ]), )