CURENT / andes

Python toolbox / library for power system transient dynamics simulation with symbolic modeling and numerical analysis 🔥
https://ltb.curent.org
Other
208 stars 108 forks source link

Bug with dependency kvxopt 1.3.2.0 #508

Closed jinningwang closed 4 months ago

jinningwang commented 5 months ago

Describe the bug

After requirement installation where kvxopt=1.3.2.0, andes cli run into error.

I've made a version limit in AMS requirement: kvxopt>=1.3.0.0,!=1.3.2.*

To Reproduce

Create a fresh conda environment and install requirements.txt will run into this error. Terminal command I used is as below:

(base) jinningwang@jwmba-3 andes % mamba create --name ltb python=3.9

(base) jinningwang@jwmba-3 andes % mamba activate ltb

(ltb) jinningwang@jwmba-3 andes % pip list
Package         Version
--------------- -------
git-filter-repo 2.38.0
pip             23.3.2
setuptools      69.0.3
wheel           0.42.0

(ltb) jinningwang@jwmba-3 andes % mamba install --file requirements.txt  

(ltb) jinningwang@jwmba-3 andes % pip install -e .

(ltb) jinningwang@jwmba-3 andes % andes
Traceback (most recent call last):
  File "/Users/jinningwang/Documents/work/mambaforge/envs/ltb/bin/andes", line 33, in <module>
    sys.exit(load_entry_point('andes', 'console_scripts', 'andes')())
  File "/Users/jinningwang/Documents/work/mambaforge/envs/ltb/bin/andes", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/Users/jinningwang/Documents/work/mambaforge/envs/ltb/lib/python3.9/importlib/metadata.py", line 86, in load
    module = import_module(match.group('module'))
  File "/Users/jinningwang/Documents/work/mambaforge/envs/ltb/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/jinningwang/Documents/work/andes/andes/__init__.py", line 4, in <module>
    from andes import io         # NOQA
  File "/Users/jinningwang/Documents/work/andes/andes/io/__init__.py", line 13, in <module>
    from andes.utils.misc import elapsed
  File "/Users/jinningwang/Documents/work/andes/andes/utils/__init__.py", line 2, in <module>
    from andes.utils import snapshot  # NOQA
  File "/Users/jinningwang/Documents/work/andes/andes/utils/snapshot.py", line 36, in <module>
    from andes.system import fix_view_arrays, import_pycode
  File "/Users/jinningwang/Documents/work/andes/andes/system.py", line 26, in <module>
    from andes.core import AntiWindup, Config, Model
  File "/Users/jinningwang/Documents/work/andes/andes/core/__init__.py", line 5, in <module>
    from andes.core.block import (Block, Lag, LagAntiWindup, LeadLag,  # NOQA
  File "/Users/jinningwang/Documents/work/andes/andes/core/block.py", line 14, in <module>
    from andes.core.common import JacTriplet, ModelFlags, dummify
  File "/Users/jinningwang/Documents/work/andes/andes/core/common.py", line 8, in <module>
    from andes.shared import jac_full_names, jac_names, jac_types
  File "/Users/jinningwang/Documents/work/andes/andes/shared.py", line 19, in <module>
    from kvxopt import (div, klu, matrix, mul, sparse, spdiag, spmatrix,  # NOQA
ImportError: dlopen(/Users/jinningwang/Documents/work/mambaforge/envs/ltb/lib/python3.9/site-packages/kvxopt/klu.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_klu_l_analyze'

Expected behavior

CLI should run normally.

Desktop (please complete the following information):

pip packages (please paste the output from pip list)

(ltb) jinningwang@jwmba-3 andes % pip list
Package             Version    Editable project location
------------------- ---------- ---------------------------------------
andes               1.9.0      /Users/jinningwang/Documents/work/andes
certifi             2023.11.17
chardet             5.2.0
colorama            0.4.6
coloredlogs         15.0.1
contourpy           1.2.0
cycler              0.12.1
dill                0.3.8
et-xmlfile          1.1.0
fonttools           4.47.2
git-filter-repo     2.38.0
gmpy2               2.1.2
humanfriendly       10.0
importlib-resources 6.1.1
kiwisolver          1.4.5
kvxopt              1.3.2.0
llvmlite            0.41.1
matplotlib          3.8.2
mpmath              1.3.0
multiprocess        0.70.16
munkres             1.1.4
numba               0.58.1
numpy               1.26.3
openpyxl            3.1.2
packaging           23.2
pandas              2.2.0
pathos              0.3.2
pillow              10.2.0
pip                 23.3.2
pox                 0.3.4
ppft                1.7.6.8
psutil              5.9.8
pyparsing           3.1.1
python-dateutil     2.8.2
pytz                2023.4
PyYAML              6.0.1
scipy               1.12.0
setuptools          69.0.3
six                 1.16.0
sympy               1.12
texttable           1.7.0
tornado             6.3.3
tqdm                4.66.1
tzdata              2023.4
unicodedata2        15.1.0
wheel               0.42.0
XlsxWriter          3.1.9
zipp                3.17.0

Additional context

After install kvxopt 1.3.0, the error goes away.

(ltb) jinningwang@jwmba-3 andes % mamba install kvxopt=1.3.0
(ltb) jinningwang@jwmba-3 andes % andes

    _           _         | Version 1.9.0
   /_\  _ _  __| |___ ___ | Python 3.9.18 on Darwin, 02/02/2024 10:13:43 AM
  / _ \| ' \/ _` / -_|_-< | 
 /_/ \_\_||_\__,_\___/__/ | This program comes with ABSOLUTELY NO WARRANTY.

usage: andes [-h] [-v {1,10,20,30,40}] {run,plot,doc,misc,prepare,prep,selftest,st,demo} ...

positional arguments:
  {run,plot,doc,misc,prepare,prep,selftest,st,demo}
                        [run] run simulation routine; [plot] plot results; [doc] quick documentation; [misc] misc.
                        functions; [prepare] prepare the numerical code; [selftest] run self test;

optional arguments:
  -h, --help            show this help message and exit
  -v {1,10,20,30,40}, --verbose {1,10,20,30,40}
                        Verbosity level in 10-DEBUG, 20-INFO, 30-WARNING, or 40-ERROR.
(ltb) jinningwang@jwmba-3 andes % andes misc --version
Python  3.9.18
andes   1.9.0
numpy   1.26.3
kvxopt  1.3.0.3
sympy   1.12
scipy   1.12.0
pandas  2.2.0
numba   0.58.1

Even then upgrade kvxopt to 1.3.2.0, the error will never occur.

(ltb) jinningwang@jwmba-3 andes % mamba install kvxopt=1.3.2

(ltb) jinningwang@jwmba-3 andes % andes

    _           _         | Version 1.9.0
   /_\  _ _  __| |___ ___ | Python 3.9.18 on Darwin, 02/02/2024 10:17:18 AM
  / _ \| ' \/ _` / -_|_-< | 
 /_/ \_\_||_\__,_\___/__/ | This program comes with ABSOLUTELY NO WARRANTY.

usage: andes [-h] [-v {1,10,20,30,40}] {run,plot,doc,misc,prepare,prep,selftest,st,demo} ...

positional arguments:
  {run,plot,doc,misc,prepare,prep,selftest,st,demo}
                        [run] run simulation routine; [plot] plot results; [doc] quick documentation; [misc] misc.
                        functions; [prepare] prepare the numerical code; [selftest] run self test;

optional arguments:
  -h, --help            show this help message and exit
  -v {1,10,20,30,40}, --verbose {1,10,20,30,40}
                        Verbosity level in 10-DEBUG, 20-INFO, 30-WARNING, or 40-ERROR.
(ltb) jinningwang@jwmba-3 andes % andes misc --version
Python  3.9.18
andes   1.9.0
numpy   1.26.3
kvxopt  1.3.2.0
sympy   1.12
scipy   1.12.0
pandas  2.2.0
numba   0.58.1
jinningwang commented 5 months ago

Hold a sec, this error goes away again after upgrading kvxopt to 1.3.2.0. It's weird, let me try again.

jinningwang commented 4 months ago

After a fix in kvxopt, the issue is solved.

References: https://github.com/conda-forge/kvxopt-feedstock/pull/34, https://github.com/sanurielf/kvxopt/issues/10

Logging message:

(andesbuild) jinningwang@jwmba-3 andes % andes

    _           _         | Version 1.9.1
   /_\  _ _  __| |___ ___ | Python 3.9.18 on Darwin, 03/02/2024 04:33:41 PM
  / _ \| ' \/ _` / -_|_-< | 
 /_/ \_\_||_\__,_\___/__/ | This program comes with ABSOLUTELY NO WARRANTY.

usage: andes [-h] [-v {1,10,20,30,40}] {run,plot,doc,misc,prepare,prep,selftest,st,demo} ...

positional arguments:
  {run,plot,doc,misc,prepare,prep,selftest,st,demo}
                        [run] run simulation routine; [plot] plot results; [doc] quick
                        documentation; [misc] misc. functions; [prepare] prepare the numerical
                        code; [selftest] run self test;

optional arguments:
  -h, --help            show this help message and exit
  -v {1,10,20,30,40}, --verbose {1,10,20,30,40}
                        Verbosity level in 10-DEBUG, 20-INFO, 30-WARNING, or 40-ERROR.
(andesbuild) jinningwang@jwmba-3 andes % andes misc --version                         
Python  3.9.18
andes   1.9.1
numpy   1.26.4
kvxopt  1.3.2.0
sympy   1.12
scipy   1.12.0
pandas  2.2.1
numba   0.59.0