Esempio n. 1
0
 def test_playing_waveform(self):
     """Test playing waveform."""
     # pylint: disable=invalid-name
     t = np.linspace(0, 1, 100)
     waveform = 0.1 * np.sin(2 * np.pi * t)
     with builder.build() as test_sched:
         builder.play(waveform, DriveChannel(0))
     self.assert_roundtrip_equal(test_sched)
Esempio n. 2
0
 def test_symbolic_amplitude_limit(self):
     """Test applying amplitude limit to symbolic pulse."""
     with builder.build() as test_sched:
         builder.play(
             Gaussian(160, 20, 40, limit_amplitude=False),
             DriveChannel(0),
         )
     self.assert_roundtrip_equal(test_sched)
Esempio n. 3
0
 def test_library_pulse_play(self, envelope, channel, *params):
     """Test playing standard pulses."""
     with builder.build() as test_sched:
         builder.play(
             envelope(*params),
             channel(0),
         )
     self.assert_roundtrip_equal(test_sched)
Esempio n. 4
0
 def test_waveform_amplitude_limit(self):
     """Test applying amplitude limit to waveform."""
     with builder.build() as test_sched:
         builder.play(
             Waveform([1, 2, 3, 4, 5], limit_amplitude=False),
             DriveChannel(0),
         )
     self.assert_roundtrip_equal(test_sched)
Esempio n. 5
0
    def test_override(self):
        """Test for overriding standard gate with pulse gate."""
        amp = Parameter("amp")

        with builder.build() as caldef:
            builder.play(Constant(100, amp), ControlChannel(0))

        qc = QuantumCircuit(2)
        qc.rx(amp, 0)
        qc.add_calibration("rx", (0, ), caldef, [amp])

        self.assert_roundtrip_equal(qc)
Esempio n. 6
0
    def test_2q_gate(self):
        """Test for two qubit pulse gate."""
        mygate = Gate("mygate", 2, [])

        with builder.build() as caldef:
            builder.play(Constant(100, 0.1), ControlChannel(0))

        qc = QuantumCircuit(2)
        qc.append(mygate, [0, 1])
        qc.add_calibration(mygate, (0, 1), caldef)

        self.assert_roundtrip_equal(qc)
Esempio n. 7
0
    def test_parameterized_gate(self):
        """Test for parameterized pulse gate."""
        amp = Parameter("amp")
        angle = Parameter("angle")
        mygate = Gate("mygate", 2, [amp, angle])

        with builder.build() as caldef:
            builder.play(Constant(100, amp * np.exp(1j * angle)),
                         ControlChannel(0))

        qc = QuantumCircuit(2)
        qc.append(mygate, [0, 1])
        qc.add_calibration(mygate, (0, 1), caldef)

        self.assert_roundtrip_equal(qc)
Esempio n. 8
0
    def test_playing_custom_symbolic_pulse(self):
        """Test playing a custom user pulse."""
        # pylint: disable=invalid-name
        t, amp, freq = sym.symbols("t, amp, freq")
        sym_envelope = 2 * amp * (freq * t - sym.floor(1 / 2 + freq * t))

        my_pulse = SymbolicPulse(
            pulse_type="Sawtooth",
            duration=100,
            parameters={
                "amp": 0.1,
                "freq": 0.05
            },
            envelope=sym_envelope,
            name="pulse1",
        )
        with builder.build() as test_sched:
            builder.play(my_pulse, DriveChannel(0))
        self.assert_roundtrip_equal(test_sched)
Esempio n. 9
0
    def test_multiple_calibrations(self):
        """Test for circuit with multiple pulse gates."""
        amp1 = Parameter("amp1")
        amp2 = Parameter("amp2")
        mygate = Gate("mygate", 1, [amp2])

        with builder.build() as caldef1:
            builder.play(Constant(100, amp1), DriveChannel(0))

        with builder.build() as caldef2:
            builder.play(Constant(100, amp2), DriveChannel(1))

        qc = QuantumCircuit(2)
        qc.rx(amp1, 0)
        qc.append(mygate, [1])
        qc.add_calibration("rx", (0, ), caldef1, [amp1])
        qc.add_calibration(mygate, (1, ), caldef2)

        self.assert_roundtrip_equal(qc)
