Пример #1
0
    def test_unsafe_sample(self) -> None:
        interp = DummyInterpolationStrategy()
        entries = [
            TableWaveformEntry(0, 0, interp),
            TableWaveformEntry(2.1, -33.2, interp),
            TableWaveformEntry(5.7, 123.4, interp)
        ]
        waveform = TableWaveform('A', entries)
        sample_times = numpy.linspace(.5, 5.5, num=11)

        expected_interp_arguments = [
            ((0, 0), (2.1, -33.2), [0.5, 1.0, 1.5, 2.0]),
            ((2.1, -33.2), (5.7, 123.4), [2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5])
        ]
        expected_result = numpy.copy(sample_times)

        result = waveform.unsafe_sample('A', sample_times)

        self.assertEqual(expected_interp_arguments, interp.call_arguments)
        numpy.testing.assert_equal(expected_result, result)

        output_expected = numpy.empty_like(expected_result)
        output_received = waveform.unsafe_sample('A',
                                                 sample_times,
                                                 output_array=output_expected)
        self.assertIs(output_expected, output_received)
        numpy.testing.assert_equal(expected_result, output_received)
Пример #2
0
 def test_unsafe_get_subset_for_channels(self):
     interp = DummyInterpolationStrategy()
     entries = [
         TableWaveformEntry(0, 0, interp),
         TableWaveformEntry(2.1, -33.2, interp),
         TableWaveformEntry(5.7, 123.4, interp)
     ]
     waveform = TableWaveform('A', entries)
     self.assertIs(waveform.unsafe_get_subset_for_channels({'A'}), waveform)
Пример #3
0
    def test_simple_properties(self):
        interp = DummyInterpolationStrategy()
        entries = [
            TableWaveformEntry(0, 0, interp),
            TableWaveformEntry(2.1, -33.2, interp),
            TableWaveformEntry(5.7, 123.4, interp)
        ]
        chan = 'A'
        waveform = TableWaveform(chan, entries)

        self.assertEqual(waveform.defined_channels, {chan})
        self.assertIs(waveform.unsafe_get_subset_for_channels({'A'}), waveform)
 def test_sample(self) -> None:
     interp = DummyInterpolationStrategy()
     entries = tuple([WaveformTableEntry(0, 0, interp),
                      WaveformTableEntry(2.1, -33.2, interp),
                      WaveformTableEntry(5.7, 123.4, interp)
                      ])
     waveform = TableWaveform(entries)
     sample_times = numpy.linspace(98.5, 103.5, num=11)
     offset = 0.5
     result = waveform.sample(sample_times, offset)
     expected_data = [((0, 0), (2.1, -33.2), [0.5, 1.0, 1.5, 2.0]),
                      ((2.1, -33.2), (5.7, 123.4), [2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5])]
     self.assertEqual(expected_data, interp.call_arguments)
     self.assertEqual(list(sample_times), list(result))
Пример #5
0
    def test_sample(self) -> None:
        interp = DummyInterpolationStrategy()
        entries = [[WaveformTableEntry(0, 0, interp),
                    WaveformTableEntry(2.1, -33.2, interp),
                    WaveformTableEntry(5.7, 123.4, interp)]]
        waveform = TableWaveform(entries)
        sample_times = numpy.linspace(98.5, 103.5, num=11)

        offset = 0.5
        result = waveform.sample(sample_times, offset)
        expected_data = [((0, 0), (2.1, -33.2), [0.5, 1.0, 1.5, 2.0]),
                         ((2.1, -33.2), (5.7, 123.4), [2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5])]
        self.assertEqual(expected_data, interp.call_arguments)
        expected_result = [sample_times - 98]
        self.assertTrue(numpy.all(expected_result == result))
Пример #6
0
 def test_duration(self) -> None:
     entries = [
         TableWaveformEntry(0, 0, HoldInterpolationStrategy()),
         TableWaveformEntry(5, 1, HoldInterpolationStrategy())
     ]
     waveform = TableWaveform('A', entries)
     self.assertEqual(5, waveform.duration)
