def test_pulse_duration(self):
        """Test parametrization of pulse duration."""
        dur = Parameter('dur')

        test_pulse = pulse.Gaussian(dur, 0.1, dur / 4)
        ref_pulse = pulse.Gaussian(160, 0.1, 40)

        self.assertEqual(test_pulse.assign_parameters({dur: 160}), ref_pulse)
    def test_parameter_attribute_play(self):
        """Test the ``parameter`` attributes."""
        inst = pulse.Play(
            pulse.Gaussian(self.dur, self.amp, self.sigma), pulse.DriveChannel(self.qubit)
        )
        self.assertTrue(inst.is_parameterized())
        self.assertSetEqual(inst.parameters, {self.dur, self.amp, self.sigma, self.qubit})

        inst = pulse.Play(pulse.Gaussian(self.dur, 0.1, self.sigma), pulse.DriveChannel(self.qubit))
        self.assertTrue(inst.is_parameterized())
        self.assertSetEqual(inst.parameters, {self.dur, self.sigma, self.qubit})
示例#3
0
    def test_call_initialize_with_parameter(self):
        """Test call instruction with parameterized subroutine with initial dict."""
        init_dict = {self.param1: 0.1, self.param2: 0.5}
        call = instructions.Call(subroutine=self.function,
                                 value_dict=init_dict)

        with pulse.build() as ref_sched:
            pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
            pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(0))
            pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))

        self.assertEqual(call.assigned_subroutine(), ref_sched)
示例#4
0
    def test_set_parameter_to_complex_schedule(self):
        """Test get parameters from complicated schedule."""
        test_block = deepcopy(self.test_sched)

        value_dict = {
            self.amp1_1: 0.1,
            self.amp1_2: 0.2,
            self.amp2: 0.3,
            self.amp3: 0.4,
            self.dur1: 100,
            self.dur2: 125,
            self.dur3: 150,
            self.ch1: 0,
            self.ch2: 2,
            self.ch3: 4,
            self.phi1: 1.0,
            self.phi2: 2.0,
            self.phi3: 3.0,
            self.meas_dur: 300,
            self.mem1: 3,
            self.reg1: 0,
            self.context_dur: 1000,
        }

        visitor = ParameterSetter(param_map=value_dict)
        assigned = visitor.visit(test_block)

        # create ref schedule
        subroutine = pulse.ScheduleBlock(alignment_context=AlignLeft())
        subroutine += pulse.ShiftPhase(1.0, pulse.DriveChannel(0))
        subroutine += pulse.Play(pulse.Gaussian(100, 0.3, 25),
                                 pulse.DriveChannel(0))

        sched = pulse.Schedule()
        sched += pulse.ShiftPhase(3.0, pulse.DriveChannel(4))

        ref_obj = pulse.ScheduleBlock(alignment_context=AlignEquispaced(1000),
                                      name="long_schedule")

        ref_obj += subroutine
        ref_obj += pulse.ShiftPhase(2.0, pulse.DriveChannel(2))
        ref_obj += pulse.Play(pulse.Gaussian(125, 0.3, 25),
                              pulse.DriveChannel(2))
        ref_obj += pulse.Call(sched)
        ref_obj += pulse.Play(pulse.Gaussian(150, 0.4, 25),
                              pulse.DriveChannel(4))

        ref_obj += pulse.Acquire(300, pulse.AcquireChannel(0),
                                 pulse.MemorySlot(3), pulse.RegisterSlot(0))

        self.assertEqual(assigned, ref_obj)
示例#5
0
    def setUp(self):
        super().setUp()

        with pulse.build() as _subroutine:
            pulse.delay(10, pulse.DriveChannel(0))
        self.subroutine = _subroutine

        self.param1 = circuit.Parameter('amp1')
        self.param2 = circuit.Parameter('amp2')
        with pulse.build() as _function:
            pulse.play(pulse.Gaussian(160, self.param1, 40), pulse.DriveChannel(0))
            pulse.play(pulse.Gaussian(160, self.param2, 40), pulse.DriveChannel(0))
            pulse.play(pulse.Gaussian(160, self.param1, 40), pulse.DriveChannel(0))
        self.function = _function
