mirror of https://github.com/Qiskit/qiskit.git
Fix return type from schedule() with a list of one entry (#7885)
This commit fixes the return type when calling schedule() with a list of a single entry. Previously this would return a single Schedule object instead of the expected list return. A similar issue was already fixed in transpile() in #5298 but schedule still had the incorrect behavior. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
d430e4d259
commit
6192bfd529
|
@ -65,6 +65,7 @@ def schedule(
|
|||
Raises:
|
||||
QiskitError: If ``inst_map`` and ``meas_map`` are not passed and ``backend`` is not passed
|
||||
"""
|
||||
arg_circuits_list = isinstance(circuits, list)
|
||||
start_time = time()
|
||||
if backend and getattr(backend, "version", 0) > 1:
|
||||
if inst_map is None:
|
||||
|
@ -100,4 +101,7 @@ def schedule(
|
|||
schedules = [schedule_circuit(circuit, schedule_config, method) for circuit in circuits]
|
||||
end_time = time()
|
||||
_log_schedule_time(start_time, end_time)
|
||||
return schedules[0] if len(schedules) == 1 else schedules
|
||||
if arg_circuits_list:
|
||||
return schedules
|
||||
else:
|
||||
return schedules[0]
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed an issue with the :class:`~qiskit.compiler.schedule` function where
|
||||
previously passing in a ``list`` of :class:`~qiskit.circuit.QuantumCircuit`
|
||||
objects with a single entry would incorrectly return a single
|
||||
:class:`~.Schedule` object instead of the expected ``list`` return type.
|
|
@ -82,6 +82,16 @@ class TestBasicSchedule(QiskitTestCase):
|
|||
self.assertEqual(actual[0], expected[0])
|
||||
self.assertEqual(actual[1], expected[1])
|
||||
|
||||
def test_single_circuit_list_schedule(self):
|
||||
"""Test that passing a single circuit list to schedule() returns a list."""
|
||||
q = QuantumRegister(2)
|
||||
c = ClassicalRegister(2)
|
||||
qc = QuantumCircuit(q, c)
|
||||
sched = schedule([qc], self.backend, method="alap")
|
||||
expected = Schedule()
|
||||
self.assertIsInstance(sched, list)
|
||||
self.assertEqual(sched[0].instructions, expected.instructions)
|
||||
|
||||
def test_alap_with_barriers(self):
|
||||
"""Test that ALAP respects barriers on new qubits."""
|
||||
q = QuantumRegister(2)
|
||||
|
|
Loading…
Reference in New Issue