Skip to content

Commit

Permalink
Fix return type from schedule() with a list of one entry (#7885) (#7889)
Browse files Browse the repository at this point in the history
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>
(cherry picked from commit 6192bfd)

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
  • Loading branch information
mergify[bot] and mtreinish authored Apr 5, 2022
1 parent fbe2bf2 commit 6796f40
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion qiskit/compiler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions test/python/scheduler/test_basic_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ def test_alap_pass(self):
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)
Expand Down

0 comments on commit 6796f40

Please sign in to comment.