8000 MATLAB: add p_global and GenerateContext by sandmaennchen · Pull Request #1241 · acados/acados · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged

Conversation

sandmaennchen
Copy link
Contributor
@sandmaennchen sandmaennchen commented Sep 5, 2024

This PR

  • introduces p_global to AcadosModel
  • introduces GenerateContext for code generation.

Compare also #1234.

And a minor cleanup of code generation in python.

@sandmaennchen sandmaennchen force-pushed the matlab_code_gen_with_context branch 2 times, most recently from fe33130 to aa3aeb3 Compare September 9, 2024 18:08
@sandmaennchen sandmaennchen marked this pull request as ready for review September 10, 2024 09:53
Copy link
Member
@FreyJo FreyJo left a 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)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member
@FreyJo FreyJo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐎

@sandmaennchen sandmaennchen force-pushed the matlab_code_gen_with_context branch from be19982 to 6697577 Compare September 11, 2024 08:20
@sandmaennchen sandmaennchen merged commit 30b3429 into acados:master Sep 11, 2024
12 checks passed
@sandmaennchen sandmaennchen deleted the matlab_code_gen_with_context branch September 11, 2024 09:25
FreyJo added a commit that referenced this pull request Sep 25, 2024
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>
FreyJo added a commit that referenced this pull request Oct 7, 2024
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>
FreyJo added a commit that referenced this pull request Oct 7, 2024
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>
FreyJo added a commit that referenced this pull request Oct 7, 2024
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>
FreyJo added a commit that referenced this pull request Oct 25, 2024
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0