Example #1
0
    def test_parametric_pulse_circuit_calibrations(self):
        """Test that disassembler parses parametric pulses back to pulse gates."""
        with pulse.build() as h_sched:
            pulse.play(pulse.library.Drag(50, 0.15, 4, 2), pulse.DriveChannel(0))

        qc = QuantumCircuit(2)
        qc.h(0)
        qc.add_calibration("h", [0], h_sched)

        backend = FakeOpenPulse2Q()
        backend.configuration().parametric_pulses = ["drag"]

        qobj = assemble(qc, backend)
        output_circuits, _, _ = disassemble(qobj)
        out_qc = output_circuits[0]

        self.assertCircuitCalibrationsEqual([qc], output_circuits)
        self.assertTrue(
            all(
                qc_sched.instructions == out_qc_sched.instructions
                for (_, qc_gate), (_, out_qc_gate) in zip(
                    qc.calibrations.items(), out_qc.calibrations.items()
                )
                for qc_sched, out_qc_sched in zip(qc_gate.values(), out_qc_gate.values())
            ),
        )
    def test_single_and_deprecated_acquire_styles(self):
        """Test that acquires are identically combined with Acquires that take a single channel."""
        backend = FakeOpenPulse2Q()
        new_style_schedule = Schedule()
        acq_dur = 1200
        for i in range(5):
            new_style_schedule += Acquire(acq_dur, AcquireChannel(i),
                                          MemorySlot(i))

        deprecated_style_schedule = Schedule()
        with self.assertWarns(DeprecationWarning):
            deprecated_style_schedule += Acquire(1200)(
                [AcquireChannel(i) for i in range(5)],
                [MemorySlot(i) for i in range(5)])

        # The Qobj IDs will be different
        n_qobj = assemble(new_style_schedule, backend)
        n_qobj.qobj_id = None
        n_qobj.experiments[0].header.name = None
        d_qobj = assemble(deprecated_style_schedule, backend)
        d_qobj.qobj_id = None
        d_qobj.experiments[0].header.name = None
        self.assertEqual(n_qobj, d_qobj)

        assembled_acquire = n_qobj.experiments[0].instructions[0]
        self.assertEqual(assembled_acquire.qubits, [0, 1, 2, 3, 4])
        self.assertEqual(assembled_acquire.memory_slot, [0, 1, 2, 3, 4])
Example #3
0
    def test_single_circuit_delay_calibrations(self):
        """Test that disassembler parses delay instruction back to delay gate."""
        qc = QuantumCircuit(2)
        qc.append(Gate("test", 1, []), [0])
        test_sched = pulse.Delay(64, pulse.DriveChannel(0)) + pulse.Delay(
            160, pulse.DriveChannel(0)
        )

        qc.add_calibration("test", [0], test_sched)

        qobj = assemble(qc, FakeOpenPulse2Q())
        output_circuits, _, _ = disassemble(qobj)

        self.assertEqual(len(qc.calibrations), len(output_circuits[0].calibrations))
        self.assertEqual(qc.calibrations.keys(), output_circuits[0].calibrations.keys())
        self.assertTrue(
            all(
                qc_cal.keys() == out_qc_cal.keys()
                for qc_cal, out_qc_cal in zip(
                    qc.calibrations.values(), output_circuits[0].calibrations.values()
                )
            )
        )
        self.assertEqual(
            qc.calibrations["test"][((0,), ())], output_circuits[0].calibrations["test"][((0,), ())]
        )
 def setUp(self):
     self.backend = FakeOpenPulse2Q()
     self.config = self.backend.configuration()
     self.inst_map = self.backend.defaults().instruction_schedule_map
     self.short_pulse = pulse.SamplePulse(samples=np.array(
         [0.02739068], dtype=np.complex128),
                                          name='p0')
 def setUp(self):
     super().setUp()
     self.backend = FakeOpenPulse2Q()
     self.backend_config = self.backend.configuration()
     self.backend_config.parametric_pulses = [
         "constant", "gaussian", "gaussian_square", "drag"
     ]
