예제 #1
0
    def test_sequence_stack(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)
        assert isinstance(slice0, FixedLengthSlice)
        waveform1 = DC(0.1e-6, 1)
        waveform2 = DC(0.1e-6, 2)
        waveform3 = DC(0.1e-6, 3)

        slice0.add_waveform(mock_awg0, waveform1)
        slice0.add_waveform(mock_awg0, waveform2)
        slice0.add_waveform(mock_awg0, waveform3)

        sequence.setup_trigger()
        sequence.setup_channels()
        sequence.run_channels()

        expected_waveform, _ = Blank(2.7e-6).concat(waveform1).concat(waveform2) \
            .concat(waveform3) \
            .normalized_sample(mock_awg0.device.sample_rate)

        assert isinstance(expected_waveform, np.ndarray)
        assert isinstance(mock_awg0.device.raw_waveform, np.ndarray)

        assert len(expected_waveform) == len(mock_awg0.device.raw_waveform)

        assert (mock_awg0.device.raw_waveform == expected_waveform).all()
예제 #2
0
    def test_slice_padding_across_multiple_trigger_channels(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)
        assert isinstance(slice2, FixedLengthSlice)
        waveform_awg0 = DC(0.1e-6, 1)
        waveform_awg2 = DC(0.1e-6, 1)
        waveform_awg4 = DC(0.1e-6, 1)

        slice2.add_waveform(mock_awg0, waveform_awg0)
        slice2.add_waveform(mock_awg3, waveform_awg2)
        slice2.add_waveform(mock_awg6, waveform_awg4)

        sequence.setup_trigger()
        sequence.setup_channels()
        sequence.run_channels()

        awg_0_expected_waveform, _ = Blank(2e-6 + 0.9e-6).concat(waveform_awg0) \
            .normalized_sample(mock_awg0.device.sample_rate)
        awg_2_expected_waveform, _ = Blank(1e-6 + 0.9e-6).concat(waveform_awg2) \
            .normalized_sample(mock_awg3.device.sample_rate)
        awg_4_expected_waveform, _ = Blank(0.9e-6).concat(waveform_awg4) \
            .normalized_sample(mock_awg6.device.sample_rate)

        for exp, awg in [
            (awg_0_expected_waveform, mock_awg0.device.raw_waveform),
            (awg_2_expected_waveform, mock_awg3.device.raw_waveform),
            (awg_4_expected_waveform, mock_awg6.device.raw_waveform)
        ]:
            assert isinstance(exp, np.ndarray)
            assert isinstance(awg, np.ndarray)
            assert len(exp) == len(awg)
            assert (exp == awg).all()
예제 #3
0
    def test_waveform_gate(self):
        runtime = init_runtime()
        sequence = init_gate_sequence(runtime)
        slice0 = FixedSlice("slice_0", 0, 5e-9)
        sequence.add_slice(slice0)

        waveform0 = DC(5e-9, 2)
        waveform1 = Blank(1e-9).concat(DC(3e-9, 1)).concat(Blank(1e-9))

        slice0.add_waveform(mock_awg10, waveform0)
        slice0.add_waveform(mock_awg10_gate, waveform1)

        sequence.setup_trigger()
        sequence.setup_channels()
        sequence.run_channels()

        expected_waveform, expected_amp = (waveform1 * waveform0) \
            .normalized_sample(mock_awg0.device.sample_rate)

        assert isinstance(expected_waveform, np.ndarray)
        assert isinstance(mock_awg0.device.raw_waveform, np.ndarray)

        assert len(expected_waveform) == len(mock_awg10.device.raw_waveform)

        assert expected_amp == mock_awg10.device.raw_waveform_amp
        assert (mock_awg10.device.raw_waveform == expected_waveform).all()
예제 #4
0
    def test_waveform_too_long_exception(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)

        waveform_slice0 = DC(3e-6, 2)

        slice0.add_waveform(mock_awg3, waveform_slice0)

        sequence.setup_trigger()

        with pytest.raises(AssertionError):
            sequence.setup_channels()
