Exemple #1
0
    def initialise(self):
        self.lab = Laboratory('UnitTests\\UTestExperimentConfiguration.yaml',
                              'test_save_dir/')

        self.lab.load_instrument('virAWG')
        awg_wfm = WaveformAWG("Wfm1", self.lab, [('virAWG', 'CH1'),
                                                 ('virAWG', 'CH2')], 1e9)
Exemple #2
0
from sqdtoolz.Experiment import Experiment
from sqdtoolz.HAL.GENatten import *
from sqdtoolz.Laboratory import *

new_lab = Laboratory(instr_config_file="tests\\ATTEN_Vaunix.yaml",
                     save_dir="mySaves\\")

new_lab.load_instrument('VaunixAtten')
atten_module = GENatten('rf_atten', new_lab, ['VaunixAtten', 'CH1'])

atten_module.Attenuation = 10
print(f'Attenuation: {atten_module.Attenuation}')
input('press <ENTER> to continue')
Exemple #3
0
class TestSegments(unittest.TestCase):
    ERR_TOL = 5e-13

    def initialise(self):
        self.lab = Laboratory('UnitTests\\UTestExperimentConfiguration.yaml',
                              'test_save_dir/')

        self.lab.load_instrument('virAWG')
        awg_wfm = WaveformAWG("Wfm1", self.lab, [('virAWG', 'CH1'),
                                                 ('virAWG', 'CH2')], 1e9)

    def cleanup(self):
        self.lab.release_all_instruments()
        self.lab = None

    def arr_equality(self, arr1, arr2):
        if arr1.size != arr2.size:
            return False
        return np.max(np.abs(arr1 - arr2)) < self.ERR_TOL

    def test_SegmentsAndIQ(self):
        self.initialise()
        awg_wfm = self.lab.HAL("Wfm1")

        #
        #Test IQ-Modulation
        #
        #Create unmodulated waveforms first
        read_segs = []
        read_segs2 = []
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init", None, 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        read_segs += ["init"]
        read_segs2 += ["zero2"]
        awg_wfm.get_output_channel(0).marker(1).set_markers_to_segments(
            read_segs)
        awg_wfm.get_output_channel(1).marker(0).set_markers_to_segments(
            read_segs2)
        #Gather initial arrays
        wfm_unmod = np.vstack(awg_wfm.get_raw_waveforms())
        #
        #Okay now modulate...
        WFMT_ModulationIQ('IQmod', self.lab, 47e7)
        WFMT_ModulationIQ('IQmod2', self.lab, 13e7)
        #
        #Changing phases Test
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        assert self.arr_equality(
            temp, wfm_mod), "The IQ waveform was incorrectly compiled."
        #
        #Trying two modulation areas
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2",
                         self.lab.WFMT('IQmod').apply(), 45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        init2_stencil = np.s_[60:105]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        temp[0, init2_stencil] *= np.cos(omega * 1e-9 * (np.arange(45) + 60))
        temp[1, init2_stencil] *= np.sin(omega * 1e-9 * (np.arange(45) + 60))
        assert self.arr_equality(
            temp, wfm_mod), "The IQ waveform was incorrectly compiled."
        #
        #Trying two different modulation areas
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2",
                         self.lab.WFMT('IQmod2').apply(), 45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        init2_stencil = np.s_[60:105]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        omega2 = 2 * np.pi * self.lab.WFMT('IQmod2').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        temp[0, init2_stencil] *= np.cos(omega2 * 1e-9 * (np.arange(45) + 60))
        temp[1, init2_stencil] *= np.sin(omega2 * 1e-9 * (np.arange(45) + 60))
        assert self.arr_equality(
            temp, wfm_mod
        ), "The IQ waveform was incorrectly compiled when using 2 different modulations."
        #
        #Trying to manipulate the phase now...
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2",
                         self.lab.WFMT('IQmod').apply(phase=0), 45e-9,
                         0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        init2_stencil = np.s_[60:105]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        omega2 = 2 * np.pi * self.lab.WFMT('IQmod2').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        temp[0, init2_stencil] *= np.cos(omega * 1e-9 * (np.arange(45)))
        temp[1, init2_stencil] *= np.sin(omega * 1e-9 * (np.arange(45)))
        assert self.arr_equality(
            temp, wfm_mod
        ), "The IQ waveform was incorrectly compiled when resetting phase to zero."
        #
        #Trying to manipulate the phase to a non-zero value...
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2",
                         self.lab.WFMT('IQmod').apply(phase=np.pi / 2), 45e-9,
                         0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        init2_stencil = np.s_[60:105]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        omega2 = 2 * np.pi * self.lab.WFMT('IQmod2').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        temp[0, init2_stencil] *= np.cos(omega * 1e-9 * (np.arange(45)) +
                                         np.pi / 2)
        temp[1, init2_stencil] *= np.sin(omega * 1e-9 * (np.arange(45)) +
                                         np.pi / 2)
        assert self.arr_equality(
            temp, wfm_mod
        ), "The IQ waveform was incorrectly compiled when changing phase to non-zero value."
        #
        #Trying to manipulate the phase to a negative non-zero value...
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2",
                         self.lab.WFMT('IQmod').apply(phase=-0.4125), 45e-9,
                         0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        init2_stencil = np.s_[60:105]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        omega2 = 2 * np.pi * self.lab.WFMT('IQmod2').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        temp[0,
             init2_stencil] *= np.cos(omega * 1e-9 * (np.arange(45)) - 0.4125)
        temp[1,
             init2_stencil] *= np.sin(omega * 1e-9 * (np.arange(45)) - 0.4125)
        assert self.arr_equality(
            temp, wfm_mod
        ), "The IQ waveform was incorrectly compiled when changing phase to a negative value."
        #
        #Trying to manipulate the phase offset...
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2",
                         self.lab.WFMT('IQmod').apply(phase_offset=-0.91939),
                         45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        init2_stencil = np.s_[60:105]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        omega2 = 2 * np.pi * self.lab.WFMT('IQmod2').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        temp[0, init2_stencil] *= np.cos(omega * 1e-9 * (np.arange(45) + 60) -
                                         0.91939)
        temp[1, init2_stencil] *= np.sin(omega * 1e-9 * (np.arange(45) + 60) -
                                         0.91939)
        assert self.arr_equality(
            temp, wfm_mod
        ), "The IQ waveform was incorrectly compiled when changing phase offset."
        #
        #Trying to manipulate the phase offset and checking relation down the track...
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2",
                         self.lab.WFMT('IQmod').apply(phase_offset=-0.91939),
                         45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3",
                         self.lab.WFMT('IQmod').apply(), 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        init2_stencil = np.s_[60:105]
        init3_stencil = np.s_[182:227]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        omega2 = 2 * np.pi * self.lab.WFMT('IQmod2').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        temp[0, init2_stencil] *= np.cos(omega * 1e-9 * (np.arange(45) + 60) -
                                         0.91939)
        temp[1, init2_stencil] *= np.sin(omega * 1e-9 * (np.arange(45) + 60) -
                                         0.91939)
        temp[0, init3_stencil] *= np.cos(omega * 1e-9 * (np.arange(45) + 182) -
                                         0.91939)
        temp[1, init3_stencil] *= np.sin(omega * 1e-9 * (np.arange(45) + 182) -
                                         0.91939)
        assert self.arr_equality(
            temp, wfm_mod
        ), "The IQ waveform was incorrectly compiled when changing phase offset in a previous waveform segment."
        #
        #Trying to manipulate the phase and checking relation down the track...
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2",
                         self.lab.WFMT('IQmod').apply(phase=0.1), 45e-9,
                         0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3",
                         self.lab.WFMT('IQmod').apply(), 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        init2_stencil = np.s_[60:105]
        init3_stencil = np.s_[182:227]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        omega2 = 2 * np.pi * self.lab.WFMT('IQmod2').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        temp[0, init2_stencil] *= np.cos(omega * 1e-9 * (np.arange(45)) + 0.1)
        temp[1, init2_stencil] *= np.sin(omega * 1e-9 * (np.arange(45)) + 0.1)
        temp[0, init3_stencil] *= np.cos(omega * 1e-9 *
                                         (np.arange(45) + 182 - 60) + 0.1)
        temp[1, init3_stencil] *= np.sin(omega * 1e-9 *
                                         (np.arange(45) + 182 - 60) + 0.1)
        assert self.arr_equality(
            temp, wfm_mod
        ), "The IQ waveform was incorrectly compiled when changing phase in a previous waveform segment."
        #
        #Trying to manipulate the phase and checking relation down the track with 2 separate frequencies!...
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(phase=0.1), 20e-9,
                         0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2",
                         self.lab.WFMT('IQmod2').apply(), 45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3",
                         self.lab.WFMT('IQmod').apply(), 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        init2_stencil = np.s_[60:105]
        init3_stencil = np.s_[182:227]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        omega2 = 2 * np.pi * self.lab.WFMT('IQmod2').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20)) + 0.1)
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20)) + 0.1)
        temp[0, init2_stencil] *= np.cos(omega2 * 1e-9 * (np.arange(45) + 60))
        temp[1, init2_stencil] *= np.sin(omega2 * 1e-9 * (np.arange(45) + 60))
        temp[0, init3_stencil] *= np.cos(omega * 1e-9 *
                                         (np.arange(45) + 182 - 10) + 0.1)
        temp[1, init3_stencil] *= np.sin(omega * 1e-9 *
                                         (np.arange(45) + 182 - 10) + 0.1)
        assert self.arr_equality(
            temp, wfm_mod
        ), "The IQ waveform was incorrectly compiled when changing phase in a previous waveform segment with 2 frequencies in play."

        shutil.rmtree('test_save_dir')
        self.cleanup()

    def test_Group(self):
        self.initialise()
        awg_wfm = self.lab.HAL("Wfm1")
        read_segs = []
        read_segs2 = []
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init", None, 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        read_segs += ["init"]
        read_segs2 += ["zero2"]
        awg_wfm.get_output_channel(0).marker(1).set_markers_to_segments(
            read_segs)
        awg_wfm.get_output_channel(1).marker(0).set_markers_to_segments(
            read_segs2)
        #Gather initial arrays
        wfm_unmod = np.vstack(awg_wfm.get_raw_waveforms())
        #Modulations
        WFMT_ModulationIQ('IQmod', self.lab, 47e7)
        WFMT_ModulationIQ('IQmod2', self.lab, 13e7)

        #
        #Test WFM_Group
        #
        #Default test with an elastic segment
        awg_wfm = WaveformAWG("Wfm1",
                              self.lab, [('virAWG', 'CH1'), ('virAWG', 'CH2')],
                              1e9,
                              total_time=227e-9)
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, -1, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        assert self.arr_equality(
            temp, wfm_mod), "Default waveform compilation failed."
        #
        #Test a basic WFS_Group construct
        awg_wfm = WaveformAWG("Wfm1",
                              self.lab, [('virAWG', 'CH1'), ('virAWG', 'CH2')],
                              1e9,
                              total_time=227e-9)
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, -1, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Group("TestGroup", [
                WFS_Constant("zero1", None, 30e-9, 0.1),
                WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1)
            ]))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        assert self.arr_equality(
            temp, wfm_mod), "WFS_Group failed in waveform compilation."
        #
        #Test a basic WFS_Group construct with elastic time-frame
        awg_wfm = WaveformAWG("Wfm1",
                              self.lab, [('virAWG', 'CH1'), ('virAWG', 'CH2')],
                              1e9,
                              total_time=227e-9)
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, -1, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Group("TestGroup", [
                WFS_Constant("zero1", None, -1, 0.1),
                WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1)
            ],
                      time_len=75e-9))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        assert self.arr_equality(
            temp, wfm_mod), "WFS_Group failed in waveform compilation."
        #
        #Test marker decomposition...
        awg_wfm = WaveformAWG("Wfm1",
                              self.lab, [('virAWG', 'CH1'), ('virAWG', 'CH2')],
                              1e9,
                              total_time=227e-9)
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, -1, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Group("TestGroup", [
                WFS_Constant("zero1", None, -1, 0.1),
                WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1)
            ],
                      time_len=75e-9))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        awg_wfm.get_output_channel(0).marker(0).set_markers_to_segments(
            ['init', ['TestGroup', 'init2'], 'init3'])
        raw_mkrs = awg_wfm.get_output_channel(0).marker(
            0).get_raw_marker_waveform()
        exp_mkrs = np.array([0] * 10 + [1] * 20 + [0] * 30 + [1] * 45 +
                            [0] * 77 + [1] * 45)
        assert self.arr_equality(
            raw_mkrs, exp_mkrs), "WFS_Group failed in marker compilation."
        #
        #Test marker decomposition in nested WFS_Groups...
        awg_wfm = WaveformAWG("Wfm1",
                              self.lab, [('virAWG', 'CH1'), ('virAWG', 'CH2')],
                              1e9,
                              total_time=237e-9)
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, -1, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Group("TestGroup", [
                WFS_Constant("zero1", None, -1, 0.1),
                WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1)
            ],
                      time_len=75e-9))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Group("TestGroup2", [
                WFS_Group("Sub1", [
                    WFS_Constant("zero1", None, 3e-9, 0.1),
                    WFS_Gaussian("init2", None, 2e-9, 0.5 - 0.1)
                ],
                          time_len=5e-9),
                WFS_Gaussian("init2", None, 5e-9, 0.5 - 0.1)
            ],
                      time_len=10e-9))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        awg_wfm.get_output_channel(0).marker(0).set_markers_to_segments([
            'init', ['TestGroup', 'init2'], 'init3',
            ['TestGroup2', 'Sub1', 'init2']
        ])
        raw_mkrs = awg_wfm.get_output_channel(0).marker(
            0).get_raw_marker_waveform()
        exp_mkrs = np.array([0] * 10 + [1] * 20 + [0] * 30 + [1] * 45 +
                            [0] * 77 + [0] * 3 + [1] * 2 + [0] * 5 + [1] * 45)
        assert self.arr_equality(
            raw_mkrs, exp_mkrs
        ), "WFS_Group failed in marker compilation in a nested case."

        #An interesting edge-case
        wait_times = np.linspace(1e-9, 2e-6, 49)
        WaveformAWG("wfmRabi", self.lab, [('virAWG', 'CH1'),
                                          ('virAWG', 'CH2')], 1.25e9)
        self.lab.HAL("wfmRabi").set_valid_total_time(
            (wait_times.size + 1) * 50e-6)
        self.lab.HAL("wfmRabi").clear_segments()
        read_segs = []
        for m, cur_wait in enumerate(wait_times):
            self.lab.HAL("wfmRabi").add_waveform_segment(
                WFS_Group("TestGroup", [
                    WFS_Constant(f"init{m}", None, -1, 0.0),
                    WFS_Gaussian(f"tip{m}",
                                 self.lab.WFMT('IQmod').apply(phase=0), 40e-9,
                                 1),
                    WFS_Constant(f"wait{m}", None, cur_wait, 0.0),
                    WFS_Gaussian(f"untip{m}",
                                 self.lab.WFMT('IQmod').apply(), 40e-9, 2),
                    WFS_Constant(f"pad{m}", None, 5e-9, 0.0)
                ],
                          time_len=46e-6))
            self.lab.HAL("wfmRabi").add_waveform_segment(
                WFS_Constant(f"read{m}", None, 4e-6, 0.0))
            read_segs += [f"read{m}"]
        self.lab.HAL("wfmRabi").add_waveform_segment(
            WFS_Constant("init_pad", None, -1, 0.0))
        self.lab.HAL("wfmRabi").get_raw_waveforms()

        shutil.rmtree('test_save_dir')
        self.cleanup()

    def test_SaveReload(self):
        self.initialise()
        self.lab.load_instrument('virACQ')
        hal_acq = ACQ("dum_acq", self.lab, 'virACQ')

        awg_wfm = self.lab.HAL("Wfm1")
        read_segs = []
        read_segs2 = []
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init", None, 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        read_segs += ["init"]
        read_segs2 += ["zero2"]
        awg_wfm.get_output_channel(0).marker(1).set_markers_to_segments(
            read_segs)
        awg_wfm.get_output_channel(1).marker(0).set_markers_to_segments(
            read_segs2)
        #Gather initial arrays
        wfm_unmod = np.vstack(awg_wfm.get_raw_waveforms())
        #Modulations
        WFMT_ModulationIQ('IQmod', self.lab, 47e7)
        WFMT_ModulationIQ('IQmod2', self.lab, 13e7)
        #Test a basic WFS_Group construct with elastic time-frame
        awg_wfm = WaveformAWG("Wfm1",
                              self.lab, [('virAWG', 'CH1'), ('virAWG', 'CH2')],
                              1e9,
                              total_time=227e-9)
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, -1, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init",
                         self.lab.WFMT('IQmod').apply(), 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Group("TestGroup", [
                WFS_Constant("zero1", None, -1, 0.1),
                WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1)
            ],
                      time_len=75e-9))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        init_stencil = np.s_[10:30]
        temp = wfm_unmod * 1.0
        omega = 2 * np.pi * self.lab.WFMT('IQmod').IQFrequency
        temp[0, init_stencil] *= np.cos(omega * 1e-9 * (np.arange(20) + 10))
        temp[1, init_stencil] *= np.sin(omega * 1e-9 * (np.arange(20) + 10))
        #
        assert self.arr_equality(
            temp, wfm_mod), "WFS_Group failed in waveform compilation."

        expConfig = ExperimentConfiguration('testConf', self.lab, 1.0,
                                            ['Wfm1'], 'dum_acq')
        # leConfig = expConfig.save_config()

        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, -1, 0.0))
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        assert not self.arr_equality(
            temp, wfm_mod
        ), "The waveform randomly compiles correctly even though it has been redone."
        expConfig.init_instruments()
        wfm_mod = np.vstack(awg_wfm.get_raw_waveforms())
        assert self.arr_equality(
            temp,
            wfm_mod), "The waveform was not constructed properly on reloading."

        shutil.rmtree('test_save_dir')
        self.cleanup()
