-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ALAP/ASAP scheduler produces incorrect delays for circuits with classically controlled gates #7006
Comments
Thanks for reporting this @Lolcroc , agree this is a bug. The |
This also happens for measurements after measurements (not just conditional gates). In the following example, ASAP schedules measurement on qubit 1 before qubit 0:
The suggested solution should fix both cases. |
I've started working on this and recognized fixing the spec of ASAP/ALAP scheduler for circuits touching classical registers is more complicated than I thought. As far as I understand, in typical backends, Considering the above, the following spec (shown by examples) makes most sense to me.
I also think we should describe that the ASAP/ALAP scheduler may not schedule instructions exactly the same as any real backend does (especially when the circuit has conditional instructions) in docstring. |
I think this makes sense, and will fix the problem of out-of-order scheduling. Considering the clbits jointly locked for the duration of the instruction also seems reasonable to me (though maybe unnecessarily defensive). Maybe @taalexander has some thoughts on how to best model the duration of classical operations and their corresponding latencies , and how the calculated delays will impact the backends.
In this example, do both measurements start at 0, or is one at 0 and one at 1000? I could see an argument for both starting at 0 (in that the result of the first measurement will be unconditionally overwritten by the second), but worry slightly about this introducing race-conditions (if both are scheduled to start at 0, and the second finishes slightly earlier, or communicates its result to clbit 0 slightly earlier, the result of the first measure would persist instead of the second). |
In practice, this depends on how the backend implements conditional operators. There could be latencies following conditional operations, Qiskit is treating scheduling very naively. There are many questions about the qiskit scheduling model that must be answered surrounding control-flow, eg., what if value calculations or decision durations are indeterministic, how does scheduling work? It seems there are two types of control-flow that would be desired - control-flow and calculations with decidable and deterministic outcomes (such as the case of doing dynamical decoupling while calculating a future decision, instead of sitting idle) as well as more sophisticated constructs that do not obey this constraint. On IBM backends, we merge together measurements on common qubits that are not dominated by other intervening quantum operations under topological ordering. This is due to triggering requirements in hardware which is difficult to communicate to the scheduling layer (and therefore it does not capture). Other hardware might have different requirements or even optimize away the first measurement statement since it is redundant. |
[race condition?] ["both start at 0" or "one at 0 and one at 1000"] |
* Add condition_bits to Instruction * Fix a bug in schduling of circuits using clbits * Fix small bugs, style and lint * Update docstrings to tell the limitation of schedulers * Add release note * Update docstrings * Replace with more robust assertions * Update test/python/transpiler/test_instruction_alignments.py Co-authored-by: Luciano Bello <bel@zurich.ibm.com> Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com> Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Information
What is the current behavior?
The ALAP and ASAP schedulers give wrong delays for circuits with gates with a classical condition. This is because the passes do not respect topological order of classical bit lines, which they should.
Steps to reproduce the problem
What is the expected behavior?
The passes need to insert delays on qubits with gates conditioned on classical bits, such that those gates are always done later than the measurement producing the classical bit outcome. The correct topological order for conditional gates is already present in the DAGCircuit, so one should only need to fix the passes.
Suggested solutions
Treat qubits and clbits on equal footing. This means variables such as
qubit_time_available
in the passrun
method should keep track of time for clbits too.The text was updated successfully, but these errors were encountered: