コード例 #1
0
 def test_get_qubit_channels(self):
     """Test to get all channels operated on a given qubit."""
     self.assertTrue(
         self._test_lists_equal(
             actual=self.config.get_qubit_channels(qubit=(1, )),
             expected=[
                 DriveChannel(1),
                 MeasureChannel(1),
                 AcquireChannel(1)
             ]))
     self.assertTrue(
         self._test_lists_equal(
             actual=self.config.get_qubit_channels(qubit=1),
             expected=[
                 ControlChannel(0),
                 ControlChannel(1),
                 AcquireChannel(1),
                 DriveChannel(1),
                 MeasureChannel(1)
             ]))
     backend_3q = self.provider.get_backend('fake_openpulse_3q')
     self.assertTrue(
         self._test_lists_equal(
             actual=backend_3q.configuration().get_qubit_channels(1),
             expected=[
                 MeasureChannel(1),
                 ControlChannel(0),
                 ControlChannel(2),
                 AcquireChannel(1),
                 DriveChannel(1),
                 ControlChannel(1)
             ]))
     with self.assertRaises(BackendConfigurationError):
         # Check that an error is raised if key not found in self._channel_qubit_map
         self.config.get_qubit_channels(10)
コード例 #2
0
    def test_default(self):
        """Test default qubit.
        """
        qubit = Qubit(1, DriveChannel(2), MeasureChannel(4), AcquireChannel(5),
                      control_channels=[ControlChannel(3)])

        self.assertEqual(qubit.drive, DriveChannel(2))
        self.assertEqual(qubit.controls[0], ControlChannel(3))
        self.assertEqual(qubit.measure, MeasureChannel(4))
        self.assertEqual(qubit.acquire, AcquireChannel(5))
コード例 #3
0
    def test_get_channel_lo(self):
        """Test retrieving channel lo from LO config."""
        channel = DriveChannel(0)
        lo_config = LoConfig({channel: 1.0})
        self.assertEqual(lo_config.channel_lo(channel), 1.0)

        channel = MeasureChannel(0)
        lo_config = LoConfig({channel: 2.0})
        self.assertEqual(lo_config.channel_lo(channel), 2.0)

        with self.assertRaises(PulseError):
            lo_config.channel_lo(MeasureChannel(1))
コード例 #4
0
    def test_default(self):
        """Test default qubit.
        """
        qubit = Qubit(1,
                      drive_channels=[DriveChannel(2, 1.2)],
                      control_channels=[ControlChannel(3)],
                      measure_channels=[MeasureChannel(4)],
                      acquire_channels=[AcquireChannel(5)])

        self.assertEqual(qubit.drive, DriveChannel(2, 1.2))
        self.assertEqual(qubit.control, ControlChannel(3))
        self.assertEqual(qubit.measure, MeasureChannel(4))
        self.assertEqual(qubit.acquire, AcquireChannel(5))
コード例 #5
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

        qubits = [Qubit(0, DriveChannel(0), AcquireChannel(0), MeasureChannel(0),
                        control_channels=[ControlChannel(0)]),
                  Qubit(1, DriveChannel(1), MeasureChannel(0), AcquireChannel(1))]
        registers = [RegisterSlot(i) for i in range(2)]
        mem_slots = [MemorySlot(i) for i in range(2)]
        self.two_qubit_device = DeviceSpecification(qubits, registers, mem_slots)
コード例 #6
0
    def setUp(self):
        super().setUp()

        qubits = [
            Qubit(0,
                  DriveChannel(0),
                  AcquireChannel(0),
                  MeasureChannel(0),
                  control_channels=[ControlChannel(0)]),
            Qubit(1, DriveChannel(1), MeasureChannel(0), AcquireChannel(1))
        ]
        registers = [RegisterSlot(i) for i in range(2)]
        mem_slots = [MemorySlot(i) for i in range(2)]
        self.two_qubit_device = DeviceSpecification(qubits, registers,
                                                    mem_slots)