Пример #7
0
    def test_num_channels(self) -> None:
        waveform = TableWaveform([])
        self.assertEqual(0, waveform.num_channels)

        interp = DummyInterpolationStrategy()
        entries = [[WaveformTableEntry(0, 0, interp),
                    WaveformTableEntry(5, 1, interp)]]
        waveform = TableWaveform(entries)
        self.assertEqual(1, waveform.num_channels)

        entries = [[WaveformTableEntry(0, 0, interp),
                    WaveformTableEntry(2.1, -33.2, interp),
                    WaveformTableEntry(5.7, 123.4, interp)],
                   [WaveformTableEntry(0, 0, interp),
                    WaveformTableEntry(2.1, -33.2, interp),
                    WaveformTableEntry(5.7, 123.4, interp)]]
        waveform = TableWaveform(entries)
        self.assertEqual(2, waveform.num_channels)
    def test_get_entries_instantiated_removal_for_three_subsequent_equal_entries_does_not_destroy_linear_interpolation(self) -> None:
        table = TablePulseTemplate()
        table.add_entry(0, 5)
        table.add_entry(2, 5, 'linear')
        table.add_entry(5, 5)
        table.add_entry(10, 0, 'linear')

        entries = table.get_entries_instantiated({})

        expected = [
            TableEntry(0, 5, HoldInterpolationStrategy()),
            TableEntry(5, 5, HoldInterpolationStrategy()),
            TableEntry(10, 0, LinearInterpolationStrategy())
        ]
        self.assertEqual(expected, entries)

        result_sampled = TableWaveform(entries).sample(numpy.linspace(0, 10, 11), 0)

        self.assertEqual([5, 5, 5, 5, 5, 5, 4, 3, 2, 1, 0], result_sampled.tolist())
Пример #9
0
    def test_get_entries_instantiated_removal_for_three_subsequent_equal_entries_does_not_destroy_linear_interpolation(self) -> None:
        table = TablePulseTemplate()
        table.add_entry(0, 5)
        table.add_entry(2, 5, 'linear')
        table.add_entry(5, 5)
        table.add_entry(10, 0, 'linear')

        entries = table.get_entries_instantiated({})

        expected = [[
            TableEntry(0, 5, HoldInterpolationStrategy()),
            TableEntry(5, 5, HoldInterpolationStrategy()),
            TableEntry(10, 0, LinearInterpolationStrategy())
        ]]
        self.assertEqual(expected, entries)

        result_sampled = TableWaveform(entries).sample(numpy.linspace(0, 10, 11), 0)

        numbers = [5, 5, 5, 5, 5, 5, 4, 3, 2, 1, 0]
        expected = [[float(x) for x in numbers]]
        self.assertEqual(expected, result_sampled.tolist())
Пример #10
0
    def test_validate_input_duplicate_removal(self):
        validated = TableWaveform._validate_input([
            TableWaveformEntry(0.0, 0.2, HoldInterpolationStrategy()),
            TableWaveformEntry(0.1, 0.2, LinearInterpolationStrategy()),
            TableWaveformEntry(0.1, 0.3, JumpInterpolationStrategy()),
            TableWaveformEntry(0.1, 0.3, HoldInterpolationStrategy()),
            TableWaveformEntry(0.2, 0.3, LinearInterpolationStrategy()),
            TableWaveformEntry(0.3, 0.3, JumpInterpolationStrategy())
        ])

        self.assertEqual(
            validated,
            (TableWaveformEntry(0.0, 0.2, HoldInterpolationStrategy()),
             TableWaveformEntry(0.1, 0.2, LinearInterpolationStrategy()),
             TableWaveformEntry(0.1, 0.3, HoldInterpolationStrategy()),
             TableWaveformEntry(0.3, 0.3, JumpInterpolationStrategy())))