Example #6
0
    def setUp(self):
        self.device = pulse.DeviceSpecification.create_from(FakeOpenPulse2Q())

        test_pulse = pulse.SamplePulse(samples=np.array(
            [0.02739068, 0.05, 0.05, 0.05, 0.02739068], dtype=np.complex128),
                                       name='pulse0')
        acquire = pulse.Acquire(5)

        self.schedule = pulse.Schedule(name='fake_experiment')
        self.schedule = self.schedule.insert(
            0, test_pulse(self.device.q[0].drive))
        self.schedule = self.schedule.insert(
            5, acquire(self.device.q, self.device.mem))

        self.user_lo_config_dict = {self.device.q[0].drive: 4.91}
        self.user_lo_config = pulse.LoConfig(self.user_lo_config_dict)

        self.default_qubit_lo_freq = [4.9, 5.0]
        self.default_meas_lo_freq = [6.5, 6.6]

        self.config = {
            'meas_level': 1,
            'memory_slots': 2,
            'memory_slot_size': 100,
            'meas_return': 'avg',
            'rep_time': 100
        }

        self.header = {
            'backend_name': 'FakeOpenPulse2Q',
            'backend_version': '0.0.0'
        }
Example #7
0
    def setUp(self):
        self.backend_config = FakeOpenPulse2Q().configuration()

        test_pulse = pulse.SamplePulse(samples=np.array(
            [0.02739068, 0.05, 0.05, 0.05, 0.02739068], dtype=np.complex128),
                                       name='pulse0')
        acquire = pulse.Acquire(5)

        self.schedule = pulse.Schedule(name='fake_experiment')
        self.schedule = self.schedule.insert(
            0, test_pulse(self.backend_config.drive(0)))
        for i in range(self.backend_config.n_qubits):
            self.schedule = self.schedule.insert(
                5, acquire(self.backend_config.acquire(i), MemorySlot(i)))

        self.user_lo_config_dict = {self.backend_config.drive(0): 4.91e9}
        self.user_lo_config = pulse.LoConfig(self.user_lo_config_dict)

        self.default_qubit_lo_freq = [4.9e9, 5.0e9]
        self.default_meas_lo_freq = [6.5e9, 6.6e9]

        self.config = {
            'meas_level': 1,
            'memory_slot_size': 100,
            'meas_return': 'avg',
            'rep_time': 0.0001,
        }

        self.header = {
            'backend_name': 'FakeOpenPulse2Q',
            'backend_version': '0.0.0'
        }
Example #8
0
 def setUp(self):
     @functional_pulse
     def linear(duration, slope, intercept):
         x = np.linspace(0, duration - 1, duration)
         return slope * x + intercept
     self.linear = linear
     self.config = FakeOpenPulse2Q().configuration()
Example #9
0
 def setUp(self):
     super().setUp()
     self.backend = FakeOpenPulse2Q()
     self.backend_config = self.backend.configuration()
     self.backend_config.parametric_pulses = [
         'constant', 'gaussian', 'gaussian_square', 'drag'
     ]
Example #10
0
    def test_creation_from_backend_with_zero_u_channels(self):
        """Test creation of device specification from backend with u_channels == 0.
        """
        backend = FakeOpenPulse2Q()

        device = DeviceSpecification.create_from(backend)

        self.assertEqual(device.q[0].drive, DriveChannel(0))
Example #11
0
 def setUp(self):
     self.backend = FakeOpenPulse2Q()
     self.device = pulse.PulseChannelSpec.from_backend(self.backend)
     self.config = self.backend.configuration()
     self.cmd_def = self.backend.defaults().build_cmd_def()
     self.short_pulse = pulse.SamplePulse(samples=np.array(
         [0.02739068], dtype=np.complex128),
                                          name='p0')
