Esempio n. 1
0
 def test_multiple_measure_in_3Q(self):
     """Test multiple measure, user memslot mapping, 3Q."""
     backend = FakeOpenPulse3Q()
     cmd_def = backend.defaults().build_cmd_def()
     q = QuantumRegister(3)
     c = ClassicalRegister(5)
     qc = QuantumCircuit(q, c)
     qc.measure(q[0], c[2])
     qc.measure(q[0], c[4])
     sched = schedule(qc, backend)
     expected = Schedule(
         cmd_def.get('measure',
                     [0, 1, 2]).filter(channels=[MeasureChannel(0)]),
         Acquire(duration=10)(
             [AcquireChannel(0),
              AcquireChannel(1),
              AcquireChannel(2)],
             [MemorySlot(2), MemorySlot(0),
              MemorySlot(1)]),
         (10, cmd_def.get('measure',
                          [0, 1, 2]).filter(channels=[MeasureChannel(0)])),
         (10, Acquire(duration=10)(
             [AcquireChannel(0),
              AcquireChannel(1),
              AcquireChannel(2)],
             [MemorySlot(4), MemorySlot(0),
              MemorySlot(1)])))
     self.assertEqual(sched.instructions, expected.instructions)
    def test_measure_combined(self):
        """
        Test to check for measure on the same qubit which generated another measure schedule.

        The measures on different qubits are combined, but measures on the same qubit
        adds another measure to the schedule.
        """
        q = QuantumRegister(2)
        c = ClassicalRegister(2)
        qc = QuantumCircuit(q, c)
        qc.u2(3.14, 1.57, q[0])
        qc.cx(q[0], q[1])
        qc.measure(q[0], c[0])
        qc.measure(q[1], c[1])
        qc.measure(q[1], c[1])
        sched = schedule(qc, self.backend, method="as_soon_as_possible")
        expected = Schedule(
            self.inst_map.get('u2', [0], 3.14,
                              1.57), (28, self.inst_map.get('cx', [0, 1])),
            (50, self.inst_map.get('measure', [0, 1])),
            (60, self.inst_map.get(
                'measure', [0, 1]).filter(channels=[MeasureChannel(1)])),
            (60, Acquire(10, AcquireChannel(0), MemorySlot(0))),
            (60, Acquire(10, AcquireChannel(1), MemorySlot(1))))
        self.assertEqual(sched.instructions, expected.instructions)
 def test_user_mapping_for_memslots_3Q(self):
     """Test measuring two of three qubits."""
     backend = FakeOpenPulse3Q()
     cmd_def = backend.defaults().build_cmd_def()
     q = QuantumRegister(3)
     c = ClassicalRegister(3)
     qc = QuantumCircuit(q, c)
     qc.measure(q[1], c[2])
     qc.measure(q[2], c[0])
     sched = schedule(qc, backend)
     expected = Schedule(
         cmd_def.get('measure', [0, 1, 2]).filter(
             channels=[MeasureChannel(1), MeasureChannel(2)]),
         Acquire(duration=10)([AcquireChannel(0), AcquireChannel(1), AcquireChannel(2)],
                              [MemorySlot(1), MemorySlot(2), MemorySlot(0)]))
     self.assertEqual(sched.instructions, expected.instructions)
Esempio n. 4
0
 def test_measure(self):
     """Test macro - measure."""
     sched = macros.measure(qubits=[0], backend=self.backend)
     expected = Schedule(
         self.inst_map.get('measure',
                           [0, 1]).filter(channels=[MeasureChannel(0)]),
         Acquire(10, AcquireChannel(0), MemorySlot(0)),
         Acquire(10, AcquireChannel(1), MemorySlot(1)))
     self.assertEqual(sched.instructions, expected.instructions)
 def test_only_needed_measures(self):
     """Test that `MeasureChannel`s are only added for measured qubits."""
     q = QuantumRegister(2)
     c = ClassicalRegister(2)
     qc = QuantumCircuit(q, c)
     qc.measure(q[1], c[1])
     sched_all_channels = schedule(qc, self.backend, method="as_soon_as_possible").channels
     deleted_channels = [MeasureChannel(0)]
     self.assertNotIn(sched_all_channels, deleted_channels)