示例#6
0
    def test_assemble_parametric(self):
        """Test that parametric pulses can be assembled properly into a PulseQobj."""
        sched = pulse.Schedule(name='test_parametric')
        sched += Play(pulse.Gaussian(duration=25, sigma=4, amp=0.5j), DriveChannel(0))
        sched += Play(pulse.Drag(duration=25, amp=0.2+0.3j, sigma=7.8, beta=4), DriveChannel(1))
        sched += Play(pulse.Constant(duration=25, amp=1), DriveChannel(2))
        sched += Play(pulse.GaussianSquare(duration=150, amp=0.2,
                                           sigma=8, width=140), MeasureChannel(0)) << sched.duration
        backend = FakeOpenPulse3Q()
        backend.configuration().parametric_pulses = ['gaussian', 'drag',
                                                     'gaussian_square', 'constant']
        qobj = assemble(sched, backend)

        self.assertEqual(qobj.config.pulse_library, [])
        qobj_insts = qobj.experiments[0].instructions
        self.assertTrue(all(inst.name == 'parametric_pulse'
                            for inst in qobj_insts))
        self.assertEqual(qobj_insts[0].pulse_shape, 'gaussian')
        self.assertEqual(qobj_insts[1].pulse_shape, 'drag')
        self.assertEqual(qobj_insts[2].pulse_shape, 'constant')
        self.assertEqual(qobj_insts[3].pulse_shape, 'gaussian_square')
        self.assertDictEqual(qobj_insts[0].parameters, {'duration': 25, 'sigma': 4, 'amp': 0.5j})
        self.assertDictEqual(qobj_insts[1].parameters,
                             {'duration': 25, 'sigma': 7.8, 'amp': 0.2+0.3j, 'beta': 4})
        self.assertDictEqual(qobj_insts[2].parameters, {'duration': 25, 'amp': 1})
        self.assertDictEqual(qobj_insts[3].parameters,
                             {'duration': 150, 'sigma': 8, 'amp': 0.2, 'width': 140})
        self.assertEqual(
            qobj.to_dict()['experiments'][0]['instructions'][0]['parameters']['amp'],
            0.5j)