Пример #11
0
    def test_build_sequence_multi_one_channel_empty(self) -> None:
        table = TablePulseTemplate(channels=2)
        table.add_entry('foo', 4)
        parameters = {'foo': 3}

        instantiated_entries = table.get_entries_instantiated(parameters)

        sequencer = DummySequencer()
        instruction_block = DummyInstructionBlock()
        table.build_sequence(sequencer, parameters, {}, instruction_block)
        expected_waveform = TableWaveform(instantiated_entries)
        self.assertEqual(1, len(instruction_block.instructions))
        instruction = instruction_block.instructions[0]
        self.assertIsInstance(instruction, EXECInstruction)
        self.assertEqual(expected_waveform, instruction.waveform)
        waveform = table.build_waveform(parameters)
        self.assertEqual(expected_waveform, waveform)
Пример #12
0
 def test_build_sequence(self) -> None:
     table = TablePulseTemplate()
     foo_decl = ParameterDeclaration('foo', min=1)
     bar_decl = ParameterDeclaration('bar')
     table.add_entry(foo_decl, 'v', 'linear')
     table.add_entry(bar_decl, 0, 'jump')
     parameters = {'v': 2.3, 'foo': 1, 'bar': 4}
     instantiated_entries = tuple(table.get_entries_instantiated(parameters))
     waveform = table.build_waveform(parameters)
     sequencer = DummySequencer()
     instruction_block = DummyInstructionBlock()
     table.build_sequence(sequencer, parameters, {}, instruction_block)
     expected_waveform = TableWaveform(instantiated_entries)
     self.assertEqual(1, len(instruction_block.instructions))
     instruction = instruction_block.instructions[0]
     self.assertIsInstance(instruction, EXECInstruction)
     self.assertEqual(expected_waveform, instruction.waveform)
     self.assertEqual(expected_waveform, waveform)
Пример #13
0
    def test_validate_input_errors(self):
        with self.assertRaises(ValueError):
            TableWaveform._validate_input(
                [TableWaveformEntry(0.0, 0.2, HoldInterpolationStrategy())])

        with self.assertRaises(ValueError):
            TableWaveform._validate_input([
                TableWaveformEntry(0.0, 0.2, HoldInterpolationStrategy()),
                TableWaveformEntry(0.0, 0.3, HoldInterpolationStrategy())
            ])

        with self.assertRaises(ValueError):
            TableWaveform._validate_input([
                TableWaveformEntry(0.1, 0.2, HoldInterpolationStrategy()),
                TableWaveformEntry(0.2, 0.2, HoldInterpolationStrategy())
            ])

        with self.assertRaises(ValueError):
            TableWaveform._validate_input([
                TableWaveformEntry(0.0, 0.2, HoldInterpolationStrategy()),
                TableWaveformEntry(0.2, 0.2, HoldInterpolationStrategy()),
                TableWaveformEntry(0.1, 0.2, HoldInterpolationStrategy())
            ])
Пример #14
0
 def test_duration_no_entries_exception(self) -> None:
     with self.assertRaises(ValueError):
         waveform = TableWaveform('A', [])
         self.assertEqual(0, waveform.duration)
Пример #15
0
 def test_few_entries(self) -> None:
     with self.assertRaises(ValueError):
         TableWaveform('A', [[]])
     with self.assertRaises(ValueError):
         TableWaveform(
             'A', [TableWaveformEntry(0, 0, HoldInterpolationStrategy())])
Пример #16
0
    def test_few_entries_multi(self) -> None:
        with self.assertRaises(ValueError):
            TableWaveform([[],[WaveformTableEntry(0, 0, HoldInterpolationStrategy())]])

        with self.assertRaises(ValueError):
            TableWaveform([[WaveformTableEntry(0, 0, HoldInterpolationStrategy())],[]])
Пример #17
0
 def test_duration_no_entries(self) -> None:
     waveform = TableWaveform([])
     self.assertEqual(0, waveform.duration)