Example #12
0
    def test_control_channel_labels_from_backend(self):
        """Test correct importing of backend control channel description."""
        backend = FakeOpenPulse2Q()

        system_model = PulseSystemModel.from_backend(backend)
        expected = [{'driven_q': 1, 'freq': '(1+0j)q0'},
                    {'driven_q': 0, 'freq': '(-1+0j)q0 + (1+0j)q1'}]

        self.assertEqual(system_model.control_channel_labels, expected)
Example #13
0
 def setUp(self):
     self.backend = FakeOpenPulse2Q()
     self.device = pulse.DeviceSpecification.create_from(self.backend)
     self.config = self.backend.configuration()
     self.defaults = self.backend.defaults()
     self.cmd_def = CmdDef.from_defaults(self.defaults.cmd_def,
                                         self.defaults.pulse_library)
     self.short_pulse = pulse.SamplePulse(samples=np.array([0.02739068], dtype=np.complex128),
                                          name='p0')
Example #14
0
 def setUp(self):
     self.backend = FakeOpenPulse2Q()
     self.config = self.backend.configuration()
     self.short_pulse = pulse.Waveform(samples=np.array([0.02739068], dtype=np.complex128),
                                       name='p0')
     sched = pulse.Schedule(name='fake_experiment')
     sched = sched.insert(0, Play(self.short_pulse, self.config.drive(0)))
     sched = sched.insert(5, Acquire(5, self.config.acquire(0), MemorySlot(0)))
     sched = sched.insert(5, Acquire(5, self.config.acquire(1), MemorySlot(1)))
     self.sched = sched
    def test_check_user_cals(self):
        """Test if schedules provided by user is distinguishable."""
        instmap = FakeOpenPulse2Q().defaults().instruction_schedule_map

        test_u1 = Schedule()
        test_u1 += ShiftPhase(Parameter("P0"), DriveChannel(0))

        instmap.add("u1", (0, ), test_u1, arguments=["P0"])
        publisher = instmap.get("u1", (0, ), P0=0).metadata["publisher"]

        self.assertEqual(publisher, CalibrationPublisher.QISKIT)
 def setUp(self):
     self.backend = FakeOpenPulse2Q()
     self.config = self.backend.configuration()
     self.cmd_def = self.backend.defaults().circuit_instruction_map
     self.short_pulse = pulse.SamplePulse(samples=np.array([0.02739068], dtype=np.complex128),
                                          name='p0')
     acquire = pulse.Acquire(5)
     sched = pulse.Schedule(name='fake_experiment')
     sched = sched.insert(0, self.short_pulse(self.config.drive(0)))
     self.sched = sched.insert(5, acquire([self.config.acquire(0), self.config.acquire(1)],
                                          [MemorySlot(0), MemorySlot(1)]))
    def test_has_custom_gate(self):
        """Test method to check custom gate."""
        backend = FakeOpenPulse2Q()
        instmap = backend.defaults().instruction_schedule_map

        self.assertFalse(instmap.has_custom_gate())

        # add something
        some_sched = Schedule()
        instmap.add("u3", (0, ), some_sched)

        self.assertTrue(instmap.has_custom_gate())
 def test_has_from_mock(self):
     """Test `has` and `assert_has` from mock data."""
     inst_map = FakeOpenPulse2Q().defaults().instruction_schedule_map
     self.assertTrue(inst_map.has("u1", [0]))
     self.assertTrue(inst_map.has("cx", (0, 1)))
     self.assertTrue(inst_map.has("u3", 0))
     self.assertTrue(inst_map.has("measure", [0, 1]))
     self.assertFalse(inst_map.has("u1", [0, 1]))
     with self.assertRaises(PulseError):
         inst_map.assert_has("dne", [0])
     with self.assertRaises(PulseError):
         inst_map.assert_has("cx", 100)
    def test_assemble_with_delay(self):
        """Test that delay instruction is ignored in assembly."""
        backend = FakeOpenPulse2Q()

        orig_schedule = self.schedule
        delay_schedule = orig_schedule + pulse.Delay(10)(self.device.drives[0])

        orig_qobj = assemble(orig_schedule, backend)
        delay_qobj = assemble(delay_schedule, backend)

        self.assertEqual(orig_qobj.experiments[0].to_dict(),
                         delay_qobj.experiments[0].to_dict())
