qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

Cannot schedule circuits using AerSimulator and QasmSimulator

Open zywang12 opened this issue 1 year ago • 5 comments

Environment

  • Qiskit version: 1.1.1
  • Python version: Python 3.12.4
  • Operating system: Ubuntu 22.04.3 LTS

What is happening?

AerSimulator and QasmSimulator cannot transpile most gates (except for barrier and id) when using the parameter scheduling_method='asap'. The following error message is displayed:

qiskit.transpiler.exceptions.TranspilerError: 'Duration of x on qubits [0] is not found.'

This is because the node.op.duration for these gates is set to None, whereas barrier and id gates have a duration value of 0.

How can we reproduce the issue?

from qiskit.circuit import QuantumCircuit
from qiskit import transpile

qc = QuantumCircuit(1)
# qc.id(0)      # The value of node.op.duration is 0
# qc.barrier()  # The value of node.op.duration is 0
qc.x(0)         # The value of node.op.duration is None
qc.measure_all()# The value of node.op.duration is None

from qiskit_aer import AerSimulator, QasmSimulator
backend1 = AerSimulator() # Failed
# backend2 = QasmSimulator() # Failed

qc1 = transpile(qc, optimization_level=1, backend=backend1, scheduling_method='asap')

What should happen?

Assigning default values to all gates would be better.

Any suggestions?

No response

zywang12 avatar Aug 10 '24 14:08 zywang12

As you've also pointed out in the description, these are simulators and don't have a concept of gate durations. If you're looking for an emulation of a real device, you can use a fake backend. For example

from qiskit.circuit import QuantumCircuit
from qiskit import transpile
from qiskit_ibm_runtime.fake_provider import FakeSherbrooke

qc = QuantumCircuit(1)
# qc.id(0)      # The value of node.op.duration is 0
# qc.barrier()  # The value of node.op.duration is 0
qc.x(0)         # The value of node.op.duration is None
qc.measure_all()# The value of node.op.duration is None

backend = FakeSherbrooke()

qc = transpile(qc, optimization_level=1, backend=backend, scheduling_method='asap')

Cryoris avatar Aug 15 '24 12:08 Cryoris

It might be nice to add a suggestion to use a fake backend in the error message.

t-imamichi avatar Aug 16 '24 07:08 t-imamichi

It would, but that might be a too specific error message, as not finding the duration of a gate could have other reasons... If there's a way to check whether a given target comes from a simulator we could add such a warning in the scheduling passes, but I don't know if it's possible to know that.

Cryoris avatar Aug 16 '24 07:08 Cryoris

I see. Duration could miss due to other reasons.

t-imamichi avatar Aug 16 '24 08:08 t-imamichi

We could potentially add a warning/error if the target durations are completely empty, in which case there's no way we can schedule a (non-empty) circuit 🤔

Cryoris avatar Aug 16 '24 08:08 Cryoris