Esempio n. 6
0
 def test_measure_sched_with_qubit_mem_slots(self):
     """Test measure with custom qubit_mem_slots."""
     sched = macros.measure(qubits=[0],
                            backend=self.backend,
                            qubit_mem_slots={0: 1})
     expected = Schedule(
         self.inst_map.get('measure', [0, 1]).filter(channels=[MeasureChannel(0)]),
         Acquire(10, AcquireChannel(0), MemorySlot(1)),
         Acquire(10, AcquireChannel(1), MemorySlot(0)))
     self.assertEqual(sched.instructions, expected.instructions)
Esempio n. 7
0
 def test_measure(self):
     """Test utility function - measure."""
     acquire = Acquire(duration=10)
     sched = measure(qubits=[0], backend=self.backend)
     expected = Schedule(
         self.inst_map.get('measure',
                           [0, 1]).filter(channels=[MeasureChannel(0)]),
         acquire(AcquireChannel(0), MemorySlot(0)),
         acquire(AcquireChannel(1), MemorySlot(1)))
     self.assertEqual(sched.instructions, expected.instructions)
    def test_construction_from_channels(self):
        """Test construction of device topology from channels."""
        topology = SystemTopology(drives=self.drives,
                                  controls=self.controls,
                                  measures=self.measures,
                                  acquires=self.acquires)

        self.assertEqual(topology.qubits[0].drive, DriveChannel(0))
        self.assertEqual(topology.qubits[0].measure, MeasureChannel(0))
        self.assertEqual(topology.qubits[0].acquire, AcquireChannel(0))
        self.assertEqual(topology.qubits[0].controls[0], ControlChannel(0))
Esempio n. 9
0
 def test_measure_sched_with_meas_map(self):
     """Test measure with custom meas_map as list and dict."""
     sched_with_meas_map_list = macros.measure(qubits=[0],
                                               backend=self.backend,
                                               meas_map=[[0, 1]])
     sched_with_meas_map_dict = macros.measure(qubits=[0],
                                               backend=self.backend,
                                               meas_map={0: [0, 1], 1: [0, 1]})
     expected = Schedule(
         self.inst_map.get('measure', [0, 1]).filter(channels=[MeasureChannel(0)]),
         Acquire(10, AcquireChannel(0), MemorySlot(0)),
         Acquire(10, AcquireChannel(1), MemorySlot(1)))
     self.assertEqual(sched_with_meas_map_list.instructions, expected.instructions)
     self.assertEqual(sched_with_meas_map_dict.instructions, expected.instructions)
 def test_user_mapping_for_memslots(self):
     """
     Test that the new schedule only has required `MeasureChannel`s and that the
     `MemorySlot`s are mapped according to the input circuit.
     """
     q = QuantumRegister(2)
     c = ClassicalRegister(2)
     qc = QuantumCircuit(q, c)
     qc.measure(q[0], c[1])
     sched = schedule(qc, self.backend)
     expected = Schedule(
         self.cmd_def.get('measure', [0, 1]).filter(channels=[MeasureChannel(0)]),
         Acquire(duration=10)([AcquireChannel(0), AcquireChannel(1)],
                              [MemorySlot(1), MemorySlot(0)]))
     self.assertEqual(sched.instructions, expected.instructions)
    def test_clbits_of_calibrated_measurements(self):
        """Test that calibrated measurements are only used when the classical bits also match."""
        q = QuantumRegister(2)
        c = ClassicalRegister(2)
        qc = QuantumCircuit(q, c)
        qc.measure(q[0], c[1])

        meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0))
        meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0))
        qc.add_calibration("measure", [0], meas_sched)

        sched = schedule(qc, self.backend)
        # Doesn't use the calibrated schedule because the classical memory slots do not match
        expected = Schedule(macros.measure([0], self.backend, qubit_mem_slots={0: 1}))
        self.assertEqual(sched.instructions, expected.instructions)
    def test_calibrated_measurements(self):
        """Test scheduling calibrated measurements."""
        q = QuantumRegister(2)
        c = ClassicalRegister(2)
        qc = QuantumCircuit(q, c)
        qc.append(U2Gate(0, 0), [q[0]])
        qc.measure(q[0], c[0])

        meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0))
        meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0))
        qc.add_calibration("measure", [0], meas_sched)

        sched = schedule(qc, self.backend)
        expected = Schedule(self.inst_map.get("u2", [0], 0, 0), (2, meas_sched))
        self.assertEqual(sched.instructions, expected.instructions)