Example #20
0
 def test_has_from_mock_gate(self):
     """Test `has` and `assert_has` from mock data."""
     inst_map = FakeOpenPulse2Q().defaults().instruction_schedule_map
     self.assertTrue(inst_map.has(U1Gate(0), [0]))
     self.assertTrue(inst_map.has(CXGate(), (0, 1)))
     self.assertTrue(inst_map.has(U3Gate(0, 0, 0), 0))
     self.assertTrue(inst_map.has('measure', [0, 1]))
     self.assertFalse(inst_map.has(U1Gate(0), [0, 1]))
     with self.assertRaises(PulseError):
         inst_map.assert_has('dne', [0])
     with self.assertRaises(PulseError):
         inst_map.assert_has(CXGate(), 100)
Example #21
0
 def test_has_from_mock(self):
     """Test `has` and `assert_has` from mock data."""
     inst_map = FakeOpenPulse2Q().defaults().circuit_instruction_map
     self.assertTrue(inst_map.has('u1', [0]))
     self.assertTrue(inst_map.has('cx', (0, 1)))
     self.assertTrue(inst_map.has('u3', 0))
     self.assertTrue(inst_map.has('measure', [0, 1]))
     self.assertFalse(inst_map.has('u1', [0, 1]))
     with self.assertRaises(PulseError):
         inst_map.assert_has('dne', [0])
     with self.assertRaises(PulseError):
         inst_map.assert_has('cx', 100)
Example #22
0
    def test_creation_from_backend_with_zero_u_channels(self):
        """Test creation of device specification from backend with u_channels == 0.
        """
        backend = FakeOpenPulse2Q()

        # overwrite n_uchannel
        backend._configuration.n_uchannels = 0

        device = DeviceSpecification.create_from(backend)

        self.assertEqual(device.q[0].drive, DriveChannel(0, 4.9, (4.5, 5.5)))
        with self.assertRaises(PulseError):
            device.q[0].control()
    def test_creation_from_backend_with_zero_u_channels(self):
        """Test creation of device specification from backend.
        """
        backend = FakeOpenPulse2Q()

        device = PulseChannelSpec.from_backend(backend)

        self.assertEqual(device.drives[0], DriveChannel(0))
        self.assertEqual(device.controls[0], ControlChannel(0))
        self.assertEqual(device.measures[0], MeasureChannel(0))
        self.assertEqual(device.acquires[0], AcquireChannel(0))
        self.assertEqual(device.registers[0], RegisterSlot(0))
        self.assertEqual(device.memoryslots[0], MemorySlot(0))
Example #24
0
 def setUp(self):
     self.backend = FakeOpenPulse2Q()
     self.device = pulse.PulseChannelSpec.from_backend(self.backend)
     self.config = self.backend.configuration()
     self.defaults = self.backend.defaults()
     self.cmd_def = CmdDef.from_defaults(self.defaults.cmd_def,
                                         self.defaults.pulse_library)
     self.short_pulse = pulse.SamplePulse(samples=np.array([0.02739068], dtype=np.complex128),
                                          name='p0')
     acquire = pulse.Acquire(5)
     sched = pulse.Schedule(name='fake_experiment')
     sched = sched.insert(0, self.short_pulse(self.device.drives[0]))
     self.sched = sched.insert(5, acquire(self.device.acquires, self.device.memoryslots))