예제 #5
0
    def test_trigger_setup(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)
        sequence.setup_trigger()

        for channel, expected_raise_at, expected_duration in [(0, 0, 2e-6),
                                                              (1, 1e-6, 0),
                                                              (2, 2e-6, 0)]:
            raise_at, duration = mock_dg.device.get_channel_delay(channel)
            assert raise_at == expected_raise_at
            if expected_duration > 0:
                assert duration == expected_duration
예제 #6
0
    def test_procedure_result_retrieve(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)

        assert isinstance(slice0, Slice)

        cycle = self.MyTestStackCycle(runtime, slice0, mock_awg0,
                                      [(0.1e-6, 1)])
        cycle.add_procedure(self.DummyResultProcedure("prefix_"))
        res = cycle.run()

        assert res["prefix_res1"] == 3333
        assert res["prefix_res2"] == 4444
예제 #7
0
    def test_sub_slice_overleaf(self):
        runtime = init_runtime()
        sequence = init_nake_sequence(runtime)
        slice0 = FixedSlice("slice_0", 0, 20e-9)
        sequence.add_slice(slice0)

        sub_slice0 = FlexSlice("sub_slice0")
        sub_slice1 = FlexSlice("sub_slice1")
        sub_slice2 = FlexSlice("sub_slice2")

        slice0.add_sub_slice(sub_slice0)
        slice0.add_sub_slice(sub_slice1)
        slice0.add_sub_slice(sub_slice2)

        waveform0 = DC(5e-9, 1)
        waveform1 = DC(5e-9, 2)
        waveform2 = DC(10e-9, 3)

        sub_slice0.add_waveform(mock_awg0, waveform0)
        sub_slice1.add_waveform(mock_awg1, waveform1)
        sub_slice2.add_waveform(mock_awg2, waveform2)

        sequence.setup_trigger()
        sequence.setup_channels()
        sequence.run_channels()

        print(slice0.processed_waveforms[mock_awg0])
        print(slice0.processed_waveforms[mock_awg1])
        print(slice0.processed_waveforms[mock_awg2])

        print(sequence.last_compiled_waveforms[mock_awg0])
        print(sequence.last_compiled_waveforms[mock_awg1])
        print(sequence.last_compiled_waveforms[mock_awg2])

        awg_0_expected_waveform, _ = waveform0.concat(Blank(5e-9)).concat(Blank(10e-9))\
            .normalized_sample(mock_awg0.device.sample_rate)
        awg_1_expected_waveform, _ = Blank(5e-9).concat(waveform1).concat(Blank(10e-9)) \
            .normalized_sample(mock_awg1.device.sample_rate)
        awg_2_expected_waveform, _ = Blank(5e-9).concat(Blank(5e-9)).concat(waveform2)\
            .normalized_sample(mock_awg2.device.sample_rate)

        for i, (exp, awg) in enumerate([
            (awg_0_expected_waveform, mock_awg0.device.raw_waveform),
            (awg_1_expected_waveform, mock_awg1.device.raw_waveform),
            (awg_2_expected_waveform, mock_awg2.device.raw_waveform)
        ]):
            print(i)
            assert isinstance(exp, np.ndarray)
            assert isinstance(awg, np.ndarray)
            assert len(exp) == len(awg)
            assert (exp == awg).all()
예제 #8
0
    def test_waveform_overlap_exception(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)

        waveform_slice0 = DC(0.1e-6, 2)
        waveform_slice1 = DC(0.1e-6, 3)

        slice0.add_waveform(mock_awg0, waveform_slice0)
        slice1.add_waveform(mock_awg0, waveform_slice1)

        sequence.setup_trigger()

        with pytest.raises(AssertionError):
            sequence.setup_channels()
