コード例 #1
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(qubits=[0, 1]), [ControlChannel(0)])
     with self.assertRaises(BackendConfigurationError):
         # Check that an error is raised if key not found in self._qubit_channel_map
         self.config.control(qubits=(10, 1))
コード例 #2
0
    def test_persistent_value(self):
        """Test converted qobj from PersistentValueInstruction."""
        cmd = PersistentValue(value=0.1j)
        instruction = cmd(ControlChannel(1))

        qobj = PulseQobjInstruction(name='pv', ch='u1', t0=0, val=0.1j)
        converted_instruction = self.converter(qobj)

        self.assertEqual(converted_instruction.timeslots,
                         instruction.timeslots)
        self.assertEqual(converted_instruction.instructions[0][-1].command,
                         cmd)
コード例 #3
0
    def test_constant_pulse_instruction(self):
        """Test that parametric pulses are correctly converted to PulseQobjInstructions."""
        converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
        instruction = Play(Constant(duration=25, amp=1), ControlChannel(2))

        valid_qobj = PulseQobjInstruction(
            name='parametric_pulse',
            pulse_shape='constant',
            ch='u2',
            t0=20,
            parameters={'duration': 25, 'amp': 1})
        self.assertEqual(converter(20, instruction), valid_qobj)
コード例 #4
0
 def setUp(self):
     qubits = [
         Qubit(0,
               drive_channels=[DriveChannel(0, 1.2)],
               control_channels=[ControlChannel(0)]),
         Qubit(1,
               drive_channels=[DriveChannel(1, 3.4)],
               acquire_channels=[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)
コード例 #5
0
    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))
コード例 #6
0
    def test_persistent_value(self):
        """Test converted qobj from PersistentValueInstruction."""
        with self.assertWarns(DeprecationWarning):
            cmd = PersistentValue(value=0.1j)
        with self.assertWarns(DeprecationWarning):
            instruction = cmd(ControlChannel(1))

        qobj = PulseQobjInstruction(name='pv', ch='u1', t0=0, val=0.1j)
        with self.assertWarns(DeprecationWarning):
            converted_instruction = self.converter(qobj)

        self.assertEqual(converted_instruction.timeslots, instruction.timeslots)
        self.assertEqual(converted_instruction.instructions[0][-1], instruction)
コード例 #7
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)
コード例 #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

        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)
コード例 #9
0
    def test_parameterized_persistent_value(self):
        """Test converted qobj from PersistentValueInstruction."""
        cmd = PersistentValue(value=0.5+0.j)
        instruction = cmd(ControlChannel(1)) << 10

        qobj = PulseQobjInstruction(name='pv', ch='u1', t0=10, val='P1*cos(np.pi*P2)')
        converted_instruction = self.converter(qobj)

        self.assertIsInstance(converted_instruction, ParameterizedSchedule)

        evaluated_instruction = converted_instruction.bind_parameters(P1=0.5, P2=0.)

        self.assertEqual(evaluated_instruction.timeslots, instruction.timeslots)
        self.assertEqual(evaluated_instruction.instructions[0][-1].command, cmd)
コード例 #10
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)
コード例 #11
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)
コード例 #12
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)
コード例 #13
0
    def test_constant_pulse_instruction(self):
        """Test that parametric pulses are correctly converted to PulseQobjInstructions."""
        converter = InstructionToQobjConverter(PulseQobjInstruction,
                                               meas_level=2)
        instruction = Play(Constant(duration=25, amp=1), ControlChannel(2))

        valid_qobj = PulseQobjInstruction(
            name="parametric_pulse",
            pulse_shape="constant",
            ch="u2",
            t0=20,
            parameters={
                "duration": 25,
                "amp": 1
            },
        )
        self.assertEqual(converter(20, instruction), valid_qobj)
コード例 #14
0
    def test_parameterized_persistent_value(self):
        """Test converted qobj from PersistentValueInstruction."""
        with self.assertWarns(DeprecationWarning):
            cmd = PersistentValue(value=0.5+0.j)
        with self.assertWarns(DeprecationWarning):
            instruction = cmd(ControlChannel(1)) << 10

        qobj = PulseQobjInstruction(name='pv', ch='u1', t0=10, val='P1*cos(np.pi*P2)')
        converted_instruction = self.converter(qobj)

        self.assertIsInstance(converted_instruction, ParameterizedSchedule)

        with self.assertWarns(DeprecationWarning):
            evaluated_instruction = converted_instruction.bind_parameters(P1=0.5, P2=0.)

        self.assertEqual(evaluated_instruction.start_time, instruction.start_time)
        self.assertEqual(evaluated_instruction.duration, instruction.duration)
        self.assertEqual(evaluated_instruction.instructions[0][-1].command, cmd)
コード例 #15
0
    def control(self, qubit: int) -> ControlChannel:
        """
        Return the secondary drive channel for the given qubit -- typically utilized for
        controlling multiqubit interactions. This channel is derived from other channels.

        Raises:
            BackendConfigurationError: If the qubit is not a part of the system.
        Returns:
            Qubit control channel.
        """
        # TODO: Determine this from the hamiltonian.
        warnings.warn(
            "The control channel appropriate for an interaction should be determined "
            "from the hamiltonian. This will be determined for you in the future."
        )
        if qubit > self.n_qubits:
            raise BackendConfigurationError(
                "This system does not have {} qubits.".format(qubit))
        return ControlChannel(qubit)
コード例 #16
0
 def test_barrier(self):
     """Test barrier."""
     with builder.build() as test_sched:
         builder.barrier(DriveChannel(0), DriveChannel(1),
                         ControlChannel(2))
     self.assert_roundtrip_equal(test_sched)
コード例 #17
0
    def test_default(self):
        """Test default control channel."""
        control_channel = ControlChannel(123)

        self.assertEqual(control_channel.index, 123)
        self.assertEqual(control_channel.name, "u123")