Example #25
0
 def setUp(self):
     self.backend = FakeOpenPulse2Q()
     self.device = pulse.DeviceSpecification.create_from(self.backend)
     self.config = self.backend.configuration()
     self.defaults = self.backend.defaults()
     self.cmd_def = CmdDef.from_defaults(self.defaults.cmd_def,
                                         self.defaults.pulse_library)
     self.short_pulse = pulse.SamplePulse(samples=np.array([0.02739068], dtype=np.complex128),
                                          name='p0')
     acquire = pulse.Acquire(5)
     sched = pulse.Schedule(name='fake_experiment')
     sched = sched.insert(0, self.short_pulse(self.device.q[0].drive))
     self.sched = sched.insert(5, acquire(self.device.q, self.device.mem))
Example #26
0
    def __init__(self, *args, **kwargs):
        """
        Init the test cal simulator
        """

        unittest.TestCase.__init__(self, *args, **kwargs)

        backend_fake = FakeOpenPulse2Q()

        back_defaults = backend_fake.defaults()
        self.meas_map = backend_fake.configuration().meas_map
        self.system = pulse.PulseChannelSpec.from_backend(backend_fake)
        self.cmd_def = pulse.CmdDef.from_defaults(back_defaults.cmd_def,
                                                  back_defaults.pulse_library)
Example #27
0
    def test_assemble_with_delay(self):
        """Test that delay instruction is ignored in assembly."""
        backend = FakeOpenPulse2Q()

        orig_schedule = self.schedule
        delay_schedule = orig_schedule + pulse.Delay(10)(self.backend_config.drive(0))

        orig_qobj = assemble(orig_schedule, backend)
        validate_qobj_against_schema(orig_qobj)
        delay_qobj = assemble(delay_schedule, backend)
        validate_qobj_against_schema(delay_qobj)

        self.assertEqual(orig_qobj.experiments[0].to_dict(),
                         delay_qobj.experiments[0].to_dict())
Example #28
0
    def __init__(self, *args, **kwargs):
        """
        Init the test cal simulator
        """

        unittest.TestCase.__init__(self, *args, **kwargs)

        backend_fake = FakeOpenPulse2Q()

        self.config = backend_fake.configuration()
        self.meas_map = self.config.meas_map
        self.n_qubits = self.config.n_qubits
        back_defaults = backend_fake.defaults()
        self.inst_map = back_defaults.instruction_schedule_map
    def setUp(self):
        self.schedule = pulse.Schedule(name='fake_experiment')
        self.schedule += pulse.FrameChange(0.)(pulse.DriveChannel(0))

        self.backend = FakeOpenPulse2Q()
        self.config = self.backend.configuration()
        self.defaults = self.backend.defaults()
        self.qubit_lo_freq = self.defaults.qubit_freq_est
        self.meas_lo_freq = self.defaults.meas_freq_est
        self.qubit_lo_range = self.config.qubit_lo_range
        self.meas_lo_range = self.config.meas_lo_range
        self.schedule_los = {pulse.DriveChannel(0): self.qubit_lo_freq[0],
                             pulse.DriveChannel(1): self.qubit_lo_freq[1],
                             pulse.MeasureChannel(0): self.meas_lo_freq[0],
                             pulse.MeasureChannel(1): self.meas_lo_freq[1]}
        self.meas_map = self.config.meas_map
        self.memory_slots = self.config.n_qubits
        self.rep_time = self.config.rep_times[0]
 def test_unsupported_meas_level(self):
     """Test that assembly raises an error if meas_level is not supported"""
     # pylint: disable=unused-variable
     backend = FakeOpenPulse2Q()
     backend.configuration().meas_levels = [1, 2]
     with self.assertRaises(SchemaValidationError):
         assemble(self.schedule,
                  backend,
                  qubit_lo_freq=self.qubit_lo_freq,
                  meas_lo_freq=self.meas_lo_freq,
                  qubit_lo_range=self.qubit_lo_range,
                  meas_lo_range=self.meas_lo_range,
                  schedule_los=self.schedule_los,
                  meas_level=0,
                  meas_map=self.meas_map,
                  memory_slots=self.memory_slots,
                  rep_time=self.rep_time,
                  rep_delay=self.rep_delay)