ami-iit / liecasadi

Rigid transform using Lie groups and Dual Quaternions, written in CasADi!
BSD 3-Clause "New" or "Revised" License
57 stars 4 forks source link

Problems running the example #2

Closed traversaro closed 2 years ago

traversaro commented 2 years ago

I tried installing the library as documented in the README and running the example.

By installing the example as documented in the README:

(castest) traversaro@IITICUBLAP257:~$ pip install "liecasadi @ git+https://github.com/ami-iit/lie-casadi.git"
Collecting liecasadi@ git+https://github.com/ami-iit/lie-casadi.git
  Cloning https://github.com/ami-iit/lie-casadi.git to /tmp/pip-install-jld36pa2/liecasadi_02974e872e9a41da95da2ba742a2bb6a
  Running command git clone --filter=blob:none --quiet https://github.com/ami-iit/lie-casadi.git /tmp/pip-install-jld36pa2/liecasadi_02974e872e9a41da95da2ba742a2bb6a
  Resolved https://github.com/ami-iit/lie-casadi.git to commit 4f538f354781243e600ce771c9236a43df83745d
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting numpy>=1.20
  Using cached numpy-1.22.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.8 MB)
Collecting casadi
  Using cached casadi-3.5.5-cp38-none-manylinux1_x86_64.whl (34.2 MB)
Building wheels for collected packages: liecasadi
  Building wheel for liecasadi (pyproject.toml) ... done
  Created wheel for liecasadi: filename=liecasadi-0.1.dev39-py3-none-any.whl size=7882 sha256=078ab323d4479d39e5aa0a577a6150df54d9224d416b94c89d26adc5db0616be
  Stored in directory: /tmp/pip-ephem-wheel-cache-v0j9nv_a/wheels/7a/26/6a/62ad9ab4f348e178408f7d79d44555ed51514496949fcdb644
Successfully built liecasadi
Installing collected packages: casadi, numpy, liecasadi
Successfully installed casadi-3.5.5 liecasadi-0.1.dev39 numpy-1.22.1

You can see that casadi got installed via pip.

Then, I tried to run the example and the example fails with:

(castest) traversaro@IITICUBLAP257:~/liecasadi/examples$ python manifold_optimization.py
Traceback (most recent call last):
  File "manifold_optimization.py", line 4, in <module>
    import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'

This is due to matplotlib missing, and it make sense that this is not part of the dependencies of the library. If I then install matplot lib, then the example fails with:

(castest) traversaro@IITICUBLAP257:~/liecasadi/examples$ python manifold_optimization.py
Traceback (most recent call last):
  File "manifold_optimization.py", line 9, in <module>
    from liecasadi import SO3, SO3Tangent
  File "/home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages/liecasadi/__init__.py", line 3, in <module>
    from .so3 import SO3, SO3Tangent
  File "/home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages/liecasadi/so3.py", line 9, in <module>
    from attr import field
ModuleNotFoundError: No module named 'attr'

This is a bit more tricky, as it requires to install the attrs package (note the final s, as the attr package will not work).

After installing also attr, I get this error:

(castest) traversaro@IITICUBLAP257:~/liecasadi/examples$ python manifold_optimization.py
Traceback (most recent call last):
  File "manifold_optimization.py", line 21, in <module>
    opti.subject_to(quat[k + 1] == (vector_SO3 + rotation_SO3).as_quat())
  File "/home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages/casadi/casadi.py", line 28146, in subject_to
    ret = self._subject_to(*args)
  File "/home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages/casadi/casadi.py", line 27470, in _subject_to
    return _casadi.Opti__subject_to(self, *args)
RuntimeError: Error in Opti::subject_to [OptiNode] at .../casadi/core/optistack.cpp:96:
.../casadi/core/optistack_internal.cpp:905: Assertion "!g.is_constant()" failed:
You passed a constant to `subject_to`. You need a symbol to form a constraint.

