198 lines
9.9 KiB
Plaintext
198 lines
9.9 KiB
Plaintext
---
|
||
title: PadDynamicalDecoupling (latest version)
|
||
description: API reference for qiskit.transpiler.passes.PadDynamicalDecoupling in the latest version of qiskit
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.transpiler.passes.PadDynamicalDecoupling
|
||
---
|
||
|
||
# PadDynamicalDecoupling
|
||
|
||
<Class id="qiskit.transpiler.passes.PadDynamicalDecoupling" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py#L36-L431" signature="qiskit.transpiler.passes.PadDynamicalDecoupling(*args, **kwargs)" modifiers="class">
|
||
Bases: `BasePadding`
|
||
|
||
Dynamical decoupling insertion pass.
|
||
|
||
This pass works on a scheduled, physical circuit. It scans the circuit for idle periods of time (i.e. those containing delay instructions) and inserts a DD sequence of gates in those spots. These gates amount to the identity, so do not alter the logical action of the circuit, but have the effect of mitigating decoherence in those idle periods.
|
||
|
||
As a special case, the pass allows a length-1 sequence (e.g. `[XGate()]`). In this case the DD insertion happens only when the gate inverse can be absorbed into a neighboring gate in the circuit (so we would still be replacing Delay with something that is equivalent to the identity). This can be used, for instance, as a Hahn echo.
|
||
|
||
This pass ensures that the inserted sequence preserves the circuit exactly (including global phase).
|
||
|
||
```python
|
||
import numpy as np
|
||
from qiskit.circuit import QuantumCircuit
|
||
from qiskit.circuit.library import XGate
|
||
from qiskit.transpiler import PassManager, InstructionDurations
|
||
from qiskit.transpiler.passes import ALAPScheduleAnalysis, PadDynamicalDecoupling
|
||
from qiskit.visualization import timeline_drawer
|
||
circ = QuantumCircuit(4)
|
||
circ.h(0)
|
||
circ.cx(0, 1)
|
||
circ.cx(1, 2)
|
||
circ.cx(2, 3)
|
||
circ.measure_all()
|
||
durations = InstructionDurations(
|
||
[("h", 0, 50), ("cx", [0, 1], 700), ("reset", None, 10),
|
||
("cx", [1, 2], 200), ("cx", [2, 3], 300),
|
||
("x", None, 50), ("measure", None, 1000)]
|
||
)
|
||
|
||
# balanced X-X sequence on all qubits
|
||
dd_sequence = [XGate(), XGate()]
|
||
pm = PassManager([ALAPScheduleAnalysis(durations),
|
||
PadDynamicalDecoupling(durations, dd_sequence)])
|
||
circ_dd = pm.run(circ)
|
||
timeline_drawer(circ_dd)
|
||
|
||
# Uhrig sequence on qubit 0
|
||
n = 8
|
||
dd_sequence = [XGate()] * n
|
||
def uhrig_pulse_location(k):
|
||
return np.sin(np.pi * (k + 1) / (2 * n + 2)) ** 2
|
||
spacing = []
|
||
for k in range(n):
|
||
spacing.append(uhrig_pulse_location(k) - sum(spacing))
|
||
spacing.append(1 - sum(spacing))
|
||
pm = PassManager(
|
||
[
|
||
ALAPScheduleAnalysis(durations),
|
||
PadDynamicalDecoupling(durations, dd_sequence, qubits=[0], spacing=spacing),
|
||
]
|
||
)
|
||
circ_dd = pm.run(circ)
|
||
timeline_drawer(circ_dd)
|
||
```
|
||
|
||
![../\_images/qiskit-transpiler-passes-PadDynamicalDecoupling-1\_00.png](/images/api/qiskit/qiskit-transpiler-passes-PadDynamicalDecoupling-1_00.png)
|
||
|
||
![../\_images/qiskit-transpiler-passes-PadDynamicalDecoupling-1\_01.png](/images/api/qiskit/qiskit-transpiler-passes-PadDynamicalDecoupling-1_01.png)
|
||
|
||
<Admonition title="Note" type="note">
|
||
You may need to call alignment pass before running dynamical decoupling to guarantee your circuit satisfies acquisition alignment constraints.
|
||
</Admonition>
|
||
|
||
Dynamical decoupling initializer.
|
||
|
||
**Parameters**
|
||
|
||
* **durations** – Durations of instructions to be used in scheduling.
|
||
|
||
* **dd\_sequence** – Sequence of gates to apply in idle spots.
|
||
|
||
* **qubits** – Physical qubits on which to apply DD. If None, all qubits will undergo DD (when possible).
|
||
|
||
* **spacing** – A list of spacings between the DD gates. The available slack will be divided according to this. The list length must be one more than the length of dd\_sequence, and the elements must sum to 1. If None, a balanced spacing will be used \[d/2, d, d, …, d, d, d/2].
|
||
|
||
* **skip\_reset\_qubits** – If True, does not insert DD on idle periods that immediately follow initialized/reset qubits (as qubits in the ground state are less susceptible to decoherence).
|
||
|
||
* **pulse\_alignment** – The hardware constraints for gate timing allocation. This is usually provided from `backend.configuration().timing_constraints`. If provided, the delay length, i.e. `spacing`, is implicitly adjusted to satisfy this constraint.
|
||
|
||
* **extra\_slack\_distribution** –
|
||
|
||
The option to control the behavior of DD sequence generation. The duration of the DD sequence should be identical to an idle time in the scheduled quantum circuit, however, the delay in between gates comprising the sequence should be integer number in units of dt, and it might be further truncated when `pulse_alignment` is specified. This sometimes results in the duration of the created sequence being shorter than the idle time that you want to fill with the sequence, i.e. extra slack. This option takes following values.
|
||
|
||
> * ”middle”: Put the extra slack to the interval at the middle of the sequence.
|
||
> * ”edges”: Divide the extra slack as evenly as possible into intervals at beginning and end of the sequence.
|
||
|
||
* **target** – The [`Target`](qiskit.transpiler.Target "qiskit.transpiler.Target") representing the target backend. Target takes precedence over other arguments when they can be inferred from target. Therefore specifying target as well as other arguments like `durations` or `pulse_alignment` will cause those other arguments to be ignored.
|
||
|
||
**Raises**
|
||
|
||
* [**TranspilerError**](transpiler#qiskit.transpiler.TranspilerError "qiskit.transpiler.TranspilerError") – When invalid DD sequence is specified.
|
||
* [**TranspilerError**](transpiler#qiskit.transpiler.TranspilerError "qiskit.transpiler.TranspilerError") – When pulse gate with the duration which is non-multiple of the alignment constraint value is found.
|
||
* [**TypeError**](https://docs.python.org/3/library/exceptions.html#TypeError "(in Python v3.13)") – If `dd_sequence` is not specified
|
||
|
||
## Attributes
|
||
|
||
### is\_analysis\_pass
|
||
|
||
<Attribute id="qiskit.transpiler.passes.PadDynamicalDecoupling.is_analysis_pass">
|
||
Check if the pass is an analysis pass.
|
||
|
||
If the pass is an AnalysisPass, that means that the pass can analyze the DAG and write the results of that analysis in the property set. Modifications on the DAG are not allowed by this kind of pass.
|
||
</Attribute>
|
||
|
||
### is\_transformation\_pass
|
||
|
||
<Attribute id="qiskit.transpiler.passes.PadDynamicalDecoupling.is_transformation_pass">
|
||
Check if the pass is a transformation pass.
|
||
|
||
If the pass is a TransformationPass, that means that the pass can manipulate the DAG, but cannot modify the property set (but it can be read).
|
||
</Attribute>
|
||
|
||
## Methods
|
||
|
||
### execute
|
||
|
||
<Function id="qiskit.transpiler.passes.PadDynamicalDecoupling.execute" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/basepasses.py#L189-L211" signature="execute(passmanager_ir, state, callback=None)">
|
||
Execute optimization task for input Qiskit IR.
|
||
|
||
**Parameters**
|
||
|
||
* **passmanager\_ir** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.13)")) – Qiskit IR to optimize.
|
||
* **state** ([*PassManagerState*](qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")) – State associated with workflow execution by the pass manager itself.
|
||
* **callback** ([*Callable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable "(in Python v3.13)") *| None*) – A callback function which is caller per execution of optimization task.
|
||
|
||
**Returns**
|
||
|
||
Optimized Qiskit IR and state of the workflow.
|
||
|
||
**Return type**
|
||
|
||
[tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)")\[[*Any*](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.13)"), [qiskit.passmanager.compilation\_status.PassManagerState](qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")]
|
||
</Function>
|
||
|
||
### name
|
||
|
||
<Function id="qiskit.transpiler.passes.PadDynamicalDecoupling.name" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/passmanager/base_tasks.py#L68-L70" signature="name()">
|
||
Name of the pass.
|
||
|
||
**Return type**
|
||
|
||
[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")
|
||
</Function>
|
||
|
||
### run
|
||
|
||
<Function id="qiskit.transpiler.passes.PadDynamicalDecoupling.run" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/passes/scheduling/padding/base_padding.py#L71-L166" signature="run(dag)">
|
||
Run the padding pass on `dag`.
|
||
|
||
**Parameters**
|
||
|
||
**dag** ([*DAGCircuit*](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.dagcircuit.DAGCircuit")) – DAG to be checked.
|
||
|
||
**Returns**
|
||
|
||
DAG with idle time filled with instructions.
|
||
|
||
**Return type**
|
||
|
||
[DAGCircuit](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")
|
||
|
||
**Raises**
|
||
|
||
[**TranspilerError**](transpiler#qiskit.transpiler.TranspilerError "qiskit.transpiler.TranspilerError") – When a particular node is not scheduled, likely some transform pass is inserted before this node is called.
|
||
</Function>
|
||
|
||
### update\_status
|
||
|
||
<Function id="qiskit.transpiler.passes.PadDynamicalDecoupling.update_status" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/basepasses.py#L213-L221" signature="update_status(state, run_state)">
|
||
Update workflow status.
|
||
|
||
**Parameters**
|
||
|
||
* **state** ([*PassManagerState*](qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")) – Pass manager state to update.
|
||
* **run\_state** (*RunState*) – Completion status of current task.
|
||
|
||
**Returns**
|
||
|
||
Updated pass manager state.
|
||
|
||
**Return type**
|
||
|
||
[*PassManagerState*](qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")
|
||
</Function>
|
||
</Class>
|
||
|