140 lines
5.7 KiB
Plaintext
140 lines
5.7 KiB
Plaintext
---
|
||
title: DynamicalDecoupling (v0.29)
|
||
description: API reference for qiskit.transpiler.passes.DynamicalDecoupling in qiskit v0.29
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.transpiler.passes.DynamicalDecoupling
|
||
---
|
||
|
||
# DynamicalDecoupling
|
||
|
||
<Class id="qiskit.transpiler.passes.DynamicalDecoupling" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.18/qiskit/transpiler/passes/scheduling/dynamical_decoupling.py" signature="DynamicalDecoupling(*args, **kwargs)" modifiers="class">
|
||
Bases: `qiskit.transpiler.basepasses.TransformationPass`
|
||
|
||
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 ALAPSchedule, DynamicalDecoupling
|
||
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)]
|
||
)
|
||
```
|
||
|
||
```python
|
||
# balanced X-X sequence on all qubits
|
||
dd_sequence = [XGate(), XGate()]
|
||
pm = PassManager([ALAPSchedule(durations),
|
||
DynamicalDecoupling(durations, dd_sequence)])
|
||
circ_dd = pm.run(circ)
|
||
timeline_drawer(circ_dd)
|
||
```
|
||
|
||
![../\_images/qiskit.transpiler.passes.DynamicalDecoupling\_1\_0.png](/images/api/qiskit/0.29/qiskit.transpiler.passes.DynamicalDecoupling_1_0.png)
|
||
|
||
```python
|
||
# 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(
|
||
[
|
||
ALAPSchedule(durations),
|
||
DynamicalDecoupling(durations, dd_sequence, qubits=[0], spacing=spacing),
|
||
]
|
||
)
|
||
circ_dd = pm.run(circ)
|
||
timeline_drawer(circ_dd)
|
||
```
|
||
|
||
![../\_images/qiskit.transpiler.passes.DynamicalDecoupling\_2\_0.png](/images/api/qiskit/0.29/qiskit.transpiler.passes.DynamicalDecoupling_2_0.png)
|
||
|
||
Dynamical decoupling initializer.
|
||
|
||
**Parameters**
|
||
|
||
* **durations** ([*InstructionDurations*](qiskit.transpiler.InstructionDurations "qiskit.transpiler.InstructionDurations")) – Durations of instructions to be used in scheduling.
|
||
* **dd\_sequence** (*list\[*[*Gate*](qiskit.circuit.Gate "qiskit.circuit.Gate")*]*) – sequence of gates to apply in idle spots.
|
||
* **qubits** (*list\[int]*) – physical qubits on which to apply DD. If None, all qubits will undergo DD (when possible).
|
||
* **spacing** (*list\[float]*) – 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** (*bool*) – if True, does not insert DD on idle periods that immediately follow initialized/reset qubits (as qubits in the ground state are less susceptile to decoherence).
|
||
|
||
## Methods
|
||
|
||
<span id="qiskit-transpiler-passes-dynamicaldecoupling-name" />
|
||
|
||
### name
|
||
|
||
<Function id="qiskit.transpiler.passes.DynamicalDecoupling.name" signature="DynamicalDecoupling.name()">
|
||
Return the name of the pass.
|
||
</Function>
|
||
|
||
<span id="qiskit-transpiler-passes-dynamicaldecoupling-run" />
|
||
|
||
### run
|
||
|
||
<Function id="qiskit.transpiler.passes.DynamicalDecoupling.run" signature="DynamicalDecoupling.run(dag)">
|
||
Run the DynamicalDecoupling pass on dag.
|
||
|
||
**Parameters**
|
||
|
||
**dag** ([*DAGCircuit*](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")) – a scheduled DAG.
|
||
|
||
**Returns**
|
||
|
||
**equivalent circuit with delays interrupted by DD,**
|
||
|
||
where possible.
|
||
|
||
**Return type**
|
||
|
||
[DAGCircuit](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")
|
||
|
||
**Raises**
|
||
|
||
[**TranspilerError**](qiskit.transpiler.TranspilerError "qiskit.transpiler.TranspilerError") – if the circuit is not mapped on physical qubits.
|
||
</Function>
|
||
|
||
## Attributes
|
||
|
||
### is\_analysis\_pass
|
||
|
||
<Attribute id="qiskit.transpiler.passes.DynamicalDecoupling.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.DynamicalDecoupling.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>
|
||
</Class>
|
||
|