Furthermore, even if I did not reached this point, I noticed that the example refers ma27 (https://github.com/ami-iit/liecasadi/blob/c79d29e87d6d654e78d258a10bac9b2bbae35773/examples/manifold_optimization.py#L47), but by following the instruction of the repo casadi gets installed by pip, and I do not think that that version of casadi has hsl support enabled.

Environments in which I run the tests:

(castest) traversaro@IITICUBLAP257:~/liecasadi/examples$ mamba list
# packages in environment at /home/traversaro/mambaforge/envs/castest:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
attrs                     21.4.0                   pypi_0    pypi
ca-certificates           2021.10.8            ha878542_0    conda-forge
casadi                    3.5.5                    pypi_0    pypi
cycler                    0.11.0                   pypi_0    pypi
fonttools                 4.29.1                   pypi_0    pypi
kiwisolver                1.3.2                    pypi_0    pypi
ld_impl_linux-64          2.36.1               hea4e1c9_2    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 11.2.0              h1d223b6_12    conda-forge
libgomp                   11.2.0              h1d223b6_12    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libstdcxx-ng              11.2.0              he4da1e4_12    conda-forge
libzlib                   1.2.11            h36c2ea0_1013    conda-forge
liecasadi                 0.1.dev39                pypi_0    pypi
matplotlib                3.5.1                    pypi_0    pypi
ncurses                   6.3                  h9c3ff4c_0    conda-forge
numpy                     1.22.1                   pypi_0    pypi
openssl                   3.0.0                h7f98852_2    conda-forge
packaging                 21.3                     pypi_0    pypi
pillow                    9.0.0                    pypi_0    pypi
pip                       22.0.2             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.7                    pypi_0    pypi
python                    3.8.12          h0744224_3_cpython    conda-forge
python-dateutil           2.8.2                    pypi_0    pypi
python_abi                3.8                      2_cp38    conda-forge
readline                  8.1                  h46c0cb4_0    conda-forge
setuptools                60.6.0           py38h578d9bd_0    conda-forge
six                       1.16.0                   pypi_0    pypi
sqlite                    3.37.0               h9cd32fc_0    conda-forge
tk                        8.6.11               h27826a3_1    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
zlib                      1.2.11            h36c2ea0_1013    conda-forge
(castest) traversaro@IITICUBLAP257:~/liecasadi/examples$ pip list --verbose
Package         Version   Location                                                             Installer
--------------- --------- -------------------------------------------------------------------- ---------
attrs           21.4.0    /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
casadi          3.5.5     /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
cycler          0.11.0    /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
fonttools       4.29.1    /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
kiwisolver      1.3.2     /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
liecasadi       0.1.dev39 /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
matplotlib      3.5.1     /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
numpy           1.22.1    /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
packaging       21.3      /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
Pillow          9.0.0     /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
pip             22.0.2    /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages
pyparsing       3.0.7     /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
python-dateutil 2.8.2     /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
setuptools      60.6.0    /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages
six             1.16.0    /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages pip
wheel           0.37.1    /home/traversaro/mambaforge/envs/castest/lib/python3.8/site-packages
traversaro commented 2 years ago

fyi @CarlottaSartore @GiulioRomualdi (as I wanted to open the issue just for the ma27 part that I found via GitHub search, everything else was due to the fact that I wanted to reach the ma27 error but I was not able to reach it).

Giulero commented 2 years ago

@traversaro thanks for the feedback! :) I try to replicate the error on my machine.

Giulero commented 2 years ago

@traversaro the problem with the attr import was due to an automatic import in my IDE :disappointed: field, indeed, comes from dataclasses! Solved in a9d072d12ee3a7333c840a711868f41d017b3dee The error

RuntimeError: Error in Opti::subject_to [OptiNode] at .../casadi/core/optistack.cpp:96:
.../casadi/core/optistack_internal.cpp:905: Assertion "!g.is_constant()" failed:
You passed a constant to `subject_to`. You need a symbol to form a constraint.

instead comes from a change in the API that I did in the last commits: as_quat() was returning the coefficients of the quaternion, while now it returns a Quaternion instance (and hence casadi does not recognize it). To access the values you need to use as_quat().coeffs(). I also removed the ma27 dep. See 3422e4ff49d822d8ea46080c3fe34b500aa81ea6.

traversaro commented 2 years ago

Thanks!

I tried with a superclean conda environment with just python and pip, created with:

mamba create -n liecasaditest python=3.9 pip
mamba activate liecasaditest

and then installing:

pip install "liecasadi @ git+https://github.com/ami-iit/lie-casadi.git"
# For the example
pip install matplotlib

After that, the example failed with:

(liecasaditest) traversaro@IITICUBLAP257:~/liecasadi$ python examples/manifold_optimization.py

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************

This is Ipopt version 3.12.3, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).

Number of nonzeros in equality constraint Jacobian...:      814
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:      450