Exemple #4
0
class TestAWGChecks(unittest.TestCase):
    def initialise(self):
        self.lab = Laboratory('UnitTests\\UTestExperimentConfiguration.yaml',
                              'test_save_dir/')

        self.lab.load_instrument('virAWG')
        awg_wfm = WaveformAWG("Wfm1", self.lab, [('virAWG', 'CH1'),
                                                 ('virAWG', 'CH2')], 1e9)

    def cleanup(self):
        self.lab.release_all_instruments()
        self.lab = None

    def test_MemoryChecks(self):
        self.initialise()
        awg_wfm = self.lab.HAL("Wfm1")
        #
        #Verify the waveform memory requirement checks
        #
        #Multiple of N check
        read_segs = []
        read_segs2 = []
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 10e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init", None, 20e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero1", None, 30e-9, 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init2", None, 45e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(WFS_Constant("zero2", None, 77e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init3", None, 45e-9, 0.5 - 0.1))
        read_segs += ["init"]
        read_segs2 += ["zero2"]
        awg_wfm.get_output_channel(0).marker(1).set_markers_to_segments(
            read_segs)
        awg_wfm.get_output_channel(1).marker(0).set_markers_to_segments(
            read_segs2)
        assert_found = False
        try:
            awg_wfm.prepare_initial()
            awg_wfm.prepare_final()
        except AssertionError:
            assert_found = True
        assert assert_found, "The waveform preparation function incorrectly accepts a waveform that does not satisfy the instrument's memory requirement (multiple of 8)."
        #
        #Minimum N check
        read_segs = []
        read_segs2 = []
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 1e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init", None, 1e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("zero2", None, 1e-9, 0.5 - 0.1))
        read_segs += ["init"]
        read_segs2 += ["zero2"]
        awg_wfm.get_output_channel(0).marker(1).set_markers_to_segments(
            read_segs)
        awg_wfm.get_output_channel(1).marker(0).set_markers_to_segments(
            read_segs2)
        assert_found = False
        try:
            awg_wfm.prepare_initial()
            awg_wfm.prepare_final()
        except AssertionError:
            assert_found = True
        assert assert_found, "The waveform preparation function incorrectly accepts a waveform that does not satisfy the instrument's memory requirement (minimum of 8)."
        #
        #Check normal programming works...
        read_segs = []
        read_segs2 = []
        awg_wfm.clear_segments()
        awg_wfm.add_waveform_segment(WFS_Constant("SEQPAD", None, 12e-9, 0.0))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("init", None, 4e-9, 0.5 - 0.1))
        awg_wfm.add_waveform_segment(
            WFS_Gaussian("zero2", None, 8e-9, 0.5 - 0.1))
        read_segs += ["init"]
        read_segs2 += ["zero2"]
        awg_wfm.get_output_channel(0).marker(1).set_markers_to_segments(
            read_segs)
        awg_wfm.get_output_channel(1).marker(0).set_markers_to_segments(
            read_segs2)
        assert_found = False
        awg_wfm.prepare_initial()
        awg_wfm.prepare_final()

        shutil.rmtree('test_save_dir')
        self.cleanup()

    def test_ValidLengthFunctions(self):
        self.initialise()
        awg_wfm = self.lab.HAL("Wfm1")
        #
        #Check the valid length functions
        #
        assert awg_wfm.get_valid_length_from_time(12e-9) == [
            16e-9, 16e-9
        ], "Valid time lengths for a given time are incorrect."
        assert awg_wfm.get_valid_length_from_time(16e-9) == [
            16e-9, 16e-9
        ], "Valid time lengths for a given time are incorrect."
        assert awg_wfm.get_valid_length_from_time(5e-9) == [
            8e-9, 8e-9
        ], "Valid time lengths for a given time are incorrect."
        #
        assert awg_wfm.get_valid_length_from_pts(12) == [
            16e-9, 16e-9
        ], "Valid time lengths for a given time are incorrect."
        assert awg_wfm.get_valid_length_from_pts(16) == [
            16e-9, 16e-9
        ], "Valid time lengths for a given time are incorrect."
        assert awg_wfm.get_valid_length_from_pts(5) == [
            8e-9, 8e-9
        ], "Valid time lengths for a given time are incorrect."

        shutil.rmtree('test_save_dir')
        self.cleanup()
