Skip to content

Commit

Permalink
Make python-constraint optional (Qiskit/qiskit#7733)
Browse files Browse the repository at this point in the history
* Make python-constraint optional

Since Qiskit/qiskit#7213 we no longer have been using the CSPLayout pass by default
in the preset passmanagers or transpile(). This is because it has been
superseded by the VF2Layout pass which is now used everywhere. While we
will keep the CSPLayout pass around for the forseeable future there is
no need to install python-constraint by default anymore since it's only
user is the CSPLayout pass, which isn't going to be commonly used
anymore now that it's not used in the default compilation path anymore.
This commit removes the python-constraint library from the requirements
list and makes it an optional dependency.

Fixes Qiskit/qiskit#7726

* Add docstring for HAS_CONSTRAINT

* Add private module to avoid module level optional import

This commit splits the custom solver class definition out into a
separate private module that is not imported until runtime. This enables
us to avoid a module level import for python-constraint meaning we only
try to import if something is actually using CSPLayout.

* Fix rebase issue

* Fix lint

* Fix typo in release note

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>

* Alphabetize optionals list

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
  • Loading branch information
mtreinish and woodsp-ibm authored May 26, 2022
1 parent fd8862a commit c3cb915
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion qiskit_algorithms/utils/optionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
.. list-table::
:widths: 25 75
* - .. py:data:: HAS_CONSTRAINT
- `python-constraint <https://github.com/python-constraint/python-constraint>__ is a
constraint satisfaction problem solver, used in the :class:`~.CSPLayout` transpiler pass.
* - .. py:data:: HAS_CPLEX
- The `IBM CPLEX Optimizer <https://www.ibm.com/analytics/cplex-optimizer>`__ is a
high-performance mathematical programming solver for linear, mixed-integer and quadratic
Expand Down Expand Up @@ -142,7 +146,6 @@
- `Z3 <https://github.com/Z3Prover/z3>`__ is a theorem prover, used in the
:class:`.CrosstalkAdaptiveSchedule` and :class:`.HoareOptimizer` transpiler passes.
External Command-Line Tools
---------------------------
Expand Down Expand Up @@ -207,6 +210,12 @@
install="pip install qiskit-ignis",
)

HAS_CONSTRAINT = _LazyImportTester(
"constraint",
name="python-constraint",
install="pip install python-constraint",
)

HAS_CPLEX = _LazyImportTester(
"cplex",
install="pip install 'qiskit-terra[bip-mapper]'",
Expand Down

0 comments on commit c3cb915

Please sign in to comment.