qiskit-documentation/docs/api/qiskit/0.35/qiskit.transpiler.passes.Lo...

93 lines
4.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: LookaheadSwap
description: API reference for qiskit.transpiler.passes.LookaheadSwap
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.transpiler.passes.LookaheadSwap
---
# LookaheadSwap
<Class id="qiskit.transpiler.passes.LookaheadSwap" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.20/qiskit/transpiler/passes/routing/lookahead_swap.py" signature="LookaheadSwap(*args, **kwargs)" modifiers="class">
Bases: `qiskit.transpiler.basepasses.TransformationPass`
Map input circuit onto a backend topology via insertion of SWAPs.
Implementation of Sven Janduras swap mapper submission for the 2018 Qiskit Developer Challenge, adapted to integrate into the transpiler architecture.
The role of the swapper pass is to modify the starting circuit to be compatible with the target devices topology (the set of two-qubit gates available on the hardware.) To do this, the pass will insert SWAP gates to relocate the virtual qubits for each upcoming gate onto a set of coupled physical qubits. However, as SWAP gates are particularly lossy, the goal is to accomplish this remapping while introducing the fewest possible additional SWAPs.
This algorithm searches through the available combinations of SWAP gates by means of a narrowed best first/beam search, described as follows:
* Start with a layout of virtual qubits onto physical qubits.
* Find any gates in the input circuit which can be performed with the current layout and mark them as mapped.
* For all possible SWAP gates, calculate the layout that would result from their application and rank them according to the distance of the resulting layout over upcoming gates (see \_calc\_layout\_distance.)
* For the four (search\_width) highest-ranking SWAPs, repeat the above process on the layout that would be generated if they were applied.
* Repeat this process down to a depth of four (search\_depth) SWAPs away from the initial layout, for a total of 256 (search\_width^search\_depth) prospective layouts.
* Choose the layout which maximizes the number of two-qubit which could be performed. Add its mapped gates, including the SWAPs generated, to the output circuit.
* Repeat the above until all gates from the initial circuit are mapped.
For more details on the algorithm, see Svens blog post: [https://medium.com/qiskit/improving-a-quantum-compiler-48410d7a7084](https://medium.com/qiskit/improving-a-quantum-compiler-48410d7a7084)
LookaheadSwap initializer.
**Parameters**
* **coupling\_map** ([*CouplingMap*](qiskit.transpiler.CouplingMap "qiskit.transpiler.CouplingMap")) CouplingMap of the target backend.
* **search\_depth** (*int*) lookahead tree depth when ranking best SWAP options.
* **search\_width** (*int*) lookahead tree width when ranking best SWAP options.
* **fake\_run** (*bool*) if true, it only pretend to do routing, i.e., no swap is effectively added.
## Methods
### name
<Function id="qiskit.transpiler.passes.LookaheadSwap.name" signature="LookaheadSwap.name()">
Return the name of the pass.
</Function>
### run
<Function id="qiskit.transpiler.passes.LookaheadSwap.run" signature="LookaheadSwap.run(dag)">
Run the LookaheadSwap pass on dag.
**Parameters**
**dag** ([*DAGCircuit*](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")) the directed acyclic graph to be mapped
**Returns**
**A dag mapped to be compatible with the coupling\_map in**
the property\_set.
**Return type**
[DAGCircuit](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")
**Raises**
* [**TranspilerError**](qiskit.transpiler.TranspilerError "qiskit.transpiler.TranspilerError") if the coupling map or the layout are not
* **compatible with the DAG**
</Function>
## Attributes
### is\_analysis\_pass
<Attribute id="qiskit.transpiler.passes.LookaheadSwap.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.LookaheadSwap.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>