示例#7
0
    def test_assign_parameters_to_call(self):
        """Test create schedule by calling subroutine and assign parameters to it."""
        init_dict = {self.param1: 0.1, self.param2: 0.5}

        with pulse.build() as test_sched:
            pulse.call(self.function)

        test_sched = test_sched.assign_parameters(value_dict=init_dict)
        test_sched = inline_subroutines(test_sched)

        with pulse.build() as ref_sched:
            pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
            pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(0))
            pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))

        self.assertEqual(test_sched, ref_sched)
    def test_dd_with_calibrations_with_parameters(self, param_value):
        """Check that calibrations in a circuit with parameters work fine."""

        circ = QuantumCircuit(2)
        circ.x(0)
        circ.cx(0, 1)
        circ.rx(param_value, 1)

        rx_duration = int(param_value * 1000)

        with pulse.build() as rx:
            pulse.play(pulse.Gaussian(rx_duration, 0.1, rx_duration // 4),
                       pulse.DriveChannel(1))

        circ.add_calibration("rx", (1, ), rx, params=[param_value])

        durations = InstructionDurations([("x", None, 100), ("cx", None, 300)])

        dd_sequence = [XGate(), XGate()]
        pm = PassManager([
            ALAPScheduleAnalysis(durations),
            PadDynamicalDecoupling(durations, dd_sequence)
        ])

        self.assertEqual(pm.run(circ).duration, rx_duration + 100 + 300)
示例#9
0
    def test_nested_assignment_partial_bind(self):
        """Test nested schedule with call instruction.
        Inline the schedule and partially bind parameters."""
        context = AlignEquispaced(duration=self.context_dur)
        subroutine = pulse.ScheduleBlock(alignment_context=context)
        subroutine += pulse.Play(self.parametric_waveform1, self.d1)

        nested_block = pulse.ScheduleBlock()
        nested_block += pulse.Call(subroutine=subroutine)

        test_obj = pulse.ScheduleBlock()
        test_obj += nested_block

        test_obj = inline_subroutines(test_obj)

        value_dict = {self.context_dur: 1000, self.dur1: 200, self.ch1: 1}

        visitor = ParameterSetter(param_map=value_dict)
        assigned = visitor.visit(test_obj)

        ref_context = AlignEquispaced(duration=1000)
        ref_subroutine = pulse.ScheduleBlock(alignment_context=ref_context)
        ref_subroutine += pulse.Play(
            pulse.Gaussian(200, self.amp1_1 + self.amp1_2, 50),
            pulse.DriveChannel(1))

        ref_nested_block = pulse.ScheduleBlock()
        ref_nested_block += ref_subroutine

        ref_obj = pulse.ScheduleBlock()
        ref_obj += ref_nested_block

        self.assertEqual(assigned, ref_obj)
示例#10
0
    def test_calibrations(self):
        """Test that the calibrations are preserved and that the circuit transpiles."""

        experiments = []
        for qubit in range(3):
            with pulse.build() as sched:
                pulse.play(pulse.Gaussian(160, Parameter("amp"), 40),
                           pulse.DriveChannel(qubit))

            experiments.append(Rabi(qubit, sched, amplitudes=[0.5]))

        par_exp = ParallelExperiment(experiments)
        par_circ = par_exp.circuits()[0]

        # If the calibrations are not there we will not be able to transpile
        try:
            transpile(par_circ, basis_gates=["rz", "sx", "x", "cx"])
        except QiskitError as error:
            self.fail("Failed to transpile with error: " + str(error))

        # Assert that the calibration keys are in the calibrations of the composite circuit.
        for qubit in range(3):
            rabi_circuit = experiments[qubit].circuits()[0]
            cal_key = next(iter(rabi_circuit.calibrations["Rabi"].keys()))

            self.assertEqual(cal_key[0], (qubit, ))
            self.assertTrue(cal_key in par_circ.calibrations["Rabi"])
示例#11
0
    def test_zero_duration_delay(self):
        """Test generating waveforms that contains zero duration delay.

        Zero duration delay should be ignored.
        """
        ch = pulse.DriveChannel(0)

        with pulse.build() as test_sched:
            pulse.play(pulse.Gaussian(160, 0.1, 40), ch)
            pulse.delay(0, ch)
            pulse.play(pulse.Gaussian(160, 0.1, 40), ch)
            pulse.delay(1, ch)
            pulse.play(pulse.Gaussian(160, 0.1, 40), ch)

        ch_events = events.ChannelEvents.load_program(test_sched, ch)

        self.assertEqual(len(list(ch_events.get_waveforms())), 4)
    def test_is_parameterized(self):
        """Test is parameterized method for parameter duration."""
        dur = Parameter('dur')
        ch = pulse.DriveChannel(0)

        test_play = pulse.Play(pulse.Gaussian(dur, 0.1, dur / 4), ch)

        self.assertEqual(test_play.is_parameterized(), True)
示例#13
0
    def test_call_with_common_parameter(self):
        """Test call subroutine with parameter that is defined multiple times."""
        amp = circuit.Parameter('amp')

        with pulse.build() as subroutine:
            pulse.play(pulse.Gaussian(160, amp, 40), pulse.DriveChannel(0))
            pulse.play(pulse.Gaussian(320, amp, 80), pulse.DriveChannel(0))

        with pulse.build() as main_prog:
            pulse.call(subroutine, amp=0.1)

        assigned_sched = inline_subroutines(main_prog)

        play_0 = assigned_sched.instructions[0][1]
        play_1 = assigned_sched.instructions[1][1]

        self.assertEqual(play_0.pulse.amp, 0.1)
        self.assertEqual(play_1.pulse.amp, 0.1)
示例#14
0
    def setUp(self):
        """Setup tests."""
        super().setUp()

        with pulse.build() as sched:
            pulse.play(pulse.Gaussian(160, Parameter("amp"), 40),
                       pulse.DriveChannel(2))

        self.sched = sched
    def test_play_duration(self):
        """Test parametrization of play instruction duration."""
        dur = Parameter('dur')
        ch = pulse.DriveChannel(0)

        test_play = pulse.Play(pulse.Gaussian(dur, 0.1, dur / 4), ch)
        test_play.assign_parameters({dur: 160})

        self.assertEqual(test_play.duration, 160)
示例#16
0
    def test_gen_filled_waveform_stepwise_opaque(self):
        """Test generating waveform with unbound parameter."""
        amp = circuit.Parameter('amp')
        my_pulse = pulse.Gaussian(10, amp, 3, name='my_pulse')
        play = pulse.Play(my_pulse, pulse.DriveChannel(0))
        inst_data = create_instruction(play, np.pi / 2, 5e9, 5, 0.1, True)

        objs = waveform.gen_filled_waveform_stepwise(inst_data,
                                                     formatter=self.formatter,
                                                     device=self.device)

        self.assertEqual(len(objs), 2)

        # type check
        self.assertEqual(type(objs[0]), drawings.BoxData)
        self.assertEqual(type(objs[1]), drawings.TextData)

        x_ref = np.array([5, 15])
        y_ref = np.array([
            -0.5 * self.formatter['box_height.opaque_shape'],
            0.5 * self.formatter['box_height.opaque_shape']
        ])

        # data check
        np.testing.assert_array_equal(objs[0].xvals, x_ref)
        np.testing.assert_array_equal(objs[0].yvals, y_ref)

        # meta data check
        ref_meta = {
            'duration (cycle time)': 10,
            'duration (sec)': 1.0,
            't0 (cycle time)': 5,
            't0 (sec)': 0.5,
            'waveform shape': 'Gaussian',
            'amp': 'amp',
            'sigma': 3,
            'phase': np.pi / 2,
            'frequency': 5e9,
            'qubit': 0,
            'name': 'my_pulse'
        }
        self.assertDictEqual(objs[0].meta, ref_meta)

        # style check
        ref_style = {
            'alpha': self.formatter['alpha.opaque_shape'],
            'zorder': self.formatter['layer.fill_waveform'],
            'linewidth': self.formatter['line_width.opaque_shape'],
            'linestyle': self.formatter['line_style.opaque_shape'],
            'facecolor': self.formatter['color.opaque_shape'][0],
            'edgecolor': self.formatter['color.opaque_shape'][1]
        }
        self.assertDictEqual(objs[0].styles, ref_style)

        # test label
        self.assertEqual(objs[1].text, 'Gaussian(amp)')
示例#17
0
    def test_gen_filled_waveform_stepwise_opaque(self):
        """Test generating waveform with unbound parameter."""
        amp = circuit.Parameter("amp")
        my_pulse = pulse.Gaussian(10, amp, 3, name="my_pulse")
        play = pulse.Play(my_pulse, pulse.DriveChannel(0))
        inst_data = create_instruction(play, np.pi / 2, 5e9, 5, 0.1, True)

        objs = waveform.gen_filled_waveform_stepwise(inst_data,
                                                     formatter=self.formatter,
                                                     device=self.device)

        self.assertEqual(len(objs), 2)

        # type check
        self.assertEqual(type(objs[0]), drawings.BoxData)
        self.assertEqual(type(objs[1]), drawings.TextData)

        x_ref = np.array([5, 15])
        y_ref = np.array([
            -0.5 * self.formatter["box_height.opaque_shape"],
            0.5 * self.formatter["box_height.opaque_shape"],
        ])

        # data check
        np.testing.assert_array_equal(objs[0].xvals, x_ref)
        np.testing.assert_array_equal(objs[0].yvals, y_ref)

        # meta data check
        ref_meta = {
            "duration (cycle time)": 10,
            "duration (sec)": 1.0,
            "t0 (cycle time)": 5,
            "t0 (sec)": 0.5,
            "waveform shape": "Gaussian",
            "amp": "amp",
            "sigma": 3,
            "phase": np.pi / 2,
            "frequency": 5e9,
            "qubit": 0,
            "name": "my_pulse",
        }
        self.assertDictEqual(objs[0].meta, ref_meta)

        # style check
        ref_style = {
            "alpha": self.formatter["alpha.opaque_shape"],
            "zorder": self.formatter["layer.fill_waveform"],
            "linewidth": self.formatter["line_width.opaque_shape"],
            "linestyle": self.formatter["line_style.opaque_shape"],
            "facecolor": self.formatter["color.opaque_shape"][0],
            "edgecolor": self.formatter["color.opaque_shape"][1],
        }
        self.assertDictEqual(objs[0].styles, ref_style)

        # test label
        self.assertEqual(objs[1].text, "Gaussian(amp)")
    def test_cannot_build_schedule(self):
        """Test we cannot build schedule with parameterized instructions"""
        dur = Parameter('dur')
        ch = pulse.DriveChannel(0)

        test_play = pulse.Play(pulse.Gaussian(dur, 0.1, dur / 4), ch)

        sched = pulse.Schedule()
        with self.assertRaises(pulse.exceptions.UnassignedDurationError):
            sched.insert(0, test_play)
示例#19
0
    def test_call_with_not_existing_parameter(self):
        """Test call subroutine with parameter not defined."""
        amp = circuit.Parameter('amp1')

        with pulse.build() as subroutine:
            pulse.play(pulse.Gaussian(160, amp, 40), pulse.DriveChannel(0))

        with self.assertRaises(exceptions.PulseError):
            with pulse.build():
                pulse.call(subroutine, amp=0.1)
示例#20
0
    def test_used_in_calls(self):
        """Test that we can identify schedules by name when calls are present."""

        with pulse.build(name="xp") as xp:
            pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(1))

        with pulse.build(name="xp2") as xp2:
            pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(1))

        with pulse.build(name="call_xp") as xp_call:
            pulse.call(xp)

        with pulse.build(name="call_call_xp") as xp_call_call:
            pulse.play(pulse.Drag(160, 0.5, 40, 0.2), pulse.DriveChannel(1))
            pulse.call(xp_call)

        self.assertSetEqual(used_in_calls("xp", [xp_call]), {"call_xp"})
        self.assertSetEqual(used_in_calls("xp", [xp2]), set())
        self.assertSetEqual(used_in_calls("xp", [xp_call, xp_call_call]),
                            {"call_xp", "call_call_xp"})

        with pulse.build(name="xp") as xp:
            pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(2))

        cr_tone_p = pulse.GaussianSquare(640, 0.2, 64, 500)
        rotary_p = pulse.GaussianSquare(640, 0.1, 64, 500)

        cr_tone_m = pulse.GaussianSquare(640, -0.2, 64, 500)
        rotary_m = pulse.GaussianSquare(640, -0.1, 64, 500)

        with pulse.build(name="cr") as cr:
            with pulse.align_sequential():
                with pulse.align_left():
                    pulse.play(rotary_p, pulse.DriveChannel(3))  # Rotary tone
                    pulse.play(cr_tone_p, pulse.ControlChannel(2))  # CR tone.
                pulse.call(xp)
                with pulse.align_left():
                    pulse.play(rotary_m, pulse.DriveChannel(3))
                    pulse.play(cr_tone_m, pulse.ControlChannel(2))
                pulse.call(xp)

        self.assertSetEqual(used_in_calls("xp", [cr]), {"cr"})
    def test_cx_cz_case(self):
        """Test the case where the coupling map has CX and CZ on different qubits.

        We use FakeBelem which has a linear coupling map and will restrict ourselves to
        qubits 0, 1, and 2. The Cals will define a template schedule for CX and CZ. We will
        mock this with GaussianSquare and Gaussian pulses since the nature of the schedules
        is irrelevant here. The parameters for CX will only have values for qubis 0 and 1 while
        the parameters for CZ will only have values for qubis 1 and 2. We therefore will have
        a CX on qubits 0, 1 in the inst. map and a CZ on qubits 1, 2.
        """

        cals = BackendCalibrations(FakeBelem())

        sig = Parameter("σ")
        dur = Parameter("duration")
        width = Parameter("width")
        amp_cx = Parameter("amp")
        amp_cz = Parameter("amp")
        uchan = Parameter("ch1.0")

        with pulse.build(name="cx") as cx:
            pulse.play(
                pulse.GaussianSquare(duration=dur, amp=amp_cx, sigma=sig, width=width),
                pulse.ControlChannel(uchan),
            )

        with pulse.build(name="cz") as cz:
            pulse.play(
                pulse.Gaussian(duration=dur, amp=amp_cz, sigma=sig), pulse.ControlChannel(uchan)
            )

        cals.add_schedule(cx, num_qubits=2)
        cals.add_schedule(cz, num_qubits=2)

        cals.add_parameter_value(640, "duration", schedule="cx")
        cals.add_parameter_value(64, "σ", schedule="cx")
        cals.add_parameter_value(320, "width", qubits=(0, 1), schedule="cx")
        cals.add_parameter_value(320, "width", qubits=(1, 0), schedule="cx")
        cals.add_parameter_value(0.1, "amp", qubits=(0, 1), schedule="cx")
        cals.add_parameter_value(0.8, "amp", qubits=(1, 0), schedule="cx")
        cals.add_parameter_value(0.1, "amp", qubits=(2, 1), schedule="cz")
        cals.add_parameter_value(0.8, "amp", qubits=(1, 2), schedule="cz")

        # CX only defined for qubits (0, 1) and (1,0)?
        self.assertTrue(cals.default_inst_map.has("cx", (0, 1)))
        self.assertTrue(cals.default_inst_map.has("cx", (1, 0)))
        self.assertFalse(cals.default_inst_map.has("cx", (2, 1)))
        self.assertFalse(cals.default_inst_map.has("cx", (1, 2)))

        # CZ only defined for qubits (2, 1) and (1,2)?
        self.assertTrue(cals.default_inst_map.has("cz", (2, 1)))
        self.assertTrue(cals.default_inst_map.has("cz", (1, 2)))
        self.assertFalse(cals.default_inst_map.has("cz", (0, 1)))
        self.assertFalse(cals.default_inst_map.has("cz", (1, 0)))
