Exemple #1
0
    def test_replace_instruction(self):
        """Test replacement of simple instruction"""
        old = Play(Constant(100, 1.0), DriveChannel(0))
        new = Play(Constant(100, 0.1), DriveChannel(0))

        sched = Schedule(old)
        new_sched = sched.replace(old, new)

        self.assertEqual(new_sched, Schedule(new))

        # test replace inplace
        sched.replace(old, new, inplace=True)
        self.assertEqual(sched, Schedule(new))
Exemple #2
0
    def test_scheduling_with_calibration(self):
        """Test if calibrated instruction can update node duration."""
        qc = QuantumCircuit(2)
        qc.x(0)
        qc.cx(0, 1)
        qc.x(1)
        qc.cx(0, 1)

        xsched = Schedule(Play(Constant(300, 0.1), DriveChannel(0)))
        qc.add_calibration("x", (0, ), xsched)

        durations = InstructionDurations([("x", None, 160), ("cx", None, 600)])
        pm = PassManager([ASAPScheduleAnalysis(durations), PadDelay()])
        scheduled = pm.run(qc)

        expected = QuantumCircuit(2)
        expected.x(0)
        expected.delay(300, 1)
        expected.cx(0, 1)
        expected.x(1)
        expected.delay(160, 0)
        expected.cx(0, 1)
        expected.add_calibration("x", (0, ), xsched)

        self.assertEqual(expected, scheduled)
    def test_parametric_pulses_with_no_duplicates(self):
        """Test parametric pulses with no duplicates."""
        schedule = Schedule()
        drive_channel = DriveChannel(0)
        schedule += Play(Gaussian(duration=25, sigma=4, amp=0.5j), drive_channel)
        schedule += Play(Gaussian(duration=25, sigma=4, amp=0.49j), drive_channel)
        schedule += Play(GaussianSquare(duration=150, amp=0.2, sigma=8, width=140), drive_channel)
        schedule += Play(GaussianSquare(duration=150, amp=0.19, sigma=8, width=140), drive_channel)
        schedule += Play(Constant(duration=150, amp=0.1 + 0.4j), drive_channel)
        schedule += Play(Constant(duration=150, amp=0.1 + 0.41j), drive_channel)
        schedule += Play(Drag(duration=25, amp=0.2 + 0.3j, sigma=7.8, beta=4), drive_channel)
        schedule += Play(Drag(duration=25, amp=0.2 + 0.31j, sigma=7.8, beta=4), drive_channel)

        compressed_schedule = transforms.compress_pulses([schedule])
        original_pulse_ids = get_pulse_ids([schedule])
        compressed_pulse_ids = get_pulse_ids(compressed_schedule)
        self.assertEqual(len(original_pulse_ids), len(compressed_pulse_ids))
 def test_parametric_commands_in_sched(self):
     """Test that schedules can be built with parametric commands."""
     sched = Schedule(name='test_parametric')
     sched += Play(Gaussian(duration=25, sigma=4, amp=0.5j), DriveChannel(0))
     sched += Play(Drag(duration=25, amp=0.2+0.3j, sigma=7.8, beta=4), DriveChannel(1))
     sched += Play(Constant(duration=25, amp=1), DriveChannel(2))
     sched_duration = sched.duration
     sched += Play(GaussianSquare(duration=1500, amp=0.2,
                                  sigma=8, width=140),
                   MeasureChannel(0)) << sched_duration
     self.assertEqual(sched.duration, 1525)
     self.assertTrue('sigma' in sched.instructions[0][1].pulse.parameters)
    def test_shift_frequency(self):
        """Test that the frequency is properly taken into account."""

        sched = Schedule()
        sched += ShiftFrequency(1.0, DriveChannel(0))
        sched += Play(Constant(duration=10, amp=1.0), DriveChannel(0))

        converter = InstructionToSignals(dt=0.222, carriers=[5.0])
        signals = converter.get_signals(sched)

        for idx in range(10):
            self.assertEqual(signals[0].samples[idx],
                             np.exp(2.0j * idx * np.pi * 1.0 * 0.222))
def generate_calibrated_circuits():
    """Test for QPY serialization with calibrations."""
    from qiskit.pulse import builder, Constant, DriveChannel

    circuits = []

    # custom gate
    mygate = Gate("mygate", 1, [])
    qc = QuantumCircuit(1)
    qc.append(mygate, [0])
    with builder.build() as caldef:
        builder.play(Constant(100, 0.1), DriveChannel(0))
    qc.add_calibration(mygate, (0, ), caldef)
    circuits.append(qc)
    # override instruction
    qc = QuantumCircuit(1)
    qc.x(0)
    with builder.build() as caldef:
        builder.play(Constant(100, 0.1), DriveChannel(0))
    qc.add_calibration("x", (0, ), caldef)
    circuits.append(qc)

    return circuits
    def test_partially_bound_callable(self):
        """Test register partial function."""
        import functools

        def callable_schedule(par_b, par_a):
            sched = Schedule()
            sched.insert(10,
                         Play(Constant(10, par_b), DriveChannel(0)),
                         inplace=True)
            sched.insert(20,
                         Play(Constant(10, par_a), DriveChannel(0)),
                         inplace=True)
            return sched

        ref_sched = Schedule()
        ref_sched.insert(10,
                         Play(Constant(10, 0.1), DriveChannel(0)),
                         inplace=True)
        ref_sched.insert(20,
                         Play(Constant(10, 0.2), DriveChannel(0)),
                         inplace=True)

        inst_map = InstructionScheduleMap()

        def test_callable_sched1(par_b):
            return callable_schedule(par_b, 0.2)

        inst_map.add("my_gate1", (0, ), test_callable_sched1, ["par_b"])
        ret_sched = inst_map.get("my_gate1", (0, ), par_b=0.1)
        self.assertEqual(ret_sched, ref_sched)

        # bind partially
        test_callable_sched2 = functools.partial(callable_schedule, par_a=0.2)

        inst_map.add("my_gate2", (0, ), test_callable_sched2, ["par_b"])
        ret_sched = inst_map.get("my_gate2", (0, ), par_b=0.1)
        self.assertEqual(ret_sched, ref_sched)
    def test_uneven_pulse_length(self):
        """Test conversion when length of pulses on a schedule is uneven."""

        schedule = Schedule()
        schedule |= Play(Waveform(np.ones(10)), DriveChannel(0))
        schedule += Play(Constant(20, 1), DriveChannel(1))

        converter = InstructionToSignals(dt=0.1, carriers=[2.0, 3.0])

        signals = converter.get_signals(schedule)

        self.assertTrue(signals[0].duration == 20)
        self.assertTrue(signals[1].duration == 20)

        self.assertAllClose(signals[0]._samples,
                            np.append(np.ones(10), np.zeros(10)))
        self.assertAllClose(signals[1]._samples, np.ones(20))

        self.assertTrue(signals[0].carrier_freq == 2.0)
        self.assertTrue(signals[1].carrier_freq == 3.0)
Exemple #9
0
 def test_numpy_integer_input(self):
     """Test that mixed integer duration types can build a schedule (#5754)."""
     sched = Schedule()
     sched += Delay(np.int32(25), DriveChannel(0))
     sched += Play(Constant(duration=30, amp=0.1), DriveChannel(0))
     self.assertEqual(sched.duration, 55)
 def callable_schedule(par_b, par_a):
     sched = Schedule()
     sched.insert(10, Play(Constant(10, par_b), DriveChannel(0)), inplace=True)
     sched.insert(20, Play(Constant(10, par_a), DriveChannel(0)), inplace=True)
     return sched