Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.05k stars 2.33k forks source link

Cannot schedule circuits using AerSimulator and QasmSimulator #12939

Open zywang12 opened 1 month ago

zywang12 commented 1 month ago

Environment

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

Cryoris commented 1 month ago

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')
t-imamichi commented 1 month ago

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

Cryoris commented 1 month ago

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.

t-imamichi commented 1 month ago

I see. Duration could miss due to other reasons.

Cryoris commented 1 month ago

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 🤔