示例#22
0
    def test_set_parameter_to_pulse(self):
        """Test get parameters from pulse instruction."""
        test_obj = self.parametric_waveform1

        value_dict = {self.amp1_1: 0.1, self.amp1_2: 0.2, self.dur1: 160}

        visitor = ParameterSetter(param_map=value_dict)
        assigned = visitor.visit(test_obj)

        ref_obj = pulse.Gaussian(duration=160, amp=0.3, sigma=40)

        self.assertEqual(assigned, ref_obj)
示例#23
0
    def test_amplitude(self):
        """Test amplitude update from Rabi."""

        rabi = Rabi(self.qubit)
        rabi.set_experiment_options(amplitudes=np.linspace(-0.95, 0.95, 21))
        exp_data = rabi.run(RabiBackend())
        exp_data.block_for_results()

        with self.assertRaises(CalibrationError):
            self.cals.get_schedule("xp", qubits=0)

        to_update = [(np.pi, "amp", "xp"), (np.pi / 2, "amp", self.x90p)]

        self.assertEqual(len(self.cals.parameters_table()), 2)

        Amplitude.update(self.cals, exp_data, angles_schedules=to_update)

        with self.assertRaises(CalibrationError):
            self.cals.get_schedule("xp", qubits=0)

        self.assertEqual(len(self.cals.parameters_table()["data"]), 4)

        # Now check the corresponding schedules
        result = exp_data.analysis_results(1)
        rate = 2 * np.pi * result.value.value
        amp = np.round(np.pi / rate, decimals=8)
        with pulse.build(name="xp") as expected:
            pulse.play(pulse.Gaussian(160, amp, 40),
                       pulse.DriveChannel(self.qubit))

        self.assertEqual(self.cals.get_schedule("xp", qubits=self.qubit),
                         expected)

        amp = np.round(0.5 * np.pi / rate, decimals=8)
        with pulse.build(name="xp") as expected:
            pulse.play(pulse.Gaussian(160, amp, 40),
                       pulse.DriveChannel(self.qubit))

        self.assertEqual(self.cals.get_schedule("x90p", qubits=self.qubit),
                         expected)
