def setUp(self):
     super().setUp()
     self.backend = FakeOpenPulse2Q()
     self.backend_config = self.backend.configuration()
     self.backend_config.parametric_pulses = [
         "constant", "gaussian", "gaussian_square", "drag"
     ]
Ejemplo n.º 2
0
 def setUp(self):
     super().setUp()
     self.backend = FakeOpenPulse2Q()
     self.config = self.backend.configuration()
     self.inst_map = self.backend.defaults().instruction_schedule_map
     self.short_pulse = pulse.Waveform(
         samples=np.array([0.02739068], dtype=np.complex128), name="p0"
     )
Ejemplo n.º 3
0
    def setUp(self):
        super().setUp()

        @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()
Ejemplo n.º 4
0
 def setup(self, unique_pulses, channels):
     self.parametric_sched = build_parametric_pulse_schedule(
         unique_pulses, channels)
     qr = QuantumRegister(1)
     self.qc = QuantumCircuit(qr)
     self.qc.append(Gate('my_pulse', 1, []), qargs=[qr[0]])
     self.backend = FakeOpenPulse2Q()
     self.inst_map = self.backend.defaults().instruction_schedule_map
     self.add_inst_map = self.inst_map
     self.add_inst_map.add('my_pulse', [0], self.parametric_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)
Ejemplo n.º 6
0
 def setUp(self):
     super().setUp()
     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_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_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)
    def test_multi_circuit_uncommon_calibrations(self):
        """Test that disassembler parses uncommon calibrations (stored at QOBJ experiment-level)."""
        with pulse.build() as sched:
            pulse.play(pulse.library.Drag(50, 0.15, 4, 2),
                       pulse.DriveChannel(0))

        qc_0 = QuantumCircuit(2)
        qc_0.h(0)
        qc_0.append(RXGate(np.pi), [1])
        qc_0.add_calibration("h", [0], sched)
        qc_0.add_calibration(RXGate(np.pi), [1], sched)

        qc_1 = QuantumCircuit(2)
        qc_1.h(0)

        circuits = [qc_0, qc_1]
        qobj = assemble(circuits, FakeOpenPulse2Q())
        output_circuits, _, _ = disassemble(qobj)

        self.assertCircuitCalibrationsEqual(circuits, output_circuits)
Ejemplo n.º 10
0
    def setUp(self):
        super().setUp()

        self.backend = FakeOpenPulse2Q()

        self.test_waveform0 = pulse.Constant(100, 0.1)
        self.test_waveform1 = pulse.Constant(200, 0.1)

        self.d0 = pulse.DriveChannel(0)
        self.d1 = pulse.DriveChannel(1)

        self.left_context = transforms.AlignLeft()
        self.right_context = transforms.AlignRight()
        self.sequential_context = transforms.AlignSequential()
        self.equispaced_context = transforms.AlignEquispaced(duration=1000)

        def _align_func(j):
            return {1: 0.1, 2: 0.25, 3: 0.7, 4: 0.85}.get(j)

        self.func_context = transforms.AlignFunc(duration=1000,
                                                 func=_align_func)
Ejemplo n.º 11
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, ), ())])
Ejemplo n.º 12
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())), )
Ejemplo n.º 13
0
    def test_single_circuit_calibrations(self):
        """Test that disassembler parses single circuit QOBJ calibrations (from QOBJ-level)."""
        theta = Parameter("theta")
        qc = QuantumCircuit(2)
        qc.h(0)
        qc.rx(np.pi, 0)
        qc.rx(theta, 1)
        qc = qc.assign_parameters({theta: np.pi})

        with pulse.build() as h_sched:
            pulse.play(pulse.library.Drag(1, 0.15, 4, 2),
                       pulse.DriveChannel(0))

        with pulse.build() as x180:
            pulse.play(pulse.library.Gaussian(1, 0.2, 5),
                       pulse.DriveChannel(0))

        qc.add_calibration("h", [0], h_sched)
        qc.add_calibration(RXGate(np.pi), [0], x180)

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

        self.assertCircuitCalibrationsEqual([qc], output_circuits)
Ejemplo n.º 14
0
 def setUp(self):
     super().setUp()
     self.backend = FakeOpenPulse2Q()
     self.configuration = self.backend.configuration()
     self.defaults = self.backend.defaults()
     self.inst_map = self.defaults.instruction_schedule_map
Ejemplo n.º 15
0
 def setUp(self):
     super().setUp()
     self.defs = FakeOpenPulse2Q().defaults()
     self.inst_map = self.defs.instruction_schedule_map
    def test_check_backend_provider_cals(self):
        """Test if schedules provided by backend provider is distinguishable."""
        instmap = FakeOpenPulse2Q().defaults().instruction_schedule_map
        publisher = instmap.get("u1", (0,), P0=0).metadata["publisher"]

        self.assertEqual(publisher, CalibrationPublisher.BACKEND_PROVIDER)