question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docplex is not fully compatible with cplex 20.1

See original GitHub issue

Information

  • Qiskit Optimization version: NA
  • Python version: 3.7.9, 3.8.7, 3.9.1
  • Operating system: macOS 11.2

What is the current behavior?

There are two issues related to docplex as follows.

(1) Docplex 2.14.186 (May 2020) or older does not work with cplex 20.1 (Jan 2021)

(2) Docplex 2.16.196 (Nov 2020) or newer does not work without installing cplex. But, cplex is not included as the dependency of docplex. It seems a bug. Because no cplex wheel available for Python 3.9, docplex 2.16.196 or newer does not work with Python 3.9. cplex version also matters.

This change is mentioned as follows.

Changed in 2.16.196 (2020.11): In docplex.mp: For solving, docplex.mp now uses the cplex module if it has been installed. If not, docplex.mp checks for the latest installed version of CPLEX Optimization Studio (COS) (using the CPLEX_STUDIO_DIRXXX environment variables) and use the cplex if a COS is found, unless the configuration of the engine states otherwise. https://pypi.org/project/docplex/#description

Summary of compatibility:

docplex → 2.14.186 or older 2.15.194 2.16.196 - 2.20.204 2.21.207
w/ cplex 12.10 (Dec 2019 - Jul 2020) OK OK OK OK
w/ cplex 20.1 (Jan 2021) NG OK OK OK
w/o cplex OK OK NG (macOS), OK (Ubuntu, Windows) OK

Steps to reproduce the problem

from docplex.mp.model import Model
a = Model()
x = a.binary_var()
print(a.add_constraint(x <= 1))

Python 3.7, docplex 2.15.194 without cplex

x1 <= 1

Python 3.7, docplex 2.16.196 with cplex 20.1

x1 <= 1

Python 3.7, docplex 2.16.196 without cplex

Traceback (most recent call last):
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/environment.py", line 290, in get_cplex_module
    import cplex  #@UnresolvedImport
ModuleNotFoundError: No module named 'cplex'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c.py", line 2, in <module>
    a = Model()
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/model.py", line 397, in __init__
    self._environment = self._make_environment()
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/model.py", line 174, in _make_environment
    env = Environment.get_default_env()
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/environment.py", line 427, in get_default_env
    Environment._default_env = Environment.make_new_configured_env()
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/environment.py", line 422, in make_new_configured_env
    return Environment(start_auto_configure=True)
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/environment.py", line 84, in __init__
    self.auto_configure(logger=logger)
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/environment.py", line 220, in auto_configure
    self.check_cplex(logger=logger)
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/environment.py", line 328, in check_cplex
    cplex = self.get_cplex_module(logger=logger)
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/environment.py", line 314, in get_cplex_module
    cplex = load_cplex_from_cos_root(loc) if loc else None
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/environment.py", line 286, in load_cplex_from_cos_root
    return load_cplex(full_path, version=version)
  File "/Users/ima/envs/test/lib/python3.7/site-packages/docplex/mp/environment.py", line 261, in load_cplex
    raise FileNotFoundError("Could not load module from %s" % module_location)
FileNotFoundError: Could not load module from /Applications/CPLEX_Studio201/cplex/python/3.7/x86-64osx/cplex/__init__.py

Python 3.8, docplex 2.15.194 with and without cplex

x1 <= 1

Python 3.8, docplex 2.16.196 with cplex 20.1

x1 <= 1

Python 3.8, docplex 2.16.196 without cplex

Traceback (most recent call last):
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/environment.py", line 290, in get_cplex_module
    import cplex  #@UnresolvedImport
ModuleNotFoundError: No module named 'cplex'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c.py", line 2, in <module>
    a = Model()
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/model.py", line 417, in __init__
    self._environment = self._make_environment()
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/model.py", line 181, in _make_environment
    env = Environment.get_default_env()
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/environment.py", line 427, in get_default_env
    Environment._default_env = Environment.make_new_configured_env()
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/environment.py", line 422, in make_new_configured_env
    return Environment(start_auto_configure=True)
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/environment.py", line 84, in __init__
    self.auto_configure(logger=logger)
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/environment.py", line 220, in auto_configure
    self.check_cplex(logger=logger)
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/environment.py", line 328, in check_cplex
    cplex = self.get_cplex_module(logger=logger)
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/environment.py", line 314, in get_cplex_module
    cplex = load_cplex_from_cos_root(loc) if loc else None
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/environment.py", line 286, in load_cplex_from_cos_root
    return load_cplex(full_path, version=version)
  File "/Users/ima/envs/test/lib/python3.8/site-packages/docplex/mp/environment.py", line 261, in load_cplex
    raise FileNotFoundError("Could not load module from %s" % module_location)
FileNotFoundError: Could not load module from /Applications/CPLEX_Studio201/cplex/python/3.8/x86-64osx/cplex/__init__.py

Python 3.8, docplex 2.14.186 with cplex 20.1

