Tim-Salzmann / l4casadi

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

issue with t_renderer #12

Closed alhaddad-m closed 1 year ago

alhaddad-m commented 1 year ago

Hi Tim! I have run my implementation with l4casadi and Acados and it was working fine. However, in last time I have executed again pip install . . After this moment I couldn't run my implementation as before. Now I have the following error when i run my code. I have installed l4casadi again but the error still same.

  File "/home/vladislav/.local/lib/python3.9/site-packages/l4casadi/template_generation/render.py", line 88, in render_template
    raise Exception(f'Rendering of {in_file} failed!\n\nAttempted to execute OS command:\n{os_cmd}\n\n')
Exception: Rendering of casadi_function.in.cpp failed!

Attempted to execute OS command:
/home/vladislav/.local/lib/python3.9/site-packages/l4casadi/template_generation/bin/t_renderer '/home/vladislav/.local/lib/python3.9/site-packages/l4casadi/template_generation/c_templates_tera/**/*' 'casadi_function.in.cpp' 'y_expr.json' 'y_expr.cpp'

Any suggestion? Best kind! Muhammad

Tim-Salzmann commented 1 year ago

Hi Muhammad,

can you please check that /home/vladislav/.local/lib/python3.9/site-packages/l4casadi/template_generation/bin/t_renderer exists? If it does exists please delete the 't_renderer' binary. It should be installed automatically during a L4CasADi run.

Could you additionally please state which OS you are running on.

Best Tim

alhaddad-m commented 1 year ago

I am working on OS Ubuntu 20.04. I have deleted the file and while running code, it was downloaded as following Dowloading https://github.com/acados/tera_renderer/releases/download/v0.0.34/t_renderer-v0.0.34-linux However the error isn't fixed. The whole message is

Error: Failed to render 'casadi_function.in.cpp'
Reason: Variable `model_expects_batch_dim` not found in context while rendering 'casadi_function.in.cpp'
Traceback (most recent call last):
  File "/home/vladislav/l4casadi/examples/mpc_cnn_model_tested.py", line 622, in <module>
    acados_solver = create_solver(model_loaded , W , W_e)
  File "/home/vladislav/l4casadi/examples/mpc_cnn_model_tested.py", line 346, in create_solver
    model , l4c_model = robot_model(model_loaded)
  File "/home/vladislav/l4casadi/examples/mpc_cnn_model_tested.py", line 332, in robot_model
    model.cost_y_expr = vertcat(sym_x, sym_u , l4c_model(vertcat(sym_p,x,y,theta)))
  File "/home/vladislav/l4casadi/l4casadi_custom/l4casadi.py", line 32, in __call__
    return self.forward(*args)
  File "/home/vladislav/l4casadi/l4casadi_custom/l4casadi.py", line 45, in forward
    self.get_ready(inp)
  File "/home/vladislav/l4casadi/l4casadi_custom/l4casadi.py", line 71, in get_ready
    self.generate_cpp_function_template(rows, cols, has_jac, has_hess)
  File "/home/vladislav/l4casadi/l4casadi_custom/l4casadi.py", line 104, in generate_cpp_function_template
    render_template(
  File "/home/vladislav/.local/lib/python3.9/site-packages/l4casadi/template_generation/render.py", line 88, in render_template
    raise Exception(f'Rendering of {in_file} failed!\n\nAttempted to execute OS command:\n{os_cmd}\n\n')
Exception: Rendering of casadi_function.in.cpp failed!

Attempted to execute OS command:
/home/vladislav/.local/lib/python3.9/site-packages/l4casadi/template_generation/bin/t_renderer '/home/vladislav/.local/lib/python3.9/site-packages/l4casadi/template_generation/c_templates_tera/**/*' 'casadi_function.in.cpp' 'y_expr.json' 'y_expr.cpp'
alhaddad-m commented 1 year ago

I have figured out the problem. I have used old l4casadi.py file in which there was has_batch and I didn't expect that it has been replaced in last version by model_expects_batch_dim. So I will close this issue. Thank you Tim. I hope I can compile C++ code with L4casadi.

Tim-Salzmann commented 1 year ago

Regarding C++ compilation. This was already done successfully: https://github.com/Tim-Salzmann/l4casadi/issues/9

If you run in trouble feel free to reach out to merdan-9 in that issue