Exemple #5
0
from sqdtoolz.Experiment import Experiment
from sqdtoolz.HAL.DDG import*
from sqdtoolz.HAL.GENmwSource import*
from sqdtoolz.ExperimentConfiguration import*
from sqdtoolz.Laboratory import*

new_lab = Laboratory(instr_config_file = "tests\\SGS100A_Test.yaml", save_dir = "mySaves\\")


#Can be done in YAML
# instr_ddg = DDG_DG645('ddg_real')
# new_exp.add_instrument(instr_ddg)

#Ideally, the length and polarity are set to default values in the drivers via the YAML file - i.e. just set TrigPulseDelay
ddg_module = DDG(new_lab._station.load_pulser())
ddg_module.get_trigger_output('AB').TrigPulseLength = 50e-9
ddg_module.get_trigger_output('AB').TrigPolarity = 1
ddg_module.get_trigger_output('AB').TrigPulseDelay = 10e-9
ddg_module.get_trigger_output('CD').TrigPulseLength = 5e-6
ddg_module.get_trigger_output('CD').TrigPulseDelay = 0e-9
ddg_module.get_trigger_output('CD').TrigPolarity = 1
ddg_module.get_trigger_output('EF').TrigPulseLength = 400e-9
ddg_module.get_trigger_output('EF').TrigPulseDelay = 250e-9
ddg_module.get_trigger_output('EF').TrigPolarity = 0
ddg_module._instr_ddg.trigger_rate(0.1e6)