Esempio n. 10
0
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
Esempio n. 11
0
    def test_bell_schedule(self):
        """Test complex schedule to create a Bell state."""
        with builder.build() as test_sched:
            with builder.align_sequential():
                # H
                builder.shift_phase(-1.57, DriveChannel(0))
                builder.play(Drag(160, 0.05, 40, 1.3), DriveChannel(0))
                builder.shift_phase(-1.57, DriveChannel(0))
                # ECR
                with builder.align_left():
                    builder.play(GaussianSquare(800, 0.05, 64, 544),
                                 DriveChannel(1))
                    builder.play(GaussianSquare(800, 0.1 - 0.2j, 64, 544),
                                 ControlChannel(0))
                builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0))
                with builder.align_left():
                    builder.play(GaussianSquare(800, -0.05, 64, 544),
                                 DriveChannel(1))
                    builder.play(GaussianSquare(800, -0.1 + 0.2j, 64, 544),
                                 ControlChannel(0))
                builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0))
                # Measure
                with builder.align_left():
                    builder.play(GaussianSquare(8000, 0.2, 64, 7744),
                                 MeasureChannel(0))
                    builder.acquire(8000, AcquireChannel(0), MemorySlot(0))

        self.assert_roundtrip_equal(test_sched)
Esempio n. 12
0
 def test_parameterized(self, channel, *params):
     """Test playing parameterized pulse."""
     # pylint: disable=no-value-for-parameter
     with builder.build() as test_sched:
         builder.play(Gaussian(*params), DriveChannel(channel))
     self.assert_roundtrip_equal(test_sched)
Esempio n. 13
0
def generate_schedule_blocks():
    """Standard QPY testcase for schedule blocks."""
    from qiskit.pulse import builder, channels, library
    from qiskit.utils import optionals

    # Parameterized schedule test is avoided.
    # Generated reference and loaded QPY object may induce parameter uuid mismatch.
    # As workaround, we need test with bounded parameters, however, schedule.parameters
    # are returned as Set and thus its order is random.
    # Since schedule parameters are validated, we cannot assign random numbers.
    # We need to upgrade testing framework.

    schedule_blocks = []

    # Instructions without parameters
    with builder.build() as block:
        with builder.align_sequential():
            builder.set_frequency(5e9, channels.DriveChannel(0))
            builder.shift_frequency(10e6, channels.DriveChannel(1))
            builder.set_phase(1.57, channels.DriveChannel(0))
            builder.shift_phase(0.1, channels.DriveChannel(1))
            builder.barrier(channels.DriveChannel(0), channels.DriveChannel(1))
            builder.play(library.Gaussian(160, 0.1, 40),
                         channels.DriveChannel(0))
            builder.play(library.GaussianSquare(800, 0.1, 64, 544),
                         channels.ControlChannel(0))
            builder.play(library.Drag(160, 0.1, 40, 1.5),
                         channels.DriveChannel(1))
            builder.play(library.Constant(800, 0.1),
                         channels.MeasureChannel(0))
            builder.acquire(1000, channels.AcquireChannel(0),
                            channels.MemorySlot(0))
    schedule_blocks.append(block)
    # Raw symbolic pulse
    if optionals.HAS_SYMENGINE:
        import symengine as sym
    else:
        import sympy as sym
    duration, amp, t = sym.symbols("duration amp t")  # pylint: disable=invalid-name
    expr = amp * sym.sin(2 * sym.pi * t / duration)
    my_pulse = library.SymbolicPulse(
        pulse_type="Sinusoidal",
        duration=100,
        parameters={"amp": 0.1},
        envelope=expr,
        valid_amp_conditions=sym.Abs(amp) <= 1.0,
    )
    with builder.build() as block:
        builder.play(my_pulse, channels.DriveChannel(0))
    schedule_blocks.append(block)
    # Raw waveform
    my_waveform = 0.1 * np.sin(2 * np.pi * np.linspace(0, 1, 100))
    with builder.build() as block:
        builder.play(my_waveform, channels.DriveChannel(0))
    schedule_blocks.append(block)

    return schedule_blocks