Tim-Salzmann / l4casadi

Use PyTorch Models with CasADi for data-driven optimization or learning-based optimal control. Supports Acados.
MIT License
337 stars 22 forks source link

OSError: liblearned_dyn.so: cannot open shared object file: No such file or directory #4

Closed 438749902 closed 1 year ago

438749902 commented 1 year ago

Environment:

Windows10-22H2-lastest WSL2 - Ubuntu22.04 Pycharm2022.3.1 python3.10 venv with CUDA 11.7

Problem:

I can run examples/readme.py and examples/simple_nlp.py successfully, but when I run examples/acados.py, the output is:

/home/lty/venv/l4/bin/python /mnt/l/Python/MPC/l4casadi/examples/acados.py 
/mnt/l/Python/MPC/l4casadi/l4casadi/template_generation/bin/t_renderer
Warning: Please note that the following versions of CasADi  are officially supported: 3.5.6 or 3.5.5 or 3.5.4 or 3.5.3 or 3.5.2 or 3.5.1 or 3.4.5 or 3.4.0.
 If there is an incompatibility with the CasADi generated code, please consider changing your CasADi version.
Version 3.6.3 currently in use.
rm -f libacados_ocp_solver_wr.so
rm -f acados_solver_wr.o
cc -fPIC -std=c99   -O2 -I/home/lty/env/acados/include -I/home/lty/env/acados/include/acados -I/home/lty/env/acados/include/blasfeo/include -I/home/lty/env/acados/include/hpipm/include  -c -o acados_solver_wr.o acados_solver_wr.c
cc -fPIC -std=c99   -O2 -I/home/lty/env/acados/include -I/home/lty/env/acados/include/acados -I/home/lty/env/acados/include/blasfeo/include -I/home/lty/env/acados/include/hpipm/include  -c -o wr_model/wr_expl_ode_fun.o wr_model/wr_expl_ode_fun.c
cc -fPIC -std=c99   -O2 -I/home/lty/env/acados/include -I/home/lty/env/acados/include/acados -I/home/lty/env/acados/include/blasfeo/include -I/home/lty/env/acados/include/hpipm/include  -c -o wr_model/wr_expl_vde_forw.o wr_model/wr_expl_vde_forw.c
cc -fPIC -std=c99   -O2 -I/home/lty/env/acados/include -I/home/lty/env/acados/include/acados -I/home/lty/env/acados/include/blasfeo/include -I/home/lty/env/acados/include/hpipm/include  -c -o wr_model/wr_expl_vde_adj.o wr_model/wr_expl_vde_adj.c
cc -shared acados_solver_wr.o wr_model/wr_expl_ode_fun.o wr_model/wr_expl_vde_forw.o wr_model/wr_expl_vde_adj.o -o libacados_ocp_solver_wr.so -L/home/lty/env/acados/lib -lacados -lhpipm -lblasfeo -lm \
-L/mnt/l/Python/MPC/l4casadi/examples/_l4c_generated -llearned_dyn
acados was compiled without OpenMP.
Traceback (most recent call last):
  File "/mnt/l/Python/MPC/l4casadi/examples/acados.py", line 219, in <module>
    run()
  File "/mnt/l/Python/MPC/l4casadi/examples/acados.py", line 187, in run
    external_shared_lib_name=learned_dyn_model.name).solver
  File "/mnt/l/Python/MPC/l4casadi/examples/acados.py", line 83, in solver
    return AcadosOcpSolver(self.ocp())  # 求解器
  File "/home/lty/env/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py", line 960, in __init__
    self.shared_lib = CDLL(self.shared_lib_name)
  File "/usr/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: liblearned_dyn.so: cannot open shared object file: No such file or directory

end

I think that mean there is no "liblearned_dyn.so", could you tell me how to solve this problem? thank you

Tim-Salzmann commented 1 year ago

Hi,

can you verify if liblearned_dyn.so is actually missing? (Should be in examples/_l4c_generated).

If liblearned_dyn.so exists, please run

ldd libacados_ocp_solver_wr.so in examples/c_generated_code and post the output here.

My initial guess is that it has something to do with WSL. I am not able to test Windows and WSL, unfortunately.

438749902 commented 1 year ago

the liblearned_dyn.so is in examples/_l4c_generated.

lty@PC-LTY:/mnt/l/Python/MPC/l4casadi/examples/_l4c_generated$ ls
f.cpp   f_forward.pt  f_jacrev.pt  g.json        g_hess.pt    l4casadi_f.cpp   l4casadi_f_forward.pt  l4casadi_f_jacrev.pt  learned_dyn.json        learned_dyn_hess.pt    libf.so  libl4casadi_f.so
f.json  f_hess.pt     g.cpp        g_forward.pt  g_jacrev.pt  l4casadi_f.json  l4casadi_f_hess.pt     learned_dyn.cpp       learned_dyn_forward.pt  learned_dyn_jacrev.pt  libg.so  liblearned_dyn.so

then i run ldd libacados_ocp_solver_wr.so in examples/c_generated_code, the output is:

linux-vdso.so.1 (0x00007ffdd67f7000)
libacados.so => /home/lty/env/acados/lib/libacados.so (0x00007f907f901000)
liblearned_dyn.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f907f6d3000)
libqpOASES_e.so.3.1 => /home/lty/env/acados/lib/libqpOASES_e.so.3.1 (0x00007f907f696000)
libhpipm.so => /home/lty/env/acados/lib/libhpipm.so (0x00007f907f53c000)
libblasfeo.so => /home/lty/env/acados/lib/libblasfeo.so (0x00007f907f33e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f907f257000)
/lib64/ld-linux-x86-64.so.2 (0x00007f907f985000)
Tim-Salzmann commented 1 year ago

Hi,

for a quick fix: please add the absolute path to _l4c_generated to the LD_LIBRARY_PATH environment var.

I will try and find a better way to do this next week.

Best Tim

438749902 commented 1 year ago

the problem is solved, thank you very much! I add export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/l/Python/MPC/l4casadi/examples/_l4c_generated in .bashrc and pycharm, then the code is wrok correctly.

Tim-Salzmann commented 1 year ago

Hi,

This should not be required anymore. If you do a pull and a fresh install of the package, the example should now work without explicitly setting LD_LIBRARY_PATH.

Let me know if it works!

438749902 commented 1 year ago

I pull the newest code and it is worked correctly. image