예제 #9
0
    def test_procedure_has_update(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)

        assert isinstance(slice0, Slice)

        cycle = self.MyTestStackCycle(runtime, slice0, mock_awg0,
                                      [(0.1e-6, 1)])
        cycle.run()

        assert not cycle.procedures[0].has_update

        cycle.procedures[0].waveform = DC(0.1e-6, 2)

        assert cycle.procedures[0].has_update
예제 #10
0
    def test_sub_slice_waveform_update(self):
        runtime = init_runtime()
        sequence = init_nake_sequence(runtime)
        slice0 = FixedSlice("slice_0", 0, 20e-9)
        sequence.add_slice(slice0)

        sub_slice0 = FlexSlice("sub_slice0")
        sub_slice1 = FlexSlice("sub_slice1")
        sub_slice2 = FlexSlice("sub_slice2")

        slice0.add_sub_slice(sub_slice0)
        slice0.add_sub_slice(sub_slice1)
        slice0.add_sub_slice(sub_slice2)

        waveform0 = DC(5e-9, 1)
        waveform1 = DC(5e-9, 2)
        waveform2 = DC(10e-9, 3)

        sub_slice0.add_waveform(mock_awg0, waveform0)
        sub_slice1.add_waveform(mock_awg1, waveform1)
        sub_slice2.add_waveform(mock_awg2, waveform2)

        sequence.setup_trigger()
        sequence.setup_channels()
        sequence.run_channels()

        assert slice0.get_updated_channel() == []

        sub_slice0.clear_waveform(mock_awg0)
        sub_slice0.add_waveform(mock_awg0, DC(5e-9, 2))
        # Slice length unchanged, expect that only awg0 need to be updated
        updated = slice0.get_updated_channel()
        assert mock_awg0 in updated
        assert mock_awg1 not in updated
        assert mock_awg2 not in updated

        waveform1_ = DC(2e-9, 2)
        sub_slice1.add_waveform(mock_awg1, waveform1_)
        # Slice length changed, expect that all channels to be updated

        updated = slice0.get_updated_channel()
        assert mock_awg0 in updated
        assert mock_awg1 in updated
        assert mock_awg2 in updated
예제 #11
0
    def test_stack_procedures(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)

        assert isinstance(slice0, Slice)

        cycle = self.MyTestStackCycle(runtime, slice0, mock_awg0,
                                      [(0.1e-6, 1), (0.1e-6, 2), (0.1e-6, 3)])
        cycle.run()

        expected_waveform, _ = Blank(2.7e-6).concat(DC(0.1e-6, 1)) \
            .concat(DC(0.1e-6, 2)).concat(DC(0.1e-6, 3)) \
            .normalized_sample(mock_awg0.device.sample_rate)

        assert isinstance(expected_waveform, np.ndarray)
        assert isinstance(mock_awg0.device.raw_waveform, np.ndarray)

        assert len(expected_waveform) == len(mock_awg0.device.raw_waveform)
        assert (mock_awg0.device.raw_waveform == expected_waveform).all()
예제 #12
0
    def test_sweep(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)

        assert isinstance(slice0, Slice)

        cycle = self.MyTestSweepCycle(runtime, slice0, mock_awg0)
        cycle.proc.amp = 1
        test_experiment = Sweep1DExperiment(runtime, "Test Experiment", cycle)

        res = test_experiment.sweep(
            scan_param="proc.len",
            scan_param_unit="s",
            points=np.linspace(0, 1e-6, 3),
            result_name="prefix_res1",
            result_unit="arb."
        )

        assert (res['prefix_res1'] == np.array([3333, 3334, 3335])).all()
예제 #13
0
    def test_slice_padding_after(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)
        assert isinstance(slice0, FixedLengthSlice)
        waveform = DC(0.1e-6, 1)

        slice0.set_waveform_padding(mock_awg0, PaddingPosition.PADDING_BEHIND)
        slice0.add_waveform(mock_awg0, waveform)

        sequence.setup_trigger()
        sequence.setup_channels()
        sequence.run_channels()

        expected_waveform, _ = waveform.concat(Blank(3e-6 - 0.1e-6)) \
            .normalized_sample(mock_awg0.device.sample_rate)

        assert isinstance(expected_waveform, np.ndarray)
        assert isinstance(mock_awg0.device.raw_waveform, np.ndarray)

        assert len(expected_waveform) == len(mock_awg0.device.raw_waveform)

        assert (mock_awg0.device.raw_waveform == expected_waveform).all()
