From c3cb9151d27be51658b5264a5c79ff06e5d85042 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 26 May 2022 15:20:51 -0400 Subject: [PATCH] Make python-constraint optional (Qiskit/qiskit-terra#7733) * Make python-constraint optional Since Qiskit/qiskit-terra#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-terra#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> --- qiskit_algorithms/utils/optionals.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qiskit_algorithms/utils/optionals.py b/qiskit_algorithms/utils/optionals.py index 35c8201a..916adda5 100644 --- a/qiskit_algorithms/utils/optionals.py +++ b/qiskit_algorithms/utils/optionals.py @@ -47,6 +47,10 @@ .. list-table:: :widths: 25 75 + * - .. py:data:: HAS_CONSTRAINT + - `python-constraint __ is a + constraint satisfaction problem solver, used in the :class:`~.CSPLayout` transpiler pass. + * - .. py:data:: HAS_CPLEX - The `IBM CPLEX Optimizer `__ is a high-performance mathematical programming solver for linear, mixed-integer and quadratic @@ -142,7 +146,6 @@ - `Z3 `__ is a theorem prover, used in the :class:`.CrosstalkAdaptiveSchedule` and :class:`.HoareOptimizer` transpiler passes. - External Command-Line Tools --------------------------- @@ -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]'",