コード例 #7
0
    def test_default(self):
        """Test default device specification.
        """
        qubits = [
            Qubit(0, DriveChannel(0), MeasureChannel(0), AcquireChannel(0)),
            Qubit(1, DriveChannel(1), MeasureChannel(1), AcquireChannel(1))
        ]
        registers = [RegisterSlot(i) for i in range(2)]
        mem_slots = [MemorySlot(i) for i in range(2)]
        spec = DeviceSpecification(qubits, registers, mem_slots)

        self.assertEqual(spec.q[0].drive, DriveChannel(0))
        self.assertEqual(spec.q[1].acquire, AcquireChannel(1))
        self.assertEqual(spec.mem[0], MemorySlot(0))
        self.assertEqual(spec.c[1], RegisterSlot(1))
コード例 #8
0
    def test_default(self):
        """Test default measure channel.
        """
        measure_channel = MeasureChannel(123)

        self.assertEqual(measure_channel.index, 123)
        self.assertEqual(measure_channel.name, 'm123')
コード例 #9
0
    def __init__(self,
                 qobj_model,
                 qubit_lo_freq,
                 meas_lo_freq,
                 qubit_lo_range=None,
                 meas_lo_range=None,
                 **run_config):
        """Create new converter.

        Args:
            qobj_model (PulseQobjExperimentConfig): qobj model for experiment config.
            qubit_lo_freq (list): List of default qubit lo frequencies in Hz.
            meas_lo_freq (list): List of default meas lo frequencies in Hz.
            qubit_lo_range (list): List of qubit lo ranges,
                each of form `[range_min, range_max]` in Hz.
            meas_lo_range (list): List of measurement lo ranges,
                each of form `[range_min, range_max]` in Hz.
            run_config (dict): experimental configuration.
        """
        self.qobj_model = qobj_model
        self.qubit_lo_freq = qubit_lo_freq
        self.meas_lo_freq = meas_lo_freq
        self.run_config = run_config

        self.default_lo_config = LoConfig()

        if qubit_lo_range:
            for i, lo_range in enumerate(qubit_lo_range):
                self.default_lo_config.add_lo_range(DriveChannel(i), lo_range)

        if meas_lo_range:
            for i, lo_range in enumerate(meas_lo_range):
                self.default_lo_config.add_lo_range(MeasureChannel(i),
                                                    lo_range)
コード例 #10
0
 def test_can_create_valid_user_lo_config(self):
     """Test if a LoConfig can be created with valid user_los."""
     channel1 = DriveChannel(0)
     channel2 = MeasureChannel(0)
     user_lo_config = LoConfig({channel1: 1.4, channel2: 3.6})
     self.assertEqual(1.4, user_lo_config.qubit_los[channel1])
     self.assertEqual(3.6, user_lo_config.meas_los[channel2])
コード例 #11
0
    def sample_schedule(self):
        """Generate a sample schedule that includes the most common elements of
           pulse schedules."""
        gp0 = library.gaussian(duration=20, amp=1.0, sigma=1.0)
        gp1 = library.gaussian(duration=20, amp=-1.0, sigma=2.0)
        gs0 = library.gaussian_square(duration=20, amp=-1.0, sigma=2.0, risefall=3)

        sched = Schedule(name='test_schedule')
        sched = sched.append(gp0(DriveChannel(0)))
        sched = sched.insert(0, Play(library.Constant(duration=60, amp=0.2 + 0.4j),
                                     ControlChannel(0)))
        sched = sched.insert(60, ShiftPhase(-1.57, DriveChannel(0)))
        sched = sched.insert(60, SetFrequency(8.0, DriveChannel(0)))
        sched = sched.insert(60, SetPhase(3.14, DriveChannel(0)))
        sched = sched.insert(70, ShiftFrequency(4.0e6, DriveChannel(0)))
        sched = sched.insert(30, Play(gp1, DriveChannel(1)))
        sched = sched.insert(60, Play(gp0, ControlChannel(0)))
        sched = sched.insert(60, Play(gs0, MeasureChannel(0)))
        sched = sched.insert(90, ShiftPhase(1.57, DriveChannel(0)))
        sched = sched.insert(90, Acquire(10,
                                         AcquireChannel(1),
                                         MemorySlot(1),
                                         RegisterSlot(1)))
        sched = sched.append(Delay(100, DriveChannel(0)))
        sched = sched + sched
        sched |= Snapshot("snapshot_1", "snap_type") << 60
        sched |= Snapshot("snapshot_2", "snap_type") << 120
        return sched