예제 #14
0
    def test_same_awg_channel_across_slices(self):
        runtime = init_runtime()
        sequence, slice0, slice1, slice2 = init_fixed_sequence(runtime)

        waveform_slice1 = DC(0.1e-6, 2)
        waveform_slice2 = DC(0.1e-6, 3)

        slice1.add_waveform(mock_awg0, waveform_slice1)
        slice2.add_waveform(mock_awg0, waveform_slice2)

        sequence.setup_trigger()
        sequence.setup_channels()
        sequence.run_channels()

        expected_waveform, _ = Blank(1.9e-6).concat(waveform_slice1) \
            .concat(Blank(0.9e-6)).concat(waveform_slice2) \
            .normalized_sample(mock_awg0.device.sample_rate)

        assert isinstance(expected_waveform, np.ndarray)
        assert isinstance(mock_awg0.device.raw_waveform, np.ndarray)

        assert len(expected_waveform) == len(mock_awg0.device.raw_waveform)
        assert (mock_awg0.device.raw_waveform == expected_waveform).all()
예제 #15
0
    def test_sub_slice_single_channel(self):
        runtime = init_runtime()
        sequence = init_nake_sequence(runtime)
        slice0 = FixedSlice("slice_0", 0, 20e-9)
        sequence.add_slice(slice0)

        sub_slice0 = FlexSlice("sub_slice0")
        sub_slice1 = FlexSlice("sub_slice1")
        sub_slice2 = FlexSlice("sub_slice2")

        slice0.add_sub_slice(sub_slice0)
        slice0.add_sub_slice(sub_slice1)
        slice0.add_sub_slice(sub_slice2)

        waveform0 = DC(5e-9, 1)
        waveform1 = DC(5e-9, 2)
        waveform2 = DC(10e-9, 3)

        sub_slice0.add_waveform(mock_awg0, waveform0)
        sub_slice1.add_waveform(mock_awg0, waveform1)
        sub_slice2.add_waveform(mock_awg0, waveform2)

        sequence.setup_trigger()
        sequence.setup_channels()
        sequence.run_channels()

        expected_waveform, _ = waveform0.concat(waveform1) \
            .concat(waveform2) \
            .normalized_sample(mock_awg0.device.sample_rate)

        assert isinstance(expected_waveform, np.ndarray)
        assert isinstance(mock_awg0.device.raw_waveform, np.ndarray)

        assert len(expected_waveform) == len(mock_awg0.device.raw_waveform)

        assert (mock_awg0.device.raw_waveform == expected_waveform).all()
예제 #16
0
from unittest.mock import MagicMock, PropertyMock, patch, call
import numpy as np

from thunderq.cycles.native import Cycle
from utils import init_runtime, init_fixed_sequence

runtime = init_runtime()
init_fixed_sequence(runtime)

test_param1 = PropertyMock()
test_param2 = PropertyMock()
test_param3 = PropertyMock()

test_result = np.linspace(0, 99, 100)


def prepare_cycle():
    global test_param1, test_param2, test_param3
    cycle = MagicMock()
    test_param1 = PropertyMock()
    test_param2 = PropertyMock()
    test_param3 = PropertyMock()
    type(cycle).test_param1 = test_param1
    type(cycle).test_param2 = test_param2
    type(cycle).test_param3 = test_param3
    type(cycle).add_procedure = MagicMock()
    type(cycle).clear_procedures = MagicMock()
    type(cycle).run = MagicMock()
    type(cycle).run.side_effect = [{'test_result': v} for v in test_result]
    type(cycle).run_sequence = MagicMock()
    type(cycle).stop_sequence = MagicMock()