このページはまだ翻訳されていません。英語の原文を表示しています。
Write a custom transpiler pass
Package versions
The code on this page was developed using the following requirements. We recommend using these versions or newer.
qiskit[all]~=2.3.0
The Qiskit SDK lets you create custom transpilation passes and run them in the PassManager object or add them to a StagedPassManager. Here we will demonstrate how to write a transpiler pass, focusing on building a pass that performs Pauli twirling on the noisy quantum gates in a quantum circuit. This example uses the DAG, which is the object manipulated by the TransformationPass type of pass.
Background: DAG representation
Before building a pass, it is important to introduce the internal representation of quantum circuits in Qiskit, the directed acyclic graph (DAG) (see this tutorial for an overview). To follow these steps, install the graphviz library for the DAG plotting functions.
In Qiskit, within the transpilation stages, circuits are represented using a DAG. In general, a DAG is composed of vertices (also known as "nodes") and directed edges that connect pairs of vertices in a particular orientation. This representation is stored using qiskit.dagcircuit.DAGCircuit objects that are composed of individual DagNode objects. The advantage of this representation over a pure list of gates (that is, a netlist) is that the flow of information between operations is explicit, making it easier to make transformation decisions.
This example illustrates the DAG by creating a simple circuit that prepares a Bell state and applies an