-
Notifications
You must be signed in to change notification settings - Fork 280
MATLAB: add p_global and GenerateContext #1241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MATLAB: add p_global and GenerateContext #1241
Conversation
fe33130
to
aa3aeb3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments, but did not check the example carefully.
Overall looks very good!
@@ -1013,17 +1013,17 @@ def generate_external_functions(self, context: Optional[GenerateContext] = None) | |||
check_casadi_version() | |||
if self.model.dyn_ext_fun_type == 'casadi': | |||
if self.solver_options.integrator_type == 'ERK': | |||
generate_c_code_explicit_ode(context, model) | |||
generate_c_code_explicit_ode(context, model, model_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not adding the additional argument model_dir
, since all information is contained in the other arguments.
Also note that the functions generate_c_code_constraint
and the ones for the cost, dont have such an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the Matlab functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this way model_dir
is defined only once and not five times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one could move it to context though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we cant, because for multiphase the models vary but there is only one context.
I would prefer setting it up in place still but not too strongly.
...ados_template/acados_template/c_templates_tera/matlab_templates/acados_mex_set_p_global.in.c
Outdated
Show resolved
Hide resolved
...ados_template/acados_template/c_templates_tera/matlab_templates/acados_mex_set_p_global.in.c
Outdated
Show resolved
Hide resolved
...ados_template/acados_template/c_templates_tera/matlab_templates/acados_mex_set_p_global.in.c
Outdated
Show resolved
Hide resolved
interfaces/acados_template/acados_template/c_templates_tera/matlab_templates/mex_solver.in.m
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐎
be19982
to
6697577
Compare
This PR introduces some changes following up on the introduction of global parameters in #1234 and #1241 incorporating recent updates to CasADi including `blazing_spline`. Note that the use of `p_global` now requires CasADi version `nightly-se2`. --------- Co-authored-by: Joris Gillis <joris@yacoda.com> Co-authored-by: Jonathan Frey <jonathanpaulfrey@gmail.com>
This PR * introduces `p_global` to Acadosl. * introduces `GenerateContext` for code generation. Compare also #1234. And minor cleanup of code generation in python. --------- Co-authored-by: Jonathan Frey <jonathanpaulfrey@gmail.com>
This PR introduces some changes following up on the introduction of global parameters in #1234 and #1241 incorporating recent updates to CasADi including `blazing_spline`. Note that the use of `p_global` now requires CasADi version `nightly-se2`. --------- Co-authored-by: Joris Gillis <joris@yacoda.com> Co-authored-by: Jonathan Frey <jonathanpaulfrey@gmail.com>
This PR introduces some changes following up on the introduction of global parameters in #1234 and #1241 incorporating recent updates to CasADi including `blazing_spline`. Note that the use of `p_global` now requires CasADi version `nightly-se2`. --------- Co-authored-by: Joris Gillis <joris@yacoda.com> Co-authored-by: Jonathan Frey <jonathanpaulfrey@gmail.com>
Previously, as of #1241, `p_global` was only supported for `MX`, since the memory pool workflow is limited to this. The `p_global_precompute_fun` now computes the same stuff but has one output vector called `global_data` (a concatenation of all the expressions previously computed by the function). This `global_data` has been added to `ocp_nlp_in` and is added as a last input to all other external CasADi functions by the `GenerateContext`. Detailed changes below: #### OCP NLP Dimensions: * Added `np_global` and `n_global_data` fields to `ocp_nlp_dims` and initialized them in `ocp_nlp_dims_assign_self`. * Introduced `ocp_nlp_dims_set_global` function to set global fields in `ocp_nlp_dims` * Updated `ocp_nlp_in_calculate_size_self` and `ocp_nlp_in_assign_self` to handle global data. #### External Function Generic Enhancements: * Added `with_global_data` field to `external_function_opts` and corresponding default setter function. #### External Function CasADi Enhancements: * Added `set_global_data_pointer` function to `external_function_external_param_casadi` and updated related functions to handle global data. #### Bug Fixes and Code Clean-Up: * Fixed incorrect error messages and improved error handling in `external_function_casadi_wrapper` and `external_function_param_casadi_wrapper`. * Refactored parameter handling in `external_function_param_casadi_set_param` and `external_function_param_casadi_set_param_sparse`.
This PR
p_global
toAcadosModel
GenerateContext
for code generation.Compare also #1234.
And a minor cleanup of code generation in python.