freq_module = GENmwSource(new_lab._station.load_SGS100A().get_output('RFOUT'))

freq_module.Power = 0
freq_module.Output = True
freq_module.Mode = 'PulseModulated'
Exemple #6
0
from sqdtoolz.Experiment import Experiment
from sqdtoolz.HAL.DDG import *
from sqdtoolz.HAL.GENvoltSource import *
from sqdtoolz.ExperimentConfiguration import *
from sqdtoolz.Laboratory import *

new_lab = Laboratory(instr_config_file="tests\\SIM928.yaml",
                     save_dir="mySaves\\")

instr_sim928 = new_lab._station.load_sim_rack928()

volt_module = GENvoltSource(instr_sim928.get_output(3))

#Slow Ramp
volt_module.RampRate = 0.001
volt_module.Voltage = 0.020
input('press <ENTER> to continue')
#Fast Ramp
volt_module.RampRate = 0.1
volt_module.Voltage = 1.0
input('press <ENTER> to continue')
volt_module.Voltage = 0.0

input('press <ENTER> to continue')
from sqdtoolz.Experiment import *
from sqdtoolz.Laboratory import *

from sqdtoolz.Drivers.dummyGENmwSource import *
from sqdtoolz.HAL.ACQ import *
from sqdtoolz.HAL.AWG import *
from sqdtoolz.HAL.DDG import *
from sqdtoolz.HAL.GENmwSource import *

