Skip to main content
IBM Quantum Platform
This page is from an old version of Qiskit SDK and does not exist in the latest version. We recommend you migrate to the latest version. See the release notes for more information.

BIPMapping

class BIPMapping(*args, **kwargs)

GitHub

Bases: qiskit.transpiler.basepasses.TransformationPass

Map a DAGCircuit onto a given coupling_map, allocating qubits and adding swap gates.

The BIP mapper tries to find the best layout and routing at once by solving a BIP (binary integer programming) problem as described in [1].

The BIP problem represents the layer-by-layer mapping of 2-qubit gates, assuming all the gates in a layer can be run on the coupling_map. In the problem, the variables ww represent the layout of qubits for each layer and the variables xx represent which pair of qubits should be swapped in between layers. Based on the values in the solution of the BIP problem, the mapped circuit will be constructed.

The BIP mapper depends on docplex to represent the BIP problem and CPLEX (cplex) to solve it. Those packages can be installed with pip install qiskit-terra[bip-mapper]. Since the free version of CPLEX can solve only small BIP problems, i.e. mapping of circuits with less than about 5 qubits, the paid version of CPLEX may be needed to map larger circuits.

If you want to fix physical qubits to be used in the mapping (e.g. running Quantum Volume circuits), you need to supply coupling_map which contains only the qubits to be used. Please do not use initial_layout for that purpose because the BIP mapper gracefully ignores initial_layout (and tries to determines its best layout).

Warning

The BIP mapper does not scale very well with respect to the number of qubits or gates. For example, it would not work with coupling_map beyond 10 qubits because the BIP solver (CPLEX) could not find any solution within the default time limit.

References:

[1] G. Nannicini et al. “Optimal qubit assignment and routing via integer programming.” arXiv:2106.06446

BIPMapping initializer.

Parameters

  • coupling_map (CouplingMap) – Directed graph represented a coupling map.

  • objective (str) –

    Type of objective function:

    • 'error_rate': [NotImplemented] Predicted error rate of the circuit
    • 'depth': [Default] Depth (number of time-steps) of the circuit
    • 'balanced': [NotImplemented] Weighted sum of 'error_rate' and 'depth'
  • backend_prop (BackendProperties) – Backend properties object

  • time_limit (float) – Time limit for solving BIP in seconds

  • threads (int) – Number of threads to be allowed for CPLEX to solve BIP

  • max_swaps_inbetween_layers (int) – Number of swaps allowed in between layers. If None, automatically set. Large value could decrease the probability to build infeasible BIP problem but also could reduce the chance of finding a feasible solution within the time_limit.

Raises

MissingOptionalLibraryError – if cplex or docplex are not installed.


Methods

name

BIPMapping.name()

Return the name of the pass.

run

BIPMapping.run(dag)

Run the BIPMapping pass on dag, assuming the number of virtual qubits (defined in dag) and the number of physical qubits (defined in coupling_map) are the same.

Parameters

dag (DAGCircuit) – DAG to map.

Returns

A mapped DAG. If there is no 2q-gate in DAG or it fails to map,

returns the original dag.

Return type

DAGCircuit

Raises

  • TranspilerError – if the number of virtual and physical qubits are not the same.
  • AssertionError – if the final layout is not valid.

Attributes

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.

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).

Was this page helpful?
Report a bug or request content on GitHub.