Skip to content

Commit

Permalink
Minor typo cleanup in transpile section (Qiskit#585)
Browse files Browse the repository at this point in the history
Came across some little fixes.
  • Loading branch information
abbycross authored Jan 5, 2024
1 parent f07c929 commit c16dd6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 12 additions & 5 deletions docs/transpile/custom-transpiler-pass.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@
"source": [
"# Write a custom transpiler pass\n",
"\n",
"Qiskit lets you create custom transpilation passes and run them in the `PassManager` object or add them to a `StagedPassMager`. Here we will demonstrate how to write a transpiler pass, focusing on building a pass that performs [Pauli twirling](https://arxiv.org/abs/quant-ph/0606161) 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.\n"
"Qiskit 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](https://arxiv.org/abs/quant-ph/0606161) 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.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<details>\n",
" <summary>\n",
" Background: DAG Representation\n",
" Background: DAG representation\n",
" </summary>\n",
"\n",
"Before building a pass it is important to introduce the internal representation of quantum circuits in Qiskit, the [directed acyclic graph (DAG)](../api/qiskit/qiskit.dagcircuit.DAGCircuit) (see [this tutorial](https://qiskit.org/ecosystem/rustworkx/tutorial/dags.html) for an overview). To follow these steps, install the `graphivz` library for the DAG plotting functions. Use a python package manager (such as `pip` or `conda`) to install `pydot` and your system's native package manager (for example, `apt`, `brew`, `yum`, or `dnf`) for `graphivz`.\n",
"Before building a pass it is important to introduce the internal representation of quantum circuits in Qiskit, the [directed acyclic graph (DAG)](../api/qiskit/qiskit.dagcircuit.DAGCircuit) (see [this tutorial](https://qiskit.org/ecosystem/rustworkx/tutorial/dags.html) for an overview). To follow these steps, install the `graphivz` library for the DAG plotting functions. Use a Python package manager (such as `pip` or `conda`) to install `pydot` and your system's native package manager (for example, `apt`, `brew`, `yum`, or `dnf`) for `graphivz`.\n",
"\n",
"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 invididual `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. \n",
"\n",
Expand Down Expand Up @@ -58,7 +65,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Transpiler Passes\n",
"## Transpiler passes\n",
"\n",
"Transpiler passes are classified as analysis or transformation passes. Passes in general work with the [DAG](../api/qiskit/qiskit.dagcircuit.DAGCircuit) and the `property_set`, a dictionary-like object for storing properties determined by analysis passes. Analysis passes work with the DAG but cannot modify it. This contrasts with transformation passes, which do modify the DAG, and can read (but not write to) `property_set`. "
]
Expand All @@ -71,7 +78,7 @@
"\n",
"The following example constructs a transpiler pass that adds Pauli twirls. [Pauli twirling](https://arxiv.org/abs/quant-ph/0606161) is an error suppression strategy that randomizes how qubits experience noisy channels, which we assume to be two-qubit gates in this example (because they are much more error-prone than single-qubit gates). The Pauli twirls do not affect the two-qubit gates' operation. They are chosen such that those applied *before* the two-qubit gate (to the left) are countered by those applied *after* the two-qubit gate (to the right). In this sense, the two-qubit operations are identical, but the way they are performed is different. One benefit of Pauli twirling is that it turns coherent errors into stochastic errors, which can be improved by averaging more.\n",
"\n",
"Transpiler passes act on the [DAG](../api/qiskit/qiskit.dagcircuit.DAGCircuit), so the important method to override is `.run()`, which takes the DAG as input. Initializing pairs Paulis as shown preserves the operation of each two-qubit gate. This is done with the helper method `build_twirl_set`, which goes through each two-qubit Pauli (as obtained from `pauli_basis(2)`) and finds the other Pauli that preserves the operation. \n",
"Transpiler passes act on the [DAG](../api/qiskit/qiskit.dagcircuit.DAGCircuit), so the important method to override is `.run()`, which takes the DAG as input. Initializing pairs of Paulis as shown preserves the operation of each two-qubit gate. This is done with the helper method `build_twirl_set`, which goes through each two-qubit Pauli (as obtained from `pauli_basis(2)`) and finds the other Pauli that preserves the operation. \n",
"\n",
"From the DAG, use the `op_nodes()` method to return all of its nodes. The DAG can also be used to collect runs, which are sequences of nodes that run uninterrupted on a qubit. These can be collected as single-qubit runs with `collect_1q_runs`, two-qubit runs with `collect_2q_runs`, and runs of nodes where the instruction names are in a namelist with `collect_runs`. The `DAGCircuit` has many methods for searching and traversing a graph. One commonly used method is `topological_op_nodes`, which provides the nodes in a dependency ordering. Other methods such as `bfs_successors` are used primarily to determine how nodes interact with subsequent operations on a DAG. \n",
"\n",
Expand Down
3 changes: 2 additions & 1 deletion docs/transpile/qiskit-transpiler-service.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ The following examples demonstrate how to transpile circuits using the Qiskit tr
)
transpiled_circuit = cloud_transpiler_service.run(random_circ)
```
​## Next steps

## Next steps

<Admonition type="tip" title="Recommendations">
- Learn how to create [AI transpiler passes.](ai-transpiler-passes)
Expand Down

0 comments on commit c16dd6b

Please sign in to comment.