-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
203 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2022. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Scheduler Test.""" | ||
|
||
from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit | ||
from qiskit.exceptions import QiskitError | ||
from qiskit.pulse import InstructionScheduleMap, Schedule | ||
from qiskit.providers.fake_provider import GenericBackendV2 | ||
from qiskit.compiler.scheduler import schedule | ||
from test import QiskitTestCase # pylint: disable=wrong-import-order | ||
|
||
|
||
class TestCircuitScheduler(QiskitTestCase): | ||
"""Tests for scheduling.""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
qr = QuantumRegister(2, name="q") | ||
cr = ClassicalRegister(2, name="c") | ||
self.circ = QuantumCircuit(qr, cr, name="circ") | ||
self.circ.cx(qr[0], qr[1]) | ||
self.circ.measure(qr, cr) | ||
|
||
qr2 = QuantumRegister(2, name="q") | ||
cr2 = ClassicalRegister(2, name="c") | ||
self.circ2 = QuantumCircuit(qr2, cr2, name="circ2") | ||
self.circ2.cx(qr2[0], qr2[1]) | ||
self.circ2.measure(qr2, cr2) | ||
|
||
with self.assertWarns(DeprecationWarning): | ||
self.backend = GenericBackendV2( | ||
3, calibrate_instructions=True, basis_gates=["cx", "u1", "u2", "u3"], seed=42 | ||
) | ||
|
||
def test_instruction_map_and_backend_not_supplied(self): | ||
"""Test instruction map and backend not supplied.""" | ||
with self.assertRaisesRegex( | ||
QiskitError, | ||
r"Must supply either a backend or InstructionScheduleMap for scheduling passes.", | ||
): | ||
with self.assertWarns(DeprecationWarning): | ||
schedule(self.circ) | ||
|
||
def test_measurement_map_and_backend_not_supplied(self): | ||
"""Test measurement map and backend not supplied.""" | ||
with self.assertRaisesRegex( | ||
QiskitError, | ||
r"Must supply either a backend or a meas_map for scheduling passes.", | ||
): | ||
with self.assertWarns(DeprecationWarning): | ||
schedule(self.circ, inst_map=InstructionScheduleMap()) | ||
|
||
def test_schedules_single_circuit(self): | ||
"""Test scheduling of a single circuit.""" | ||
with self.assertWarns(DeprecationWarning): | ||
circuit_schedule = schedule(self.circ, self.backend) | ||
|
||
self.assertIsInstance(circuit_schedule, Schedule) | ||
self.assertEqual(circuit_schedule.name, "circ") | ||
|
||
def test_schedules_multiple_circuits(self): | ||
"""Test scheduling of multiple circuits.""" | ||
self.enable_parallel_processing() | ||
|
||
circuits = [self.circ, self.circ2] | ||
with self.assertWarns(DeprecationWarning): | ||
circuit_schedules = schedule(circuits, self.backend, method="asap") | ||
self.assertEqual(len(circuit_schedules), len(circuits)) | ||
|
||
circuit_one_schedule = circuit_schedules[0] | ||
circuit_two_schedule = circuit_schedules[1] | ||
|
||
with self.assertWarns(DeprecationWarning): | ||
self.assertEqual( | ||
circuit_one_schedule, | ||
schedule(self.circ, self.backend, method="asap"), | ||
) | ||
|
||
self.assertEqual( | ||
circuit_two_schedule, | ||
schedule(self.circ2, self.backend, method="asap"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2020, 2024. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
# pylint: disable=missing-function-docstring | ||
|
||
"""Tests basic functionality of the sequence function""" | ||
# TODO with the removal of pulses, this file can be removed too. | ||
|
||
import unittest | ||
|
||
from qiskit import QuantumCircuit, pulse | ||
from qiskit.compiler import sequence, transpile, schedule | ||
from qiskit.pulse.transforms import pad | ||
from qiskit.providers.fake_provider import Fake127QPulseV1 | ||
from test import QiskitTestCase # pylint: disable=wrong-import-order | ||
|
||
|
||
class TestSequence(QiskitTestCase): | ||
"""Test sequence function.""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
with self.assertWarns(DeprecationWarning): | ||
self.backend = Fake127QPulseV1() | ||
self.backend.configuration().timing_constraints = {} | ||
|
||
def test_sequence_empty(self): | ||
with self.assertWarns(DeprecationWarning): | ||
self.assertEqual(sequence([], self.backend), []) | ||
|
||
def test_transpile_and_sequence_agree_with_schedule(self): | ||
qc = QuantumCircuit(2, name="bell") | ||
qc.h(0) | ||
qc.cx(0, 1) | ||
qc.measure_all() | ||
with self.assertWarnsRegex( | ||
DeprecationWarning, | ||
expected_regex="The `transpile` function will " | ||
"stop supporting inputs of type `BackendV1`", | ||
): | ||
sc = transpile(qc, self.backend, scheduling_method="alap") | ||
with self.assertWarns(DeprecationWarning): | ||
actual = sequence(sc, self.backend) | ||
with self.assertWarnsRegex( | ||
DeprecationWarning, | ||
expected_regex="The `transpile` function will " | ||
"stop supporting inputs of type `BackendV1`", | ||
): | ||
expected = schedule(transpile(qc, self.backend), self.backend) | ||
with self.assertWarns(DeprecationWarning): | ||
# pad adds Delay which is deprecated | ||
self.assertEqual(actual, pad(expected)) | ||
|
||
def test_transpile_and_sequence_agree_with_schedule_for_circuit_with_delay(self): | ||
qc = QuantumCircuit(1, 1, name="t2") | ||
qc.h(0) | ||
qc.delay(500, 0, unit="ns") | ||
qc.h(0) | ||
qc.measure(0, 0) | ||
with self.assertWarnsRegex( | ||
DeprecationWarning, | ||
expected_regex="The `transpile` function will " | ||
"stop supporting inputs of type `BackendV1`", | ||
): | ||
sc = transpile(qc, self.backend, scheduling_method="alap") | ||
with self.assertWarns(DeprecationWarning): | ||
actual = sequence(sc, self.backend) | ||
with self.assertWarnsRegex( | ||
DeprecationWarning, | ||
expected_regex="The `transpile` function will " | ||
"stop supporting inputs of type `BackendV1`", | ||
): | ||
expected = schedule(transpile(qc, self.backend), self.backend) | ||
with self.assertWarns(DeprecationWarning): | ||
self.assertEqual( | ||
actual.exclude(instruction_types=[pulse.Delay]), | ||
expected.exclude(instruction_types=[pulse.Delay]), | ||
) | ||
|
||
@unittest.skip("not yet determined if delays on ancilla should be removed or not") | ||
def test_transpile_and_sequence_agree_with_schedule_for_circuits_without_measures(self): | ||
qc = QuantumCircuit(2, name="bell_without_measurement") | ||
qc.h(0) | ||
qc.cx(0, 1) | ||
with self.assertWarnsRegex( | ||
DeprecationWarning, | ||
expected_regex="The `transpile` function will " | ||
"stop supporting inputs of type `BackendV1`", | ||
): | ||
sc = transpile(qc, self.backend, scheduling_method="alap") | ||
with self.assertWarns(DeprecationWarning): | ||
actual = sequence(sc, self.backend) | ||
with self.assertWarnsRegex( | ||
DeprecationWarning, | ||
expected_regex="The `transpile` function will " | ||
"stop supporting inputs of type `BackendV1`", | ||
): | ||
with self.assertWarns(DeprecationWarning): | ||
expected = schedule(transpile(qc, self.backend), self.backend) | ||
self.assertEqual(actual, pad(expected)) |