示例#24
0
    def test_call_with_parameter_name_collision(self):
        """Test call subroutine with duplicated parameter names."""
        amp1 = circuit.Parameter('amp')
        amp2 = circuit.Parameter('amp')
        sigma = circuit.Parameter('sigma')

        with pulse.build() as subroutine:
            pulse.play(pulse.Gaussian(160, amp1, sigma), pulse.DriveChannel(0))
            pulse.play(pulse.Gaussian(160, amp2, sigma), pulse.DriveChannel(0))

        with pulse.build() as main_prog:
            pulse.call(subroutine, value_dict={amp1: 0.1, amp2: 0.2}, sigma=40)

        assigned_sched = inline_subroutines(main_prog)

        play_0 = assigned_sched.instructions[0][1]
        play_1 = assigned_sched.instructions[1][1]

        self.assertEqual(play_0.pulse.amp, 0.1)
        self.assertEqual(play_0.pulse.sigma, 40)
        self.assertEqual(play_1.pulse.amp, 0.2)
        self.assertEqual(play_1.pulse.sigma, 40)
    def setUp(self):
        """Setup for the test."""
        super().setUp()
        self.inst_map = pulse.InstructionScheduleMap()

        self.sx_duration = 160

        with pulse.build(name="sx") as sx_sched:
            pulse.play(pulse.Gaussian(self.sx_duration, 0.5, 40), pulse.DriveChannel(0))

        self.inst_map.add("sx", 0, sx_sched)

        self.cals = Calibrations.from_backend(FakeArmonk(), libraries=[FixedFrequencyTransmon()])
