def test_default(self):
        """Test default snapshot."""
        snapshot = Snapshot(label='test_name', snapshot_type='state')

        self.assertEqual(snapshot.name, "test_name")
        self.assertEqual(snapshot.type, "state")
        self.assertEqual(snapshot.duration, 0)
예제 #2
0
    def test_name_inherited(self):
        """Test that schedule keeps name if an instruction is added."""
        gp0 = pulse_lib.gaussian(duration=100,
                                 amp=0.7,
                                 sigma=3,
                                 name='pulse_name')
        with self.assertWarns(DeprecationWarning):
            pv0 = PersistentValue(0.1)
        snapshot = Snapshot('snapshot_label', 'state')

        sched1 = Schedule(name='test_name')
        sched2 = Schedule(name=None)
        sched3 = sched1 | sched2
        self.assertEqual(sched3.name, 'test_name')

        sched_acq = Acquire(
            10, self.config.acquire(1), MemorySlot(1),
            name='acq_name') | sched1
        self.assertEqual(sched_acq.name, 'acq_name')

        sched_pulse = Play(gp0, self.config.drive(0)) | sched1
        self.assertEqual(sched_pulse.name, 'pulse_name')

        with self.assertWarns(DeprecationWarning):
            sched_pv = pv0(self.config.drive(0), name='pv_name') | sched1
        self.assertEqual(sched_pv.name, 'pv_name')

        sched_fc = ShiftPhase(0.1, self.config.drive(0),
                              name='fc_name') | sched1
        self.assertEqual(sched_fc.name, 'fc_name')

        sched_snapshot = snapshot | sched1
        self.assertEqual(sched_snapshot.name, 'snapshot_label')
예제 #3
0
    def test_can_create_valid_schedule(self):
        """Test valid schedule creation without error."""
        gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3)
        gp1 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3)

        sched = Schedule()
        sched = sched.append(Play(gp0, self.config.drive(0)))
        with self.assertWarns(DeprecationWarning):
            sched = sched.insert(
                0,
                PersistentValue(value=0.2 + 0.4j)(self.config.control([0,
                                                                       1])[0]))
        sched = sched.insert(60, ShiftPhase(-1.57, self.config.drive(0)))
        sched = sched.insert(30, Play(gp1, self.config.drive(0)))
        sched = sched.insert(60, Play(gp0, self.config.control([0, 1])[0]))
        sched = sched.insert(80, Snapshot("label", "snap_type"))
        sched = sched.insert(90, ShiftPhase(1.57, self.config.drive(0)))
        sched = sched.insert(
            90,
            Acquire(10, self.config.acquire(0), MemorySlot(0),
                    RegisterSlot(0)))  # TODO: this shouldn't raise a warning
        self.assertEqual(0, sched.start_time)
        self.assertEqual(100, sched.stop_time)
        self.assertEqual(100, sched.duration)
        new_sched = Schedule()
        new_sched = new_sched.append(sched)
        new_sched = new_sched.append(sched)
        self.assertEqual(0, new_sched.start_time)
        self.assertEqual(200, new_sched.stop_time)
        self.assertEqual(200, new_sched.duration)
        ids = set()
        for _, inst in sched.instructions:
            self.assertFalse(inst.id in ids)
            ids.add(inst.id)
예제 #4
0
    def test_can_create_valid_schedule(self):
        """Test valid schedule creation without error."""
        gp0 = library.gaussian(duration=20, amp=0.7, sigma=3)
        gp1 = library.gaussian(duration=20, amp=0.7, sigma=3)

        sched = Schedule()
        sched = sched.append(Play(gp0, self.config.drive(0)))
        sched = sched.insert(60, ShiftPhase(-1.57, self.config.drive(0)))
        sched = sched.insert(30, Play(gp1, self.config.drive(0)))
        sched = sched.insert(60, Play(gp0, self.config.control([0, 1])[0]))
        sched = sched.insert(80, Snapshot("label", "snap_type"))
        sched = sched.insert(90, ShiftPhase(1.57, self.config.drive(0)))
        sched = sched.insert(
            90, Acquire(10, self.config.acquire(0), MemorySlot(0), RegisterSlot(0))
        )
        self.assertEqual(0, sched.start_time)
        self.assertEqual(100, sched.stop_time)
        self.assertEqual(100, sched.duration)
        new_sched = Schedule()
        new_sched = new_sched.append(sched)
        new_sched = new_sched.append(sched)
        self.assertEqual(0, new_sched.start_time)
        self.assertEqual(200, new_sched.stop_time)
        self.assertEqual(200, new_sched.duration)
        ids = set()
        for _, inst in sched.instructions:
            self.assertFalse(inst.id in ids)
            ids.add(inst.id)
