Skip to content

Commit

Permalink
BIP mapping pass (#6580)
Browse files Browse the repository at this point in the history
* wip: initial move

* fix a bug when no coupling_map is supplied

* Improved documentation and parameter settings

* Improved logical/physical qubit mapping

* Better handling of measurements and final layout

* minor fixes

* add unit tests

* wip: start refactoring

* improve layout handling

* simplify dag construction and fix to output all ops

* fix to work with ApplyLayout

* focus on layout+routing

* improve how to call MIPMapping

* simplify the spec

* add an error handling

* fix how to call MIPMapping pass

* update user warning for change of given layout

* wip: refactor mip model

* improve top-level interface

* return original dag if fails to solve MIP

* minor fixes

* care the case no cplex is installed

* fix not to ignore swaps in original layers

* fix mismatch in layer and su4layer indices

* simplify by focusing only on depth objective

* rename MIP to BIP

* lint

lint

lint

lint

* improve interface around dummy steps

* improve error message when cplex fails

* restore level3 preset passmanager

* improve depth objective

* Rework optional dependency and add test configuration

This commit reworks the logic around the optional dependency on cplex.
The pass despite raising an exception if cplex wasn't installed was
unconditionally trying to import cplex from the model module at import
time. To avoid failures from that this adds a try block around the
actual cplex usage in the model module and exports whether it's
available or not. At the same time this is leveraged to add a skip
condition on the tests so we only run them if cplex is installed. Then
to run tests in CI we install cplex in the linux 3.7 job so we at least
run it in one environment. It's not available in all our supported
environments so getting full coverage in every env is not worth trying
for, so just testing the qiskit portion works is enough.

* Fix lint

* Fix test, lint and logging

* Fix lint and test, update docstring

* Fix docstring and improve performance taking the risk of failing to map

* Update docstring

* Replace cplex.Cplex with docplex.mp.model.Model to improve readability

Replace cplex.Cplex with docplex.mp.model.Model to improve readability

fix requiring docplex version

move docplex to requirements-dev

* Improve BIPMappingModel interface

simplify and improve docstring

Improve BIPMappingModel interface

* Update qiskit/transpiler/passes/routing/algorithms/bip_model.py

Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>

* Fix docplex dependency

* fix unnecessary-comprehension

* lint

* lint

* update how to set cplex params and remove redundant constraints

* skip unless docplex

* fix a bug in arg threads

* remove python version restriction

* Change spec to require the number of virtual and physical qubits are the same

* Update to use 'requires' to require precondition passes

* Update qiskit/transpiler/passes/routing/algorithms/bip_model.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* lint

* Add release note

Add release note

fix typos

* Update docstring

Update docstring

fix typo

* Improve error handling

* Change to return mapped dag for circuits with only 1q-gates

* Revert the spec change in the case of only 1q-gates

* Update releasenotes/notes/add-bip-mapper-f729f2c5672d7f3e.yaml

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update releasenotes/notes/add-bip-mapper-f729f2c5672d7f3e.yaml

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update qiskit/transpiler/passes/routing/bip_mapping.py

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update qiskit/transpiler/passes/routing/bip_mapping.py

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update qiskit/transpiler/passes/routing/bip_mapping.py

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update qiskit/transpiler/passes/routing/bip_mapping.py

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

Co-authored-by: Giacomo Nannicini <gnannicini@users.noreply.github.com>
Co-authored-by: Giacomo Nannicini <giacomo.n@gmail.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
8 people authored Jul 1, 2021
1 parent 80ea8fe commit cd4a712
Show file tree
Hide file tree
Showing 9 changed files with 941 additions and 1 deletion.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ stages:
pip install -U -r requirements.txt -r requirements-dev.txt -c constraints.txt
python setup.py sdist
pip install -U -c constraints.txt dist/qiskit-terra*.tar.gz
pip install -U "qiskit-aer" "z3-solver" -c constraints.txt
pip install -U "cplex" "qiskit-aer" "z3-solver" -c constraints.txt
mkdir -p /tmp/terra-tests
cp -r test /tmp/terra-tests/.
cp .stestr.conf /tmp/terra-tests/.
Expand Down
2 changes: 2 additions & 0 deletions qiskit/transpiler/passes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
LookaheadSwap
StochasticSwap
SabreSwap
BIPMapping
Basis Change
============
Expand Down Expand Up @@ -144,6 +145,7 @@
from .routing import LookaheadSwap
from .routing import StochasticSwap
from .routing import SabreSwap
from .routing import BIPMapping

# basis change
from .basis import Decompose
Expand Down
1 change: 1 addition & 0 deletions qiskit/transpiler/passes/routing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
from .lookahead_swap import LookaheadSwap
from .stochastic_swap import StochasticSwap
from .sabre_swap import SabreSwap
from .bip_mapping import BIPMapping
Loading

0 comments on commit cd4a712

Please sign in to comment.