コード例 #12
0
    def test_buffering(self):
        """Test channel buffering."""
        buffer_chan = DriveChannel(0, buffer=5)
        measure_chan = MeasureChannel(0, buffer=10)
        acquire_chan = AcquireChannel(0, buffer=10)
        memory_slot = MemorySlot(0)
        gp0 = pulse_lib.gaussian(duration=10, amp=0.7, sigma=3)
        fc_pi_2 = FrameChange(phase=1.57)

        # no initial buffer
        sched = Schedule()
        sched += gp0(buffer_chan)

        self.assertEqual(sched.duration, 10)

        # this pulse should be buffered
        sched += gp0(buffer_chan)

        self.assertEqual(sched.duration, 25)

        # should not be buffered as framechange
        sched += fc_pi_2(buffer_chan)

        self.assertEqual(sched.duration, 25)

        # use buffer with insert
        sched = sched.insert(sched.duration, gp0(buffer_chan), buffer=True)

        self.assertEqual(sched.duration, 40)

        sched = Schedule()

        sched = gp0(measure_chan) + Acquire(duration=10)(acquire_chan, memory_slot)

        self.assertEqual(sched.duration, 10)
コード例 #13
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)
コード例 #14
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)
コード例 #15
0
    def sample_schedule(self):
        """Generate a sample schedule that includes the most common elements of
           pulse schedules."""
        gp0 = pulse_lib.gaussian(duration=20, amp=1.0, sigma=1.0)
        gp1 = pulse_lib.gaussian(duration=20, amp=-1.0, sigma=2.0)
        gs0 = pulse_lib.gaussian_square(duration=20,
                                        amp=-1.0,
                                        sigma=2.0,
                                        risefall=3)

        fc_pi_2 = FrameChange(phase=1.57)
        acquire = Acquire(10)
        delay = Delay(100)
        sched = Schedule()
        sched = sched.append(gp0(DriveChannel(0)))
        sched = sched.insert(
            0,
            pulse_lib.ConstantPulse(duration=60,
                                    amp=0.2 + 0.4j)(ControlChannel(0)))
        sched = sched.insert(60, FrameChange(phase=-1.57)(DriveChannel(0)))
        sched = sched.insert(60, SetFrequency(8.0, DriveChannel(0)))
        sched = sched.insert(30, gp1(DriveChannel(1)))
        sched = sched.insert(60, gp0(ControlChannel(0)))
        sched = sched.insert(60, gs0(MeasureChannel(0)))
        sched = sched.insert(90, fc_pi_2(DriveChannel(0)))
        sched = sched.insert(
            90, acquire(AcquireChannel(1), MemorySlot(1), RegisterSlot(1)))
        sched = sched.append(delay(DriveChannel(0)))
        sched = sched + sched
        sched |= Snapshot("snapshot_1", "snap_type") << 60
        sched |= Snapshot("snapshot_2", "snap_type") << 120
        return sched
コード例 #16
0
 def setUp(self):
     self.schedule = Schedule()
     self.qubits = [
         Qubit(0,
               drive_channel=DriveChannel(0),
               control_channels=[ControlChannel(0)],
               measure_channel=MeasureChannel(0),
               acquire_channel=AcquireChannel(0)),
         Qubit(1,
               drive_channel=DriveChannel(1),
               acquire_channel=AcquireChannel(1),
               measure_channel=MeasureChannel(1))
     ]
     self.registers = [RegisterSlot(i) for i in range(2)]
     self.mem_slots = [MemorySlot(i) for i in range(2)]
     self.device = DeviceSpecification(self.qubits, self.registers,
                                       self.mem_slots)