from sqdtoolz.HAL.WaveformGeneric import *
from sqdtoolz.HAL.WaveformMapper import *

import numpy as np
import time

new_lab = Laboratory('UnitTests\\UTestExperimentConfiguration.yaml',
                     'test_save_dir/')

new_lab.load_instrument('virACQ')
new_lab.load_instrument('virDDG')
new_lab.load_instrument('virAWG')
new_lab.load_instrument('virMWS')

#Initialise test-modules
hal_acq = ACQ("dum_acq", new_lab, 'virACQ')
hal_ddg = DDG(
    "ddg",
    new_lab,
    'virDDG',
)
awg_wfm = WaveformAWG("Wfm1", new_lab, [('virAWG', 'CH1'), ('virAWG', 'CH2')],
                      1e9)
from sqdtoolz.Experiment import Experiment
from sqdtoolz.HAL.DDG import*
from sqdtoolz.HAL.GENmwSource import*
from sqdtoolz.ExperimentConfiguration import*
from sqdtoolz.Laboratory import*

new_lab = Laboratory(instr_config_file = "tests\\WFSynthHDProV2_Test.yaml", save_dir = "mySaves\\")

#Ideally, the length and polarity are set to default values in the drivers via the YAML file - i.e. just set TrigPulseDelay
ddg_module = DDG(new_lab._station.load_pulser())
ddg_module.get_trigger_output('AB').TrigPulseLength = 500e-9
ddg_module.get_trigger_output('AB').TrigPolarity = 1
ddg_module.get_trigger_output('AB').TrigPulseDelay = 10e-9
new_lab._station.load_pulser().trigger_rate(500e3)