예제 #5
0
    def test_name_inherited(self):
        """Test that schedule keeps name if an instruction is added."""
        gp0 = library.gaussian(duration=100,
                               amp=0.7,
                               sigma=3,
                               name="pulse_name")
        snapshot = Snapshot("snapshot_label", "state")

        sched1 = Schedule(name="test_name")
        sched2 = Schedule(name=None)
        sched3 = sched1 | sched2
        self.assertEqual(sched3.name, "test_name")

        sched_acq = Acquire(
            10, self.config.acquire(1), MemorySlot(1),
            name="acq_name") | sched1
        self.assertEqual(sched_acq.name, "acq_name")

        sched_pulse = Play(gp0, self.config.drive(0)) | sched1
        self.assertEqual(sched_pulse.name, "pulse_name")

        sched_fc = ShiftPhase(0.1, self.config.drive(0),
                              name="fc_name") | sched1
        self.assertEqual(sched_fc.name, "fc_name")

        sched_snapshot = snapshot | sched1
        self.assertEqual(sched_snapshot.name, "snapshot_label")
예제 #6
0
    def test_default(self):
        """Test default snapshot.
        """
        snap_command = Snapshot(label='test_label', snap_type='state')

        self.assertEqual(snap_command.label, "test_label")
        self.assertEqual(snap_command.type, "state")
        self.assertEqual(snap_command.duration, 0)
예제 #7
0
    def test_default(self):
        """Test default snapshot.
        """
        snap_command = Snapshot(name='test_name', snap_type='state')

        self.assertEqual(snap_command.name, "test_name")
        self.assertEqual(snap_command.type, "state")
        self.assertEqual(snap_command.duration, 0)
예제 #8
0
    def test_default(self):
        """Test default snapshot."""
        snapshot = Snapshot(label='test_name', snapshot_type='state')

        self.assertIsInstance(snapshot.id, int)
        self.assertEqual(snapshot.name, 'test_name')
        self.assertEqual(snapshot.type, 'state')
        self.assertEqual(snapshot.duration, 0)
        self.assertNotEqual(snapshot, Delay(10, DriveChannel(0)))
        self.assertEqual(repr(snapshot), "Snapshot(test_name, state, name='test_name')")
예제 #9
0
    def test_delay_snapshot_channel(self):
        """Test Delay on DriveChannel"""

        snapshot_ch = SnapshotChannel()
        snapshot = Snapshot(label='test')
        # should pass as is an append
        sched = Delay(self.delay_time, snapshot_ch) + snapshot
        self.assertIsInstance(sched, Schedule)
        # should fail due to overlap
        with self.assertRaises(PulseError):
            sched = Delay(self.delay_time, snapshot_ch) | snapshot << 5
            self.assertIsInstance(sched, Schedule)
예제 #10
0
    def test_can_create_valid_schedule_with_syntax_sugar(self):
        """Test that in place operations on schedule are still immutable
        and return equivalent schedules."""
        gp0 = library.gaussian(duration=20, amp=0.7, sigma=3)
        gp1 = library.gaussian(duration=20, amp=0.5, sigma=3)

        sched = Schedule()
        sched += Play(gp0, self.config.drive(0))
        sched |= ShiftPhase(-1.57, self.config.drive(0)) << 60
        sched |= Play(gp1, self.config.drive(0)) << 30
        sched |= Play(gp0, self.config.control(qubits=[0, 1])[0]) << 60
        sched |= Snapshot("label", "snap_type") << 60
        sched |= ShiftPhase(1.57, self.config.drive(0)) << 90
        sched |= Acquire(10, self.config.acquire(0), MemorySlot(0)) << 90
        sched += sched
예제 #11
0
    def test_can_create_valid_schedule_with_syntax_sugar(self):
        """Test that in place operations on schedule are still immutable
           and return equivalent schedules."""
        gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3)
        gp1 = pulse_lib.gaussian(duration=20, amp=0.5, sigma=3)

        sched = Schedule()
        sched += Play(gp0, self.config.drive(0))
        with self.assertWarns(DeprecationWarning):
            sched |= PersistentValue(value=0.2 + 0.4j)(self.config.control(
                [0, 1])[0])
        sched |= ShiftPhase(-1.57, self.config.drive(0)) << 60
        sched |= Play(gp1, self.config.drive(0)) << 30
        sched |= Play(gp0, self.config.control(qubits=[0, 1])[0]) << 60
        sched |= Snapshot("label", "snap_type") << 60
        sched |= ShiftPhase(1.57, self.config.drive(0)) << 90
        sched |= Acquire(10, self.config.acquire(0), MemorySlot(0)) << 90
        sched += sched