コード例 #17
0
 def test_can_create_valid_user_lo_config(self):
     """Test if a LoConfig can be created with valid user_los.
     """
     channel1 = DriveChannel(0, lo_freq=1.2, lo_freq_range=(1.0, 2.0))
     channel2 = MeasureChannel(0, lo_freq=3.4, lo_freq_range=(3.0, 4.0))
     user_lo_config = LoConfig({channel1: 1.4, channel2: 3.6})
     self.assertEqual(1.4, user_lo_config._q_lo_freq[channel1])
     self.assertEqual(3.6, user_lo_config._m_lo_freq[channel2])
コード例 #18
0
    def test_frame_change(self):
        """Test converted qobj from FrameChangeInstruction."""
        qobj = PulseQobjInstruction(name='fc', ch='m0', t0=0, phase=0.1)
        converted_instruction = self.converter(qobj)

        instruction = ShiftPhase(0.1, MeasureChannel(0))
        self.assertEqual(converted_instruction.timeslots, instruction.timeslots)
        self.assertEqual(converted_instruction.instructions[0][-1], instruction)
コード例 #19
0
    def test_set_phase(self):
        """Test converted qobj from SetPhase."""
        qobj = PulseQobjInstruction(name='setp', ch='m0', t0=0, phase=3.14)
        converted_instruction = self.converter(qobj)

        instruction = SetPhase(3.14, MeasureChannel(0))
        self.assertEqual(converted_instruction.start_time, 0)
        self.assertEqual(converted_instruction.duration, 0)
        self.assertEqual(converted_instruction.instructions[0][-1], instruction)
コード例 #20
0
 def test_get_channels(self):
     """Test requesting channels from the system."""
     self.assertEqual(self.config.drive(0), DriveChannel(0))
     self.assertEqual(self.config.measure(1), MeasureChannel(1))
     self.assertEqual(self.config.acquire(0), AcquireChannel(0))
     with self.assertRaises(BackendConfigurationError):
         # Check that an error is raised if the system doesn't have that many qubits
         self.assertEqual(self.config.acquire(10), AcquireChannel(10))
     self.assertEqual(self.config.control(0), ControlChannel(0))
コード例 #21
0
    def test_meas_los(self):
        """Test measurement channel configuration."""
        user_lo_config = LoConfig({MeasureChannel(0): 3.5e9})
        converter = LoConfigConverter(PulseQobjExperimentConfig, [1.2e9],
                                      [3.4e9], [(0., 5e9)], [(0., 5e9)])

        valid_qobj = PulseQobjExperimentConfig(meas_lo_freq=[3.5])

        self.assertEqual(converter(user_lo_config), valid_qobj)
コード例 #22
0
 def setUp(self):
     self.device = DeviceSpecification(qubits=[
         Qubit(0,
               drive_channels=[DriveChannel(0, 1.2)],
               measure_channels=[MeasureChannel(0, 3.4)],
               acquire_channels=[AcquireChannel(0)])
     ],
                                       registers=[RegisterSlot(0)],
                                       mem_slots=[MemorySlot(0)])
コード例 #23
0
 def test_get_channel_qubits(self):
     """Test to get all qubits operated on a given channel."""
     self.assertEqual(self.config.get_channel_qubits(channel=DriveChannel(0)), [0])
     self.assertEqual(self.config.get_channel_qubits(channel=ControlChannel(0)), [0, 1])
     backend_3q = self.provider.get_backend('fake_openpulse_3q')
     self.assertEqual(backend_3q.configuration().get_channel_qubits(ControlChannel(2)), [2, 1])
     self.assertEqual(backend_3q.configuration().get_channel_qubits(ControlChannel(1)), [1, 0])
     with self.assertRaises(BackendConfigurationError):
         # Check that an error is raised if key not found in self._channel_qubit_map
         self.config.get_channel_qubits(MeasureChannel(10))
