This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
/
pad_delay.py
78 lines (60 loc) · 2.73 KB
/
pad_delay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""Padding pass to insert Delay into empty timeslots for dynamic circuit backends."""
from qiskit.circuit import Qubit
from qiskit.circuit.delay import Delay
from qiskit.dagcircuit import DAGNode, DAGOutNode
from .block_base_padder import BlockBasePadder
class PadDelay(BlockBasePadder):
"""Padding idle time with Delay instructions.
Consecutive delays will be merged in the output of this pass.
.. code-block::python
durations = InstructionDurations([("x", None, 160), ("cx", None, 800)])
qc = QuantumCircuit(2)
qc.delay(100, 0)
qc.x(1)
qc.cx(0, 1)
The ASAP-scheduled circuit output may become
.. parsed-literal::
┌────────────────┐
q_0: ┤ Delay(160[dt]) ├──■──
└─────┬───┬──────┘┌─┴─┐
q_1: ──────┤ X ├───────┤ X ├
└───┘ └───┘
Note that the additional idle time of 60dt on the ``q_0`` wire coming from the duration difference
between ``Delay`` of 100dt (``q_0``) and ``XGate`` of 160 dt (``q_1``) is absorbed in
the delay instruction on the ``q_0`` wire, i.e. in total 160 dt.
See :class:`BlockBasePadder` pass for details.
"""
def __init__(self, fill_very_end: bool = True, schedule_idle_qubits: bool = False):
"""Create new padding delay pass.
Args:
fill_very_end: Set ``True`` to fill the end of circuit with delay.
schedule_idle_qubits: Set to true if you'd like a delay inserted on idle qubits.
This is useful for timeline visualizations, but may cause issues for execution
on large backends.
"""
super().__init__(schedule_idle_qubits=schedule_idle_qubits)
self.fill_very_end = fill_very_end
def _pad(
self,
block_idx: int,
qubit: Qubit,
t_start: int,
t_end: int,
next_node: DAGNode,
prev_node: DAGNode,
) -> None:
if not self.fill_very_end and isinstance(next_node, DAGOutNode):
return
time_interval = t_end - t_start
self._apply_scheduled_op(block_idx, t_start, Delay(time_interval, "dt"), qubit)