Skip to content

Commit

Permalink
Fix bug: execute valid circuits built with delays (#5302)
Browse files Browse the repository at this point in the history
* Fix bug where execute would raise an error for valid circuits built with delays

* Remove unused function

* Fixup style: unused import

* Update broken test
  • Loading branch information
lcapelluto authored Oct 28, 2020
1 parent f9a59ca commit 6c052ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
28 changes: 0 additions & 28 deletions qiskit/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"""
import logging
from time import time
from qiskit.circuit import QuantumCircuit
from qiskit.compiler import transpile, assemble, schedule
from qiskit.providers import BaseBackend
from qiskit.providers.backend import Backend
Expand Down Expand Up @@ -249,14 +248,6 @@ def execute(experiments, backend,
initial_layout=initial_layout)
experiments = pass_manager.run(experiments)
else:
if 'delay' not in backend.configuration().basis_gates and _any_delay_in(experiments):
if schedule_circuit and backend.configuration().open_pulse:
pass # the delay will be handled in the Pulse schedule
else:
raise QiskitError("Backend {} does not support delay instruction. "
"Use 'schedule_circuit=True' for pulse-enabled backends."
.format(backend.name()))

# transpiling the circuits using given transpile options
experiments = transpile(experiments,
basis_gates=basis_gates,
Expand Down Expand Up @@ -332,22 +323,3 @@ def _check_conflicting_argument(**kargs):
if conflicting_args:
raise QiskitError("The parameters pass_manager conflicts with the following "
"parameter(s): {}.".format(', '.join(conflicting_args)))


def _any_delay_in(circuits):
"""Check if the circuits have any delay instruction.
Args:
circuits (QuantumCircuit or list[QuantumCircuit]): Circuits to be checked
Returns:
bool: True if there is any delay in either of the circuit, otherwise False.
"""
if isinstance(circuits, QuantumCircuit):
circuits = [circuits]
has_delay = False
for qc in circuits:
if 'delay' in qc.count_ops():
has_delay = True
break
return has_delay
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed an issue where an error was thrown in execute for valid circuits
built with delays.
5 changes: 2 additions & 3 deletions test/python/circuit/test_scheduled_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,12 @@ def test_cannot_schedule_circuit_with_mixed_SI_and_dt_when_no_one_tells_dt(self)
with self.assertRaises(QiskitError):
transpile(qc, self.backend_without_dt, scheduling_method='alap')

def test_cannot_execute_delay_circuit_when_schedule_circuit_off(self):
def test_can_execute_delay_circuit_when_schedule_circuit_off(self):
qc = QuantumCircuit(2)
qc.h(0)
qc.delay(500, 1)
qc.cx(0, 1)
with self.assertRaises(QiskitError):
execute(qc, backend=self.backend_with_dt, schedule_circuit=False)
execute(qc, backend=self.backend_with_dt, schedule_circuit=False)

def test_transpile_single_delay_circuit(self):
qc = QuantumCircuit(1)
Expand Down

0 comments on commit 6c052ce

Please sign in to comment.