Skip to content
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

Treat Reset like Measure in ConstrainedReschedule #11756

Merged
merged 7 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from qiskit.circuit.gate import Gate
from qiskit.circuit.delay import Delay
from qiskit.circuit.measure import Measure
from qiskit.circuit.reset import Reset
from qiskit.dagcircuit import DAGCircuit, DAGOpNode, DAGOutNode
from qiskit.transpiler.basepasses import AnalysisPass
from qiskit.transpiler.exceptions import TranspilerError
Expand Down Expand Up @@ -113,7 +114,7 @@ def _push_node_back(self, dag: DAGCircuit, node: DAGOpNode):

if isinstance(node.op, Gate):
alignment = self.pulse_align
elif isinstance(node.op, Measure):
elif isinstance(node.op, (Measure, Reset)):
alignment = self.acquire_align
elif isinstance(node.op, Delay) or getattr(node.op, "_directive", False):
# Directive or delay. These can start at arbitrary time.
Expand All @@ -135,7 +136,7 @@ def _push_node_back(self, dag: DAGCircuit, node: DAGOpNode):
# Compute shifted t1 of this node separately for qreg and creg
new_t1q = this_t0 + node.op.duration
this_qubits = set(node.qargs)
if isinstance(node.op, Measure):
if isinstance(node.op, (Measure, Reset)):
# creg access ends at the end of instruction
new_t1c = new_t1q
this_clbits = set(node.cargs)
Expand All @@ -153,7 +154,7 @@ def _push_node_back(self, dag: DAGCircuit, node: DAGOpNode):
# Compute next node start time separately for qreg and creg
next_t0q = node_start_time[next_node]
next_qubits = set(next_node.qargs)
if isinstance(next_node.op, Measure):
if isinstance(next_node.op, (Measure, Reset)):
# creg access starts after write latency
next_t0c = next_t0q + clbit_write_latency
next_clbits = set(next_node.cargs)
Expand Down
21 changes: 19 additions & 2 deletions qiskit/transpiler/passes/scheduling/base_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from qiskit.transpiler import InstructionDurations
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.passes.scheduling.time_unit_conversion import TimeUnitConversion
from qiskit.dagcircuit import DAGOpNode, DAGCircuit
from qiskit.circuit import Delay, Gate
from qiskit.dagcircuit import DAGOpNode, DAGCircuit, DAGOutNode
from qiskit.circuit import Delay, Gate, Measure, Reset
from qiskit.circuit.parameterexpression import ParameterExpression
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.target import Target
Expand Down Expand Up @@ -269,6 +269,23 @@ def _get_node_duration(
else:
duration = node.op.duration

if isinstance(node.op, Reset):
raise RuntimeWarning(
hunterkemeny marked this conversation as resolved.
Show resolved Hide resolved
"Qiskit scheduler assumes Reset works similarly to Measure instruction. "
"Actual behavior depends on the control system of your quantum backend. "
"Your backend may provide a plugin scheduler pass."
)
elif isinstance(node.op, Measure):
is_mid_circuit = not any(
isinstance(x, DAGOutNode) for x in dag.quantum_successors(node)
)
if is_mid_circuit:
raise RuntimeWarning(
"Qiskit scheduler assumes mid-circuit measurement works as a standard instruction. "
"Actual backend may apply custom scheduling. "
"Your backend may provide a plugin scheduler pass."
)

if isinstance(duration, ParameterExpression):
raise TranspilerError(
f"Parameterized duration ({duration}) "
Expand Down
11 changes: 11 additions & 0 deletions releasenotes/notes/add-scheduler-warnings-da6968a39fd8e6e7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fixes:
- |
Fixed an issue where the :class:`.ConstrainedReschedule` transpiler pass would previously error
if the circuit contained a :class:`~.circuit.Reset` instruction. This has been corrected so that the
pass no longer errors, however an actual hardware may behave differently from
what Qiskit scheduler assumes especially for
mid-circuit measurements and resets.
Qiskit scheduler raises ``RuntimeWarning`` if
it encounters circuit containing either.
Fixed `#10354 <https://github.com/Qiskit/qiskit/issues/10354>`__

Loading