示例#26
0
    def test_default_schedule(self):
        """Test the default schedule."""
        rabi = Rabi(2, self.sched)
        rabi.set_experiment_options(amplitudes=[0.5])
        rabi.backend = MockIQBackend(RabiHelper())
        circs = rabi.circuits()

        with pulse.build() as expected:
            pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(2))

        self.assertEqual(circs[0].calibrations["Rabi"][((2, ), (0.5, ))],
                         expected)
        self.assertEqual(len(circs), 1)
示例#27
0
    def test_ef_rabi_circuit(self):
        """Test the EFRabi experiment end to end."""
        anharm = -330e6

        with pulse.build() as sched:
            pulse.shift_frequency(anharm, pulse.DriveChannel(2))
            pulse.play(pulse.Gaussian(160, Parameter("amp"), 40),
                       pulse.DriveChannel(2))
            pulse.shift_frequency(-anharm, pulse.DriveChannel(2))

        rabi12 = EFRabi(2, sched)
        rabi12.set_experiment_options(amplitudes=[0.5])
        circ = rabi12.circuits()[0]

        with pulse.build() as expected:
            pulse.shift_frequency(anharm, pulse.DriveChannel(2))
            pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(2))
            pulse.shift_frequency(-anharm, pulse.DriveChannel(2))

        self.assertEqual(circ.calibrations["Rabi"][((2, ), (0.5, ))], expected)
        self.assertEqual(circ.data[0][0].name, "x")
        self.assertEqual(circ.data[1][0].name, "Rabi")
    def setUp(self):
        """Setup amplitude values."""
        super().setUp()
        self.cals = Calibrations()
        self.qubit = 1

        axp = Parameter("amp")
        chan = Parameter("ch0")
        with pulse.build(name="xp") as xp:
            pulse.play(pulse.Gaussian(duration=160, amp=axp, sigma=40),
                       pulse.DriveChannel(chan))

        ax90p = Parameter("amp")
        with pulse.build(name="x90p") as x90p:
            pulse.play(pulse.Gaussian(duration=160, amp=ax90p, sigma=40),
                       pulse.DriveChannel(chan))

        self.x90p = x90p

        self.cals.add_schedule(xp, num_qubits=1)
        self.cals.add_schedule(x90p, num_qubits=1)
        self.cals.add_parameter_value(0.2, "amp", self.qubit, "xp")
        self.cals.add_parameter_value(0.1, "amp", self.qubit, "x90p")
示例#29
0
    def _default_gate_schedule(self, backend: Optional[Backend] = None):
        """Create the default schedule for the Rabi gate."""
        amp = Parameter("amp")
        with pulse.build(backend=backend, name="rabi") as default_schedule:
            pulse.play(
                pulse.Gaussian(
                    duration=self.experiment_options.duration,
                    amp=amp,
                    sigma=self.experiment_options.sigma,
                ),
                pulse.DriveChannel(self.physical_qubits[0]),
            )

        return default_schedule
示例#30
0
    def test_empty(self):
        """Test is_empty check."""
        test_pulse = pulse.Gaussian(10, 0.1, 3)

        sched = pulse.Schedule()
        sched = sched.insert(0, pulse.ShiftPhase(1.57, pulse.DriveChannel(0)))

        events = ChannelEvents.load_program(sched, pulse.DriveChannel(0))
        self.assertTrue(events.is_empty())

        sched = pulse.Schedule()
        sched = sched.insert(0, pulse.Play(test_pulse, pulse.DriveChannel(0)))

        events = ChannelEvents.load_program(sched, pulse.DriveChannel(0))
        self.assertFalse(events.is_empty())