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.26k stars 2.37k forks source link

Delay (sorry, again) #6678

Open yaelbh opened 3 years ago

yaelbh commented 3 years ago

Information

What is the current behavior?

I've updated my Terra clone with the latest version, which includes the new pass. Still some circuits don't run correctly. I don't know if it's still related to the delay instruction.

Steps to reproduce the problem

Consider the code:

from qiskit import IBMQ, QuantumCircuit, execute

provider = IBMQ.load_account()
backend = provider.backend.ibmq_lima
delays = [5, 50, 100, 150, 200]

circs = []
for d in delays:
    circ = QuantumCircuit(1, 1)
    circ.x(0)
    circ.barrier()
    circ.delay(d, 0, unit="us")
    circ.barrier()
    circ.measure(0, 0)
    circs.append(circ)

res = execute(circs, backend).result()

print("Counts of ground state:")
for i, d in enumerate(delays):
    print(res.get_counts(i).get('0', 0), end=" ")
print("")

It works well:

Counts of ground state:
126 390 590 714 799

But when I change the delays to

delays = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195]

Everything gets stuck in the ground state:

Counts of ground state:
1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024

Is there a limitation on the number of circuits?

nkanazawa1989 commented 3 years ago

Oh I found alignment is missing in the execute function. We need to update this.

yaelbh commented 3 years ago

execute is not updated anymore. Users need to set transpiler options to alignment=16, scheduling_method="alap". How do we make every user using delay know this? Especially considering that no error is triggered, so users may not know that the delay was no performed.

nkanazawa1989 commented 3 years ago

I think now backends report alignment and users don't need to take care of it This is not reported yet. If you execute some circuit with delay on a backend reporting the alignment value, transpiler raises an error to ask one to set scheduling option. The problem here is we cannot pass this option from the execute API. Do we want to update execute @ajavadia ?

nkanazawa1989 commented 3 years ago

Sorry I misunderstood. execute can take scheduling_method. Users can get transpiler error and one can set scheduling_method to execute. I think this issue can be closed.

nkanazawa1989 commented 3 years ago

Backend will report alignment value in few weeks, so please keep this issue open until we get alignment from backend configuration. Then you can get proper error message when you try to run circuits with invalid delay.

yaelbh commented 3 years ago

Here's a summary of what I understand will be the situation in a few weeks:

  1. Circuits with delay instructions will have to be transpiled with scheduling_method set to something.
  2. If scheduling_method is not set, the transpiler triggers an error message, which recommends to set scheduling_method to alap.

We should consider automatically setting scheduling_method to alap (if it's not set by the user), and probably report this behind-the-scenes activity in the screen or log.

Note that, following #6460, we will sometimes see the same behavior also in circuits that don't contain delay instructions.

yaelbh commented 3 years ago

Regarding #6460, if the delays are multiple of 16 dt then there will probably be no error

zlatko-minev commented 3 years ago

Just checking back in, would this issue resolved now on the cloud systems?