Traceback (most recent call last):
  File "c.py", line 4, in <module>
    print(a.add_constraint(x <= 1))
  File "/Users/ima/envs/dev38/lib/python3.8/site-packages/docplex/mp/model.py", line 3518, in add_constraint
    ct = self._add_constraint_internal(ct, ctname)
  File "/Users/ima/envs/dev38/lib/python3.8/site-packages/docplex/mp/model.py", line 2995, in _add_constraint_internal
    self._post_constraint(ct)
  File "/Users/ima/envs/dev38/lib/python3.8/site-packages/docplex/mp/model.py", line 3003, in _post_constraint
    ct_engine_index = self._create_engine_constraint(ct)
  File "/Users/ima/envs/dev38/lib/python3.8/site-packages/docplex/mp/model.py", line 2881, in _create_engine_constraint
    return eng.create_linear_constraint(ct)
  File "/Users/ima/envs/dev38/lib/python3.8/site-packages/docplex/mp/cplex_engine.py", line 937, in create_linear_constraint
    return self._make_cplex_linear_ct(cpx_lin_expr=cpx_linexp,
  File "/Users/ima/envs/dev38/lib/python3.8/site-packages/docplex/mp/cplex_engine.py", line 925, in _make_cplex_linear_ct
    ret_add = fast_add_linear(self._cplex, cpx_lin_expr, cpx_sense, cpx_rhs, cpxnames)
  File "/Users/ima/envs/dev38/lib/python3.8/site-packages/docplex/mp/cplex_engine.py", line 215, in fast_add_linear1290
    cpxenv._apienc) as (rmat, nnz):
AttributeError: 'Environment' object has no attribute '_apienc'

Python 3.9, docplex 2.15.194 without cplex

x1 <= 1

Python 3.9, docplex 2.16.196 without cplex

Traceback (most recent call last):
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/environment.py", line 290, in get_cplex_module
    import cplex  #@UnresolvedImport
ModuleNotFoundError: No module named 'cplex'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ima/tasks/1_2021/qiskit/aqua/tmp/c.py", line 2, in <module>
    a = Model()
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/model.py", line 417, in __init__
    self._environment = self._make_environment()
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/model.py", line 181, in _make_environment
    env = Environment.get_default_env()
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/environment.py", line 427, in get_default_env
    Environment._default_env = Environment.make_new_configured_env()
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/environment.py", line 422, in make_new_configured_env
    return Environment(start_auto_configure=True)
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/environment.py", line 84, in __init__
    self.auto_configure(logger=logger)
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/environment.py", line 220, in auto_configure
    self.check_cplex(logger=logger)
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/environment.py", line 328, in check_cplex
    cplex = self.get_cplex_module(logger=logger)
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/environment.py", line 314, in get_cplex_module
    cplex = load_cplex_from_cos_root(loc) if loc else None
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/environment.py", line 286, in load_cplex_from_cos_root
    return load_cplex(full_path, version=version)
  File "/Users/ima/envs/dev39/lib/python3.9/site-packages/docplex/mp/environment.py", line 261, in load_cplex
    raise FileNotFoundError("Could not load module from %s" % module_location)
FileNotFoundError: Could not load module from /Applications/CPLEX_Studio201/cplex/python/3.9/x86-64osx/cplex/__init__.py

What is the expected behavior?

QuadraticProgram works fine.

Suggested solutions

I recommend to pin 2.15.194 (Jul 2020) for the time being because it is the only docplex that works with any Python 3.6-3.9 even without cplex wheel.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
woodsp-ibmcommented, Mar 25, 2021

@t-imamichi I see there is a cplex 20.1.0.1 that was released and says its from Feb 8th. Is it worth double checking the status of the docplex/cplex ahead of release to see if the version pinning we have in place still makes sense or whether it can be relaxed at all.

1reaction
manoelmarquescommented, Feb 12, 2021

The PR #30 runs all unit tests under Ubuntu for all python versions, with and without cplex and cvxpy with no restrictions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cplex 20.1 is not compatible with docplex 2.20.204
Hi all,I have updated my Cplex from 12.9 to 20.1.0(Both under IBM Academic Initiative). Before installing the newest version of ...
Read more >
Changelog — IBM® Decision Optimization CPLEX® Modeling ...
Latest supported CPLEX Optimization Studio is now 20.1 ... If not, docplex.mp checks for the latest installed version of CPLEX Optimization Studio (COS) ......
Read more >
python 3.x - How to install CP Optimizer 20.1 with docplex?
To complement Sascha's answer: docplex is a modeling layer, it does not include the runtimes (CPLEX and CPO) . Runtimes have to be...
Read more >
Python does not identify the academic version of CPLEX
Python does not identify the academic version of CPLEX. I am using Linux, Ubuntu. I have Python 3.6. I installed CPLEX studio 12.9...
Read more >
Cplex Python: Installation, API, and Examples
Not only linear programming, but it also has support for complex level ... This method will add CPLEX and Docplex to your python...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found