Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed Feb 5, 2025
1 parent e4e6ed0 commit d025c63
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 4 deletions.
2 changes: 1 addition & 1 deletion qiskit/providers/fake_provider/utils/backend_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def convert_to_target(conf_dict: dict, props_dict: dict = None) -> Target:
target.pulse_alignment = conf_dict["timing_constraints"].get("pulse_alignment")
target.acquire_alignment = conf_dict["timing_constraints"].get("acquire_alignment")
# If pulse defaults exists use that as the source of truth

target.add_instruction(
Delay(Parameter("t")), {(bit,): None for bit in range(target.num_qubits)}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ def generate_preset_pass_manager(
timing_constraints = _parse_timing_constraints(backend, timing_constraints)
# The basis gates parser will set _skip_target to True if a custom basis gate is found
# (known edge case).
basis_gates, name_mapping, _skip_target = _parse_basis_gates(
basis_gates, backend, _skip_target
)
basis_gates, name_mapping, _skip_target = _parse_basis_gates(basis_gates, backend, _skip_target)
coupling_map = _parse_coupling_map(coupling_map, backend)

if target is None:
Expand Down
92 changes: 92 additions & 0 deletions test/python/compiler/test_scheduler.py
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"),
)
109 changes: 109 additions & 0 deletions test/python/compiler/test_sequencer.py
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))

0 comments on commit d025c63

Please sign in to comment.