Esempio n. 13
0
    def test_measure_with_custom_inst_map(self):
        """Test measure with custom inst_map, meas_map with measure_name."""
        q0_sched = Play(GaussianSquare(1200, 1, 0.4, 1150), MeasureChannel(0))
        q0_sched += Acquire(1200, AcquireChannel(0), MemorySlot(0))
        inst_map = InstructionScheduleMap()
        inst_map.add('my_sched', 0, q0_sched)
        sched = macros.measure(qubits=[0],
                               measure_name='my_sched',
                               inst_map=inst_map,
                               meas_map=[[0]])
        self.assertEqual(sched.instructions, q0_sched.instructions)

        with self.assertRaises(PulseError):
            macros.measure(qubits=[0],
                           measure_name="name",
                           inst_map=inst_map,
                           meas_map=[[0]])
    def test_subset_calibrated_measurements(self):
        """Test that measurement calibrations can be added and used for some qubits, even
        if the other qubits do not also have calibrated measurements."""
        qc = QuantumCircuit(3, 3)
        qc.measure(0, 0)
        qc.measure(1, 1)
        qc.measure(2, 2)
        meas_scheds = []
        for qubit in [0, 2]:
            meas = (Play(Gaussian(1200, 0.2, 4), MeasureChannel(qubit)) +
                    Acquire(1200, AcquireChannel(qubit), MemorySlot(qubit)))
            meas_scheds.append(meas)
            qc.add_calibration('measure', [qubit], meas)

        meas = macros.measure([1], FakeOpenPulse3Q())
        meas = meas.exclude(channels=[AcquireChannel(0), AcquireChannel(2)])
        sched = schedule(qc, FakeOpenPulse3Q())
        expected = Schedule(meas_scheds[0], meas_scheds[1], meas)
        self.assertEqual(sched.instructions, expected.instructions)
Esempio n. 15
0
    def __init__(self, qobj_model, qubit_lo_freq, meas_lo_freq, qubit_lo_range,
                 meas_lo_range, **run_config):
        """Create new converter.

        Args:
            qobj_model (PulseQobjExperimentConfig): qobj model for experiment config.
            qubit_lo_freq (list): List of default qubit lo frequencies.
            meas_lo_freq (list): List of default meas lo frequencies.
            qubit_lo_range (list): List of qubit lo ranges.
            meas_lo_range (list): List of measurement lo ranges.
            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()

        for i, lo_range in enumerate(qubit_lo_range):
            self.default_lo_config.add_lo_range(DriveChannel(i), lo_range)
        for i, lo_range in enumerate(meas_lo_range):
            self.default_lo_config.add_lo_range(MeasureChannel(i), lo_range)
 def setUp(self):
     self.drives = [DriveChannel(ii) for ii in range(2)]
     self.acquires = [AcquireChannel(ii) for ii in range(2)]
     self.controls = [ControlChannel(ii) for ii in range(1)]
     self.measures = [MeasureChannel(ii) for ii in range(2)]