Skip to content

Commit

Permalink
Update text on trivial qubit mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelynj committed Jan 26, 2024
1 parent e07922e commit 83bf059
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/transpile/transpiler-stages.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"The next stage involves the layout or connectivity of the backend a circuit will be sent to. In general, quantum circuits are abstract entities whose qubits are \"virtual\" or \"logical\" representations of actual qubits used in computations. To execute a sequence of gates, a one-to-one mapping from the \"virtual\" qubits to the \"physical\" qubits in an actual quantum device is necesary. This mapping is stored as a `Layout` object.\n",
"\n",
"\n",
"![Qubit mapping](/images/transpile/transpiler-stages/layout-mapping.png)\n",
"![This image illustrates qubits being mapped from the wire representation to a diagram that represents how the qubits are connected on the system.](/images/transpile/transpiler-stages/layout-mapping.png \"Qubit mapping\")\n",
"\n",
"The choice of mapping is extremely important for minimizing the number of SWAP operations needed to map the input circuit onto the device topology and ensure the most well-calibrated qubits are used. Due to the importance of this stage, the preset pass managers try a few different methods to find the best layout. Typically this involves two steps: first, try to find a \"perfect\" layout (a layout that does not require any SWAP operations), and then, a heuristic pass that tries to find the best layout to use if a perfect layout cannot be found. There are two `Passes` typically used for this first step:\n",
Expand All @@ -63,9 +62,7 @@
"\n",
"However, finding the optimal SWAP mapping is hard. In fact, it is an NP-hard problem, and is thus prohibitively expensive to compute for all but the smallest quantum devices and input circuits. To work around this, Qiskit uses a stochastic heuristic algorithm called `SabreSwap` to compute a good, but not necessarily optimal, SWAP mapping. The use of a stochastic method means that the circuits generated are not guaranteed to be the same over repeated runs. Indeed, running the same circuit repeatedly results in a distribution of circuit depths and gate counts at the output. It is for this reason that many users choose to run the routing function (or the entire `StagedPassManager`) many times and select the lowest-depth circuits from the distribution of outputs.\n",
"\n",
"For example, this is a GHZ circuit executed 100 times, using a “bad” (disconnected) `initial_layout`:\n",
"\n",
" <img src=\"/images/transpile/transpiler-stages/hardware-qubit-graph.png\" alt=\"Layout of qubits on hardware\" width=\"350%\" />"
"For example, let's take a 15 qubit GHZ circuit executed 100 times, using a “bad” (disconnected) `initial_layout`."
]
},
{
Expand Down Expand Up @@ -127,7 +124,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This distribution is quite wide, signaling the difficulty the SWAP mapper is having in computing the best mapping.\n",
"This distribution is quite wide, signaling the difficulty the SWAP mapper is having in computing the best mapping. In fact, we can take a closer look at what hardware qubits were chosen to run the circuit:\n",
"\n",
"<img src=\"/images/transpile/transpiler-stages/hardware-qubit-graph.png\" alt=\"Layout of qubits on hardware\" width=\"350%\" />\n",
"\n",
"As you can see this selection of qubits isn't even fully connected to each other! This means unnecessary SWAP gates must be inserted in order to execute all of the two-qubit gates because we naively chose which hardware qubits to use in our circuit.\n",
"\n",
"It's also important to point out here that the `SabreSwap` algorithm is different from the larger `SabreLayout` method in the previous stage. By default, `SabreLayout` runs both layout and routing, and returns the transformed circuit. This is done for a few particular technical reasons specified in the pass's [API reference page](../api/qiskit/qiskit.transpiler.passes.SabreLayout). "
]
Expand Down

0 comments on commit 83bf059

Please sign in to comment.