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

Fix error message upon misalignment in PadDynamicalDecoupling #12952

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -20,7 +20,7 @@
from qiskit.circuit.delay import Delay
from qiskit.circuit.library.standard_gates import IGate, UGate, U3Gate
from qiskit.circuit.reset import Reset
from qiskit.dagcircuit import DAGCircuit, DAGNode, DAGInNode, DAGOpNode
from qiskit.dagcircuit import DAGCircuit, DAGNode, DAGInNode, DAGOpNode, DAGOutNode
from qiskit.quantum_info.operators.predicates import matrix_equal
from qiskit.synthesis.one_qubit import OneQubitEulerDecomposer
from qiskit.transpiler.exceptions import TranspilerError
Expand Down Expand Up @@ -331,8 +331,7 @@ def _pad(
if time_interval % self._alignment != 0:
raise TranspilerError(
f"Time interval {time_interval} is not divisible by alignment {self._alignment} "
f"between DAGNode {prev_node.name} on qargs {prev_node.qargs} and {next_node.name} "
f"on qargs {next_node.qargs}."
f"between {_format_node(prev_node)} and {_format_node(next_node)}."
)

if not self.__is_dd_qubit(dag.qubits.index(qubit)):
Expand Down Expand Up @@ -430,3 +429,10 @@ def _resolve_params(gate: Gate) -> tuple:
else:
params.append(p)
return tuple(params)


def _format_node(node: DAGNode) -> str:
"""Util to format the DAGNode, DAGInNode, and DAGOutNode."""
if isinstance(node, (DAGInNode, DAGOutNode)):
return f"{node.__class__.__name__} on qarg {node.wire}"
return f"DAGNode {node.name} on qargs {node.qargs}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Fixed a bug in :class:`.PadDynamicalDecoupling`, which previously
did not correctly display the error message that a delay is not
pulse-aligned, if the previous or following node was an input/output
node. Now, the error message is correctly displayed.
17 changes: 17 additions & 0 deletions test/python/transpiler/test_dynamical_decoupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,23 @@ def test_paramaterized_global_phase(self):

self.assertEqual(qc.global_phase + np.pi, pm.run(qc).global_phase)

def test_misalignment_at_boundaries(self):
"""Test the correct error message is raised for misalignments at In/Out nodes."""
# a circuit where the previous node is DAGInNode, and the next DAGOutNode
circuit = QuantumCircuit(1)
circuit.delay(101)

dd_sequence = [XGate(), XGate()]
pm = PassManager(
[
ALAPScheduleAnalysis(self.durations),
PadDynamicalDecoupling(self.durations, dd_sequence, pulse_alignment=2),
]
)

with self.assertRaises(TranspilerError):
_ = pm.run(circuit)


if __name__ == "__main__":
unittest.main()
Loading