コード例 #24
0
    def setUp(self):
        self.linear = SamplePulse(np.arange(0, 0.01), name='linear')
        self.pulse_library = [
            PulseLibraryItem(name=self.linear.name,
                             samples=self.linear.samples.tolist())
        ]

        self.converter = QobjToInstructionConverter(self.pulse_library,
                                                    buffer=0)

        self.device = DeviceSpecification(
            qubits=[
                Qubit(0, DriveChannel(0), MeasureChannel(0),
                      AcquireChannel(0)),
                Qubit(1, DriveChannel(1), MeasureChannel(1),
                      AcquireChannel(1)),
            ],
            registers=[RegisterSlot(0), RegisterSlot(1)],
            mem_slots=[MemorySlot(0), MemorySlot(1)])
コード例 #25
0
    def test_frame_change(self):
        """Test converted qobj from FrameChangeInstruction."""
        cmd = FrameChange(phase=0.1)
        instruction = cmd(MeasureChannel(0))

        qobj = PulseQobjInstruction(name='fc', ch='m0', t0=0, phase=0.1)
        converted_instruction = self.converter(qobj)

        self.assertEqual(converted_instruction.timeslots, instruction.timeslots)
        self.assertEqual(converted_instruction.instructions[0][-1].command, cmd)
コード例 #26
0
    def test_frame_change(self):
        """Test converted qobj from ShiftPhase."""
        qobj = PulseQobjInstruction(name="fc", ch="m0", t0=0, phase=0.1)
        converted_instruction = self.converter(qobj)

        instruction = ShiftPhase(0.1, MeasureChannel(0))
        self.assertEqual(converted_instruction.start_time, 0)
        self.assertEqual(converted_instruction.duration, 0)
        self.assertEqual(converted_instruction.instructions[0][-1],
                         instruction)
コード例 #27
0
 def setUp(self):
     self.device = DeviceSpecification(
         qubits=[
             Qubit(0, DriveChannel(0), MeasureChannel(0), AcquireChannel(0))
         ],
         registers=[
             RegisterSlot(0)
         ],
         mem_slots=[
             MemorySlot(0)
         ]
     )
コード例 #28
0
    def measure(self, qubit: int) -> MeasureChannel:
        """
        Return the measure stimulus channel for the given qubit.

        Raises:
            BackendConfigurationError: If the qubit is not a part of the system.
        Returns:
            Qubit measurement stimulus line.
        """
        if qubit > self.n_qubits:
            raise BackendConfigurationError("This system does not have {} qubits.".format(qubit))
        return MeasureChannel(qubit)
コード例 #29
0
    def test_parameterized_set_phase(self):
        """Test converted qobj from SetPhase, with parameterized phase."""
        qobj = PulseQobjInstruction(name='setp', ch='m0', t0=0, phase='p/2')
        converted_instruction = self.converter(qobj)
        self.assertIsInstance(converted_instruction, ParameterizedSchedule)

        evaluated_instruction = converted_instruction.bind_parameters(3.14)

        instruction = SetPhase(3.14 / 2, MeasureChannel(0))
        self.assertEqual(evaluated_instruction.start_time, 0)
        self.assertEqual(evaluated_instruction.duration, 0)
        self.assertEqual(evaluated_instruction.instructions[0][-1], instruction)
コード例 #30
0
    def measure(self, qubit: int) -> MeasureChannel:
        """
        Return the measure stimulus channel for the given qubit.

        Raises:
            BackendConfigurationError: If the qubit is not a part of the system.
        Returns:
            Qubit measurement stimulus line.
        """
        if not 0 <= qubit < self.n_qubits:
            raise BackendConfigurationError("Invalid index for {}-qubit system.".format(qubit))
        return MeasureChannel(qubit)