Total number of variables............................:      179
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:      114
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  0.0000000e+00 1.08e+00 0.00e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  1.1226556e+03 4.05e-02 8.17e+04  -1.0 6.10e+00    -  1.00e+00 1.00e+00h  1
   2  1.8990559e+03 7.27e-03 9.65e+05  -1.0 8.88e+00   4.0 1.00e+00 1.00e+00h  1
   3  1.9436912e+03 1.18e-04 4.44e+05  -1.0 1.55e+00   4.4 1.00e+00 1.00e+00h  1
   4  1.9460341e+03 2.52e-08 7.26e+02  -1.0 1.25e-02   3.9 1.00e+00 1.00e+00h  1
   5  1.9460360e+03 1.80e-08 7.26e+02  -3.8 5.92e-01   3.5 1.00e+00 3.05e-05h 16
   6  1.9452324e+03 1.84e-05 2.90e+01  -3.8 9.33e-03   3.9 1.00e+00 1.00e+00H  1
   7  1.7751446e+03 1.50e-03 2.10e+05  -5.7 4.88e+00    -  1.00e+00 1.00e+00f  1
   8  1.7801310e+03 1.29e-06 6.20e+02  -5.7 3.33e-02   3.4 1.00e+00 1.00e+00h  1
   9  1.7798743e+03 1.58e-09 3.07e+03  -5.7 6.47e-03   2.9 1.00e+00 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  1.7795838e+03 1.64e-05 5.00e+01  -5.7 2.14e-02   3.4 1.00e+00 1.00e+00f  1
  11  1.7574171e+03 1.12e-03 1.02e+05  -5.7 3.69e+00    -  1.00e+00 1.00e+00f  1
  12  1.7509892e+03 7.26e-07 1.05e+03  -5.7 8.50e-02   2.9 1.00e+00 1.00e+00f  1
  13  1.7508191e+03 6.97e-06 1.87e+01  -5.7 8.99e-03   3.3 1.00e+00 1.00e+00f  1
  14  1.6973885e+03 3.67e-04 6.98e+04  -5.7 2.09e+00    -  1.00e+00 1.00e+00f  1
  15  1.6888633e+03 2.04e-07 4.76e+02  -5.7 4.58e-02   2.8 1.00e+00 1.00e+00f  1
  16  1.6885783e+03 7.54e-06 1.58e+01  -5.7 8.56e-03   3.3 1.00e+00 1.00e+00f  1
  17  1.6742156e+03 1.30e-04 2.15e+04  -5.7 1.18e+00    -  1.00e+00 1.00e+00f  1
  18  1.6727965e+03 1.62e-08 5.71e+00  -5.7 4.67e-03   2.8 1.00e+00 1.00e+00f  1
  19  1.6689016e+03 2.74e-05 2.48e+05  -5.7 5.94e-01    -  1.00e+00 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  20  1.6687812e+03 4.89e-10 4.24e+00  -5.7 7.19e-04   3.2 1.00e+00 1.00e+00f  1
  21  1.6687741e+03 5.76e-08 1.36e+00  -5.7 2.47e-02    -  1.00e+00 1.00e+00f  1
  22  1.6687737e+03 1.30e-11 5.88e-02  -8.6 5.68e-04    -  1.00e+00 1.00e+00h  1
  23  1.6687737e+03 6.77e-15 1.42e-07  -8.6 8.58e-06    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 23

                                   (scaled)                 (unscaled)
Objective...............:   1.6687736910055917e+03    1.6687736910055917e+03
Dual infeasibility......:   1.4156103134155273e-07    1.4156103134155273e-07
Constraint violation....:   6.7723604502134549e-15    6.7723604502134549e-15
Complementarity.........:   0.0000000000000000e+00    0.0000000000000000e+00
Overall NLP error.......:   1.7590093435680195e-12    1.4156103134155273e-07

Number of objective function evaluations             = 41
Number of objective gradient evaluations             = 24
Number of equality constraint evaluations            = 41
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 24
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 23
Total CPU secs in IPOPT (w/o function evaluations)   =      0.018
Total CPU secs in NLP function evaluations           =      0.013

EXIT: Optimal Solution Found.
      solver  :   t_proc      (avg)   t_wall      (avg)    n_eval
       nlp_f  | 153.00us (  3.73us) 154.20us (  3.76us)        41
       nlp_g  |   1.41ms ( 34.27us)   1.41ms ( 34.42us)        41
  nlp_grad_f  | 201.00us (  8.04us) 197.70us (  7.91us)        25
  nlp_hess_l  |   6.64ms (288.83us)   6.65ms (289.13us)        23
   nlp_jac_g  |   5.42ms (216.80us)   5.43ms (217.16us)        25
       total  |  33.32ms ( 33.32ms)  33.32ms ( 33.32ms)         1
Traceback (most recent call last):
  File "/home/traversaro/mambaforge/envs/liecasaditest/lib/python3.9/site-packages/casadi/casadi.py", line 7605, in tocsc
    from scipy.sparse import csc_matrix
ModuleNotFoundError: No module named 'scipy'

The above exception was the direct cause of the following exception:

But this seems more to be a casadi problem. After installing scipy, the example works fine: Screenshot 2022-02-03 112836

(Note: I installed everything via pip just to validate the provided README instructions. Tipically, it is always a good idea to install as much python packages as possible via the "general" package maneger that you are using, i.e. either apt or conda, rather then installing packages via pip, to avoid incompatibilities.)

traversaro commented 2 years ago

Hi @Giulero, I just tried and the example still fails due to the missing matplotlib and scipy modules, perhaps it could be mentioned at the beginning of the example to install them to correctly run the example? If you prefer not, no problem, but in general it is good practice to always explain why an issue is being closed when you close an issue.

Giulero commented 2 years ago

Hi @traversaro! Sure, you're right :) I closed the issue since the problems related to the wrong attr import and the other the changed API were solved. I'll add a few lines at the beginning of the example for the installation of matplotlib and scipy !