Пример #1
0
    def test_schedule_generator_supports_parameter_expressions(self):
        """Test expression-based schedule generator functionalty."""

        t_param = Parameter('t')
        amp = 1.0

        def test_func(dur: ParameterExpression, t_val: int):
            dur_bound = dur.bind({t_param: t_val})
            sched = Schedule()
            sched += Play(library.constant(int(float(dur_bound)), amp),
                          DriveChannel(0))
            return sched

        expected_sched = Schedule()
        expected_sched += Play(library.constant(10, amp), DriveChannel(0))

        inst_map = InstructionScheduleMap()
        inst_map.add('f', (0, ), test_func)
        self.assertEqual(inst_map.get('f', (0, ), dur=2 * t_param, t_val=5),
                         expected_sched)

        self.assertEqual(inst_map.get_parameters('f', (0, )), (
            'dur',
            't_val',
        ))
Пример #2
0
 def test_constant(self):
     """Test discrete sampled constant pulse."""
     amp = 0.5j
     duration = 10
     times = np.arange(0, duration) + 0.5  # to match default midpoint sampling strategy
     constant_ref = continuous.constant(times, amp=amp)
     constant_pulse = library.constant(duration, amp=amp)
     self.assertIsInstance(constant_pulse, Waveform)
     np.testing.assert_array_almost_equal(constant_pulse.samples, constant_ref)
Пример #3
0
    def test_schedule_generator(self):
        """Test schedule generator functionalty."""

        x_test = 10
        amp_test = 1.0

        def test_func(x):
            sched = Schedule()
            sched += Play(library.constant(int(x), amp_test), DriveChannel(0))
            return sched

        ref_sched = Schedule()
        ref_sched += Play(library.constant(x_test, amp_test), DriveChannel(0))

        inst_map = InstructionScheduleMap()
        inst_map.add('f', (0,), test_func)
        self.assertEqual(inst_map.get('f', (0,), x_test), ref_sched)

        self.assertEqual(inst_map.get_parameters('f', (0,)), ('x',))
Пример #4
0
    def test_schedule_generator(self):
        """Test schedule generator functionalty."""

        dur_val = 10
        amp = 1.0

        def test_func(dur: int):
            sched = Schedule()
            sched += Play(library.constant(int(dur), amp), DriveChannel(0))
            return sched

        expected_sched = Schedule()
        expected_sched += Play(library.constant(dur_val, amp), DriveChannel(0))

        inst_map = InstructionScheduleMap()
        inst_map.add('f', (0, ), test_func)
        self.assertEqual(inst_map.get('f', (0, ), dur_val), expected_sched)

        self.assertEqual(inst_map.get_parameters('f', (0, )), ('dur', ))
Пример #5
0
 def test_func(x):
     sched = Schedule()
     sched += Play(library.constant(int(x), amp_test), DriveChannel(0))
     return sched
Пример #6
0
 def test_func(dur: ParameterExpression, t_val: int):
     dur_bound = dur.bind({t_param: t_val})
     sched = Schedule()
     sched += Play(library.constant(int(float(dur_bound)), amp),
                   DriveChannel(0))
     return sched
Пример #7
0
 def test_func(dur: int):
     sched = Schedule()
     sched += Play(library.constant(int(dur), amp), DriveChannel(0))
     return sched