instr_freq = new_lab._station.load_MWS_Windfreak()
freq_module = GENmwSource(instr_freq.get_output('RFoutA'))
freq_module2 = GENmwSource(instr_freq.get_output('RFoutB'))

freq_module.Power = 0
freq_module.Output = True
freq_module.Frequency = 4e9
freq_module.Mode = 'Continuous'

freq_module2.Power = 0
freq_module2.Output = True
freq_module2.Frequency = 7e9
freq_module2.Mode = 'Continuous'

input('press <ENTER> to continue')
Exemple #9
0
from sqdtoolz.HAL.DDG import *
from sqdtoolz.HAL.AWG import *
from sqdtoolz.HAL.ACQ import *
from sqdtoolz.ExperimentConfiguration import *
from sqdtoolz.HAL.WaveformSegments import *
from sqdtoolz.HAL.WaveformTransformations import *
import numpy as np
from sqdtoolz.Variable import *
from sqdtoolz.Laboratory import *

from sqdtoolz.HAL.Processors.ProcessorCPU import *
from sqdtoolz.HAL.Processors.CPU.CPU_DDC import *
from sqdtoolz.HAL.Processors.CPU.CPU_FIR import *
from sqdtoolz.HAL.Processors.CPU.CPU_Mean import *

new_lab = Laboratory(instr_config_file="tests\\TaborTest.yaml",
                     save_dir="mySaves\\")

#Can be done in YAML
# instr_ddg = DDG_DG645('ddg_real')
# new_exp.add_instrument(instr_ddg)

#Ideally, the length and polarity are set to default values in the drivers via the YAML file - i.e. just set TrigPulseDelay
# ddg_module = DDG(new_lab._station.load_pulser())
# ddg_module.get_trigger_output('AB').TrigPulseLength = 500e-9
# ddg_module.get_trigger_output('AB').TrigPolarity = 1
# ddg_module.get_trigger_output('AB').TrigPulseDelay = 0e-9
# ddg_module.get_trigger_output('CD').TrigPulseLength = 100e-9
# ddg_module.get_trigger_output('CD').TrigPulseDelay = 50e-9
# ddg_module.get_trigger_output('CD').TrigPolarity = 1
# ddg_module.get_trigger_output('EF').TrigPulseLength = 50e-9
# ddg_module.get_trigger_output('EF').TrigPulseDelay = 10e-9