Code error for python

Hi :wave:

In ‘GitHub - FreyJo/AS-RTI-acados at v1.0.0’ ,When I run file pendulum_benchmark.py, an error occurs:
OSError: /home/uav/AS-RTI-acados/AS-RTI-acados/c_generated_code/libacados_ocp_solver_pendulum.so: cannot open shared object file: No such file or directory

where can find this libacados_ocp_solver_pendulum.so file to resolve the error message?

Here are the all error message:

  File "pendulum_benchmark.py", line 707, in <module>
    run_pendulum_benchmark_closed_loop(SETTINGS)
  File "pendulum_benchmark.py", line 200, in run_pendulum_benchmark_closed_loop
    ocp_solver = setup_acados_ocp_solver(model,
  File "/home/uav/AS-RTI-acados/AS-RTI-acados/setup_acados_ocp_solver.py", line 282, in setup_acados_ocp_solver
    ocp_solver = AcadosOcpSolver(ocp, verbose=False)
  File "/home/uav/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py", line 248, in __init__
    self.__shared_lib = get_shared_lib(self.shared_lib_name, self.winmode)
  File "/home/uav/acados/interfaces/acados_template/acados_template/utils.py", line 130, in get_shared_lib
    shared_lib = DllLoader(shared_lib_name)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/uav/AS-RTI-acados/AS-RTI-acados/c_generated_code/libacados_ocp_solver_pendulum.so: cannot open shared object file: No such file or directory 

Hi,
this library should be generated in the c_generated_code folder when setting up AcadosOcpSolver.
Did you check out version v0.3.2 of acados as stated in the README of this repository?
Also maybe try to set verbose=True here, to see if anything goes wrong when compiling the solver:

Best,
Jonathan

I try to install acados v0.3.2 as follow:

  • first,creat a virtual environment
virtualenv as-rti --python=/usr/bin/python3
# Source the environment
source as-rti/bin/activate

But when i run a Python example <acados_root>/examples/acados_python/getting_started/minimal_example_ocp.pyto check that everything works, some of errors occur as:

acados_solver_pendulum_ode.c:998:5: error: too many arguments to function ‘ocp_nlp_get’
  998 |     ocp_nlp_get(capsule->nlp_config, capsule->nlp_solver, "stat_m", &stat_m);
      |     ^~~~~~~~~~~
In file included from acados_solver_pendulum_ode.c:37:
/home/uav/acados/include/acados_c/ocp_nlp_interface.h:438:27: note: declared here
  438 | ACADOS_SYMBOL_EXPORT void ocp_nlp_get(ocp_nlp_solver *solver, const char *field, void *return_value_);
      |                           ^~~~~~~~~~~
acados_solver_pendulum_ode.c:1002:24: warning: passing argument 1 of ‘ocp_nlp_get’ from incompatible pointer type [-Wincompatible-pointer-types]
 1002 |     ocp_nlp_get(capsule->nlp_config, capsule->nlp_solver, "statistics", stat);
      |                 ~~~~~~~^~~~~~~~~~~~
      |                        |
      |                        ocp_nlp_config * {aka struct ocp_nlp_config *}
In file included from acados_solver_pendulum_ode.c:37:
/home/uav/acados/include/acados_c/ocp_nlp_interface.h:438:55: note: expected ‘ocp_nlp_solver *’ {aka ‘struct ocp_nlp_solver *’} but argument is of type ‘ocp_nlp_config *’ {aka ‘struct ocp_nlp_config *’}
  438 | ACADOS_SYMBOL_EXPORT void ocp_nlp_get(ocp_nlp_solver *solver, const char *field, void *return_value_);
      |                                       ~~~~~~~~~~~~~~~~^~~~~~
acados_solver_pendulum_ode.c:1002:45: warning: passing argument 2 of ‘ocp_nlp_get’ from incompatible pointer type [-Wincompatible-pointer-types]
 1002 |     ocp_nlp_get(capsule->nlp_config, capsule->nlp_solver, "statistics", stat);
      |                                      ~~~~~~~^~~~~~~~~~~~
      |                                             |
      |                                             ocp_nlp_solver * {aka struct ocp_nlp_solver *}
In file included from acados_solver_pendulum_ode.c:37:
/home/uav/acados/include/acados_c/ocp_nlp_interface.h:438:75: note: expected ‘const char *’ but argument is of type ‘ocp_nlp_solver *’ {aka ‘struct ocp_nlp_solver *’}
  438 | _EXPORT void ocp_nlp_get(ocp_nlp_solver *solver, const char *field, void *return_value_);
      |                                                  ~~~~~~~~~~~~^~~~~

acados_solver_pendulum_ode.c:1002:5: error: too many arguments to function ‘ocp_nlp_get’
 1002 |     ocp_nlp_get(capsule->nlp_config, capsule->nlp_solver, "statistics", stat);
      |     ^~~~~~~~~~~
In file included from acados_solver_pendulum_ode.c:37:
/home/uav/acados/include/acados_c/ocp_nlp_interface.h:438:27: note: declared here
  438 | ACADOS_SYMBOL_EXPORT void ocp_nlp_get(ocp_nlp_solver *solver, const char *field, void *return_value_);
      |                           ^~~~~~~~~~~
make: *** [<内置>:acados_solver_pendulum_ode.o] 错误 1
acados was compiled without OpenMP.
Traceback (most recent call last):
  File "minimal_example_ocp.py", line 104, in <module>
    main()
  File "minimal_example_ocp.py", line 83, in main
    ocp_solver = AcadosOcpSolver(ocp, json_file = 'acados_ocp.json')
  File "/home/uav/AS-RTI-acados/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py", line 249, in __init__
    self.shared_lib = DllLoader(self.shared_lib_name)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/uav/AS-RTI-acados/acados/examples/acados_python/getting_started/c_generated_code/libacados_ocp_solver_pendulum_ode.so: cannot open shared object file:

how can i deal with these error ?

I install acados v0.3.2 and run a Python example with no error, and how can I confirm that I have correctly installed this version of acados? i run pendulum_benchmark.py again and get:

(as-rti-env) uav@uav-NUC12WSKi5:~/AS-RTI-acados/AS-RTI-acados$ python3 pendulum_benchmark.py 
/home/uav/AS-RTI-acados/as-rti-env/lib/python3.8/site-packages/scipy/__init__.py:143: UserWarning: A NumPy version >=1.19.5 and <1.27.0 is required for this version of SciPy (detected version 1.17.4)
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
--------
Warning: Please note that the following versions of CasADi are officially supported: 3.4.03.4.5 or 3.5.1 or 3.5.2 or 3.5.3 or 3.5.4 or 3.5.6 or 3.5.5 or 3.6.0 or 3.6.1 or 3.6.2 or 3.6.3 or 3.6.4.
 If there is an incompatibility with the CasADi generated code, please consider changing your CasADi version.
Version 3.6.7 currently in use.
Initial cost is None, skipping.
Translating path NONLINEAR_LS cost to CONVEX_OVER_NONLINEAR.
Translating terminal NONLINEAR_LS cost to CONVEX_OVER_NONLINEAR.
Warning: Please note that the following versions of CasADi are officially supported: 3.4.03.4.5 or 3.5.1 or 3.5.2 or 3.5.3 or 3.5.4 or 3.5.6 or 3.5.5 or 3.6.0 or 3.6.1 or 3.6.2 or 3.6.3 or 3.6.4.
 If there is an incompatibility with the CasADi generated code, please consider changing your CasADi version.
Version 3.6.7 currently in use.
Traceback (most recent call last):
  File "pendulum_benchmark.py", line 707, in <module>
    run_pendulum_benchmark_closed_loop(SETTINGS)
  File "pendulum_benchmark.py", line 200, in run_pendulum_benchmark_closed_loop
    ocp_solver = setup_acados_ocp_solver(model,
  File "/home/uav/AS-RTI-acados/AS-RTI-acados/setup_acados_ocp_solver.py", line 288, in setup_acados_ocp_solver
    ocp_solver = AcadosOcpSolver(ocp, verbose=False)
  File "/home/uav/AS-RTI-acados/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py", line 249, in __init__
    self.shared_lib = DllLoader(self.shared_lib_name)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/uav/AS-RTI-acados/AS-RTI-acados/c_generated_code/libacados_ocp_solver_pendulum.so: cannot open shared object file: No such file or directory

i uninstall acados and delete the virtual environment, install acadosv0.3.2 again in a new virtual environment,when i run pendulum_benchmark.py

(as-rti-env) uav@uav-NUC12WSKi5:~/AS-RTI-acados/AS-RTI-acados$ python pendulum_benchmark.py 
/home/uav/AS-RTI-acados/as-rti-env/lib/python3.8/site-packages/scipy/__init__.py:143: UserWarning: A NumPy version >=1.19.5 and <1.27.0 is required for this version of SciPy (detected version 1.17.4)
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
--------
Traceback (most recent call last):
  File "pendulum_benchmark.py", line 707, in <module>
    run_pendulum_benchmark_closed_loop(SETTINGS)
  File "pendulum_benchmark.py", line 164, in run_pendulum_benchmark_closed_loop
    integrator = setup_acados_integrator(plant_model, DT_PLANT, mpc_params,
  File "/home/uav/AS-RTI-acados/AS-RTI-acados/setup_acados_integrator.py", line 75, in setup_acados_integrator
    acados_integrator = AcadosSimSolver(sim, verbose=False)
  File "/home/uav/AS-RTI-acados/acados/interfaces/acados_template/acados_template/acados_sim_solver.py", line 283, in __init__
    self.shared_lib = DllLoader(self.shared_lib_name, winmode=self.winmode)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/uav/AS-RTI-acados/AS-RTI-acados/c_generated_code/libacados_sim_solver_pendulum_plant.so: cannot open shared object file: No such file or directory

it is another error

Hi,

The steps you describe to install acados seem correct.
I just ran the benchmark code locally on my machine.
It also works with the latest acados main branch, so the acados version is probably not the issue.
Please try to go step by step:

  1. make sure the minimal example works on your machine.
  2. test the AS-RTI example within acados: examples/acados_python/pendulum_on_cart/as_rti/as_rti_closed_loop_example.py
  3. Run the benchmark, but make sure the verbose flags are set to True to not miss an error message.
  4. If you get the error about the missing library, and there is no compiler error before, check if the library is indeed there to rule out if it just cannot be loaded for some reason.

Hope you can reproduce the results soon!

EDIT: I see that there might be a regression in AS-RTI-C, the plot looks wrong when running with the latest acados version. I will try to debug this soon. Please for now use the referenced acados version.

HI!
i install acados (version:v0.3.5_stable), run the minimal example /examples/acados_python/getting_started/minimal_example_ocp.py and examples/acados_python/pendulum_on_cart/as_rti/as_rti_closed_loop_example.py, the results can be show as follow:


but when i run pendulum_benchmark.py,errors show as:

(as-rti-env) uav@uav-NUC12WSKi5:~/AS-RTI-acados/AS-RTI-2/AS-RTI-acados$ python pendulum_benchmark.py 
/home/uav/AS-RTI-acados/as-rti-env/lib/python3.8/site-packages/scipy/__init__.py:143: UserWarning: A NumPy version >=1.19.5 and <1.27.0 is required for this version of SciPy (detected version 1.17.4)
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
Warning: Please note that the following versions of CasADi are officially supported: 3.4.03.4.5 or 3.5.1 or 3.5.2 or 3.5.3 or 3.5.4 or 3.5.6 or 3.5.5 or 3.6.0 or 3.6.1 or 3.6.2 or 3.6.3 or 3.6.4 or 3.6.5.
 If there is an incompatibility with the CasADi generated code, please consider changing your CasADi version.
Version 3.6.7 currently in use.
Initial cost is None, skipping.
Translating path NONLINEAR_LS cost to CONVEX_OVER_NONLINEAR.
Translating terminal NONLINEAR_LS cost to CONVEX_OVER_NONLINEAR.
Warning: Please note that the following versions of CasADi are officially supported: 3.4.03.4.5 or 3.5.1 or 3.5.2 or 3.5.3 or 3.5.4 or 3.5.6 or 3.5.5 or 3.6.0 or 3.6.1 or 3.6.2 or 3.6.3 or 3.6.4 or 3.6.5.
 If there is an incompatibility with the CasADi generated code, please consider changing your CasADi version.
Version 3.6.7 currently in use.
rm -f libacados_ocp_solver_pendulum.so
rm -f pendulum_cost/pendulum_conl_cost_0_fun.o pendulum_cost/pendulum_conl_cost_0_fun_jac_hess.o pendulum_cost/pendulum_conl_cost_fun.o pendulum_cost/pendulum_conl_cost_fun_jac_hess.o pendulum_cost/pendulum_conl_cost_e_fun.o pendulum_cost/pendulum_conl_cost_e_fun_jac_hess.o acados_solver_pendulum.o
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o pendulum_cost/pendulum_conl_cost_0_fun.o pendulum_cost/pendulum_conl_cost_0_fun.c
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o pendulum_cost/pendulum_conl_cost_0_fun_jac_hess.o pendulum_cost/pendulum_conl_cost_0_fun_jac_hess.c
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o pendulum_cost/pendulum_conl_cost_fun.o pendulum_cost/pendulum_conl_cost_fun.c
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o pendulum_cost/pendulum_conl_cost_fun_jac_hess.o pendulum_cost/pendulum_conl_cost_fun_jac_hess.c
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o pendulum_cost/pendulum_conl_cost_e_fun.o pendulum_cost/pendulum_conl_cost_e_fun.c
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o pendulum_cost/pendulum_conl_cost_e_fun_jac_hess.o pendulum_cost/pendulum_conl_cost_e_fun_jac_hess.c
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o acados_solver_pendulum.o acados_solver_pendulum.c
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o pendulum_model/pendulum_impl_dae_fun.o pendulum_model/pendulum_impl_dae_fun.c
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o pendulum_model/pendulum_impl_dae_fun_jac_x_xdot_z.o pendulum_model/pendulum_impl_dae_fun_jac_x_xdot_z.c
cc -fPIC -std=c99   -O2 -DACADOS_WITH_DAQP -I/home/uav/AS-RTI-acados/acados/include -I/home/uav/AS-RTI-acados/acados/include/acados -I/home/uav/AS-RTI-acados/acados/include/blasfeo/include -I/home/uav/AS-RTI-acados/acados/include/hpipm/include -I /home/uav/AS-RTI-acados/acados/include/daqp/include  -c -o pendulum_model/pendulum_impl_dae_jac_x_xdot_u_z.o pendulum_model/pendulum_impl_dae_jac_x_xdot_u_z.c
cc -shared pendulum_cost/pendulum_conl_cost_0_fun.o pendulum_cost/pendulum_conl_cost_0_fun_jac_hess.o pendulum_cost/pendulum_conl_cost_fun.o pendulum_cost/pendulum_conl_cost_fun_jac_hess.o pendulum_cost/pendulum_conl_cost_e_fun.o pendulum_cost/pendulum_conl_cost_e_fun_jac_hess.o acados_solver_pendulum.o pendulum_model/pendulum_impl_dae_fun.o pendulum_model/pendulum_impl_dae_fun_jac_x_xdot_z.o pendulum_model/pendulum_impl_dae_jac_x_xdot_u_z.o -o libacados_ocp_solver_pendulum.so -L/home/uav/AS-RTI-acados/acados/lib -lacados -lhpipm -lblasfeo -lm -ldaqp \
-L -l
acados was compiled without OpenMP.

error: ocp_qp_xcond_solver_config_initialize_from_plan: unsupported plan->qp_solver
This might happen, if acados was not compiled with the specified QP solver.

what should i do next? hope to hear from you!

Hi,

now I see.
The benchmark uses DAQP as a QP solver.
You need to compile acados with this QP solver enabled.
Please add: -DACADOS_WITH_DAQP=ON to your cmake command.
Let me know if you can reproduce the results then :slight_smile:

thanks,I have resolved this issue and obtained the corresponding chart,and i have some questions about the code in AS-RTI-acados/simulate.py at 4349509154b127b4c36ef95ebef839351e494692 · FreyJo/AS-RTI-acados · GitHub
What is the effect of the loop here?I can’t understand it very well

hi, Sincerely, may I ask how relative suboptimality is calculated in the code?

Hi,
the loop over n_runs is just to get consistent timings.
The minimum computation time over the runs is evaluated to filter out artifacts from the operating system, other processes running etc.

The relative suboptimality is computed by comparing the closed-loop costs of controllers with respect to an “ideal” one, which is superior to the others as it contains more shooting nodes. This is also described in our paper.

Best,
Jonathan

Also, I fixed a bug in AS-RTI-C, and the benchmark should now also work with the latest main branch of acados, see Fix AS-RTI-C by FreyJo · Pull Request #1443 · acados/acados · GitHub

ok! thank you very much!

Thank you very much for your answer. If there are any further questions about the code, I will continue to ask. Thank you again for your enthusiastic response.

1 Like