-
Notifications
You must be signed in to change notification settings - Fork 280
Matlab full template based OCP solver #934
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…properly set function parameters
FreyJo
approved these changes
Jun 16, 2023
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.
It looks very good! Happy that it works!
We discussed the cleanup of external QP solver flags to be pushed still.
FreyJo
added a commit
that referenced
this pull request
Aug 16, 2024
Announced in https://discourse.acados.org/t/matlab-interface-overhaul-to-match-the-python-interface-in-solver-creation/1721 This PR applies only minimal changes to the examples, example and documentation update will follow soon and TODOs are tracked in #1196 ## Key updates With this PR, the problem formulation objects closely match the Python correspondents. The changes are detailed and motivated below. ### OCP solver creation An acados OCP solver can now be created in different ways. Option 1) is planned to be deprecated in a future release, option 2) is the preferred one for which new features will be added and option 3) is a way to transition to the new interface, which only requires minimal changes to existing code and will be supported longer than 1). #### 1) old / legacy style Previously, an acados OCP solver in Matlab was created by calling: ``` % create OCP ocp_model = acados_ocp_model(); ocp_opts = acados_ocp_opts(); % set fields of ocp_model, ocp_opts using ocp_model.set(...) ocp_solver = acados_ocp(ocp_model, ocp_opts); ``` The classes `acados_ocp_model`, `acados_ocp_opts` and `acados_ocp` are part of the **legacy** Matlab interface of acados. This will still work in `acados` `v0.4.*`. However, we plan on deprecating it and suggest for users to transition to the new interface 2), or the explicit translation to the new formulation object 3), both detailed below. BREAKING CHANGES: The differences in behavior are that: 1) `acados_ocp` returns an `AcadosOcpSolver` object, which can be interacted with similarly to the old `acados_ocp` class. 2) The `AcadosOcpSolver` does not have fields `model_struct` and `opts_struct` corresponding to the legacy interface, instead there is a field `ocp` of type `AcadosOcp` from which information about the problem and solver can be deduced. #### 2) new interface for OCP solver description The new Matlab interface to describe OCP solvers for their creation can be used with the following syntax: ``` % OCP formulation ocp = AcadosOcp(); % provide OCP formulation and solver options by setting properties ocp_solver = AcadosOcpSolver(ocp); ``` An example for this can be found in the file [`new_minimal_example_ocp.m`](https://github.com/acados/acados/blob/matlab_interface_overhaul/examples/acados_matlab_octave/getting_started/new_minimal_example_ocp.m) Interactions with `AcadosOcpSolver` follow the same syntax as before, `.set(), .get()`, with the `acados_ocp` class. #### 3) transition to new interface The easiest way to update your code to change your code from ``` ocp_solver = acados_ocp(ocp_model, ocp_opts); ``` to ``` ocp = setup_AcadosOcp_from_legacy_ocp_description(ocp_model, ocp_opts) ocp_solver = AcadosOcpSolver(ocp); ``` This makes the translation of the old formulation objects into the new one more explicit. This also helps users who want to transition to the new interface. One can compare the `AcadosOcp` objects obtained with the new interface with the one obtained by the function `setup_AcadosOcp_from_legacy_ocp_description`. ### Integrator / solver for initial value problems creation The changes done to the integrator interface are pretty much analogous to the one of the OCP solver. An example can be found in the file [`new_minimal_example_sim.m`](https://github.com/acados/acados/blob/matlab_interface_overhaul/examples/acados_matlab_octave/getting_started/new_minimal_example_sim.m) ## Background and Motivation The classes `AcadosOcp` and subclasses `AcadosModel`, `AcadosOcpConstraints`, `AcadosOcpCost`, `AcadosOcpDims`, `AcadosOcpOptions` now completely match their Python correspondents, which are extensively documented. The mismatch between some names between the Matlab and Python interface was causing trouble for both users and developers of acados. These classes have existed in Matlab for a long time now, but were primarily used in the background. Internally, there has been a translation function, similar to `setup_AcadosOcp_from_legacy_ocp_description` for a long time, since the existence of an `acados` Simulink interface, and more prominently, since the whole Matlab interface uses the template based solver as a backend, introduced in [PR #934](#934). Lastly, this cleanup, will enable an extension of the Matlab interface to acados OCP solvers based on multi-phase OCP formulations, which we plan for the near future. --------- Co-authored-by: sandmaennchen <katrin.baumgaertner@posteo.de>
FreyJo
added a commit
that referenced
this pull request
Aug 21, 2024
Announced in https://discourse.acados.org/t/matlab-interface-overhaul-to-match-the-python-interface-in-solver-creation/1721 This PR applies only minimal changes to the examples, example and documentation update will follow soon and TODOs are tracked in #1196 With this PR, the problem formulation objects closely match the Python correspondents. The changes are detailed and motivated below. An acados OCP solver can now be created in different ways. Option 1) is planned to be deprecated in a future release, option 2) is the preferred one for which new features will be added and option 3) is a way to transition to the new interface, which only requires minimal changes to existing code and will be supported longer than 1). Previously, an acados OCP solver in Matlab was created by calling: ``` % create OCP ocp_model = acados_ocp_model(); ocp_opts = acados_ocp_opts(); % set fields of ocp_model, ocp_opts using ocp_model.set(...) ocp_solver = acados_ocp(ocp_model, ocp_opts); ``` The classes `acados_ocp_model`, `acados_ocp_opts` and `acados_ocp` are part of the **legacy** Matlab interface of acados. This will still work in `acados` `v0.4.*`. However, we plan on deprecating it and suggest for users to transition to the new interface 2), or the explicit translation to the new formulation object 3), both detailed below. BREAKING CHANGES: The differences in behavior are that: 1) `acados_ocp` returns an `AcadosOcpSolver` object, which can be interacted with similarly to the old `acados_ocp` class. 2) The `AcadosOcpSolver` does not have fields `model_struct` and `opts_struct` corresponding to the legacy interface, instead there is a field `ocp` of type `AcadosOcp` from which information about the problem and solver can be deduced. The new Matlab interface to describe OCP solvers for their creation can be used with the following syntax: ``` % OCP formulation ocp = AcadosOcp(); % provide OCP formulation and solver options by setting properties ocp_solver = AcadosOcpSolver(ocp); ``` An example for this can be found in the file [`new_minimal_example_ocp.m`](https://github.com/acados/acados/blob/matlab_interface_overhaul/examples/acados_matlab_octave/getting_started/new_minimal_example_ocp.m) Interactions with `AcadosOcpSolver` follow the same syntax as before, `.set(), .get()`, with the `acados_ocp` class. The easiest way to update your code to change your code from ``` ocp_solver = acados_ocp(ocp_model, ocp_opts); ``` to ``` ocp = setup_AcadosOcp_from_legacy_ocp_description(ocp_model, ocp_opts) ocp_solver = AcadosOcpSolver(ocp); ``` This makes the translation of the old formulation objects into the new one more explicit. This also helps users who want to transition to the new interface. One can compare the `AcadosOcp` objects obtained with the new interface with the one obtained by the function `setup_AcadosOcp_from_legacy_ocp_description`. The changes done to the integrator interface are pretty much analogous to the one of the OCP solver. An example can be found in the file [`new_minimal_example_sim.m`](https://github.com/acados/acados/blob/matlab_interface_overhaul/examples/acados_matlab_octave/getting_started/new_minimal_example_sim.m) The classes `AcadosOcp` and subclasses `AcadosModel`, `AcadosOcpConstraints`, `AcadosOcpCost`, `AcadosOcpDims`, `AcadosOcpOptions` now completely match their Python correspondents, which are extensively documented. The mismatch between some names between the Matlab and Python interface was causing trouble for both users and developers of acados. These classes have existed in Matlab for a long time now, but were primarily used in the background. Internally, there has been a translation function, similar to `setup_AcadosOcp_from_legacy_ocp_description` for a long time, since the existence of an `acados` Simulink interface, and more prominently, since the whole Matlab interface uses the template based solver as a backend, introduced in [PR #934](#934). Lastly, this cleanup, will enable an extension of the Matlab interface to acados OCP solvers based on multi-phase OCP formulations, which we plan for the near future. --------- Co-authored-by: sandmaennchen <katrin.baumgaertner@posteo.de>
sandmaennchen
added a commit
that referenced
this pull request
Sep 12, 2024
The option ` codgen_model` is no longer supported. It effectively does not work anymore since the migration to a fully template based backend, i.e. in #934
FreyJo
pushed a commit
that referenced
this pull request
Oct 7, 2024
The option ` codgen_model` is no longer supported. It effectively does not work anymore since the migration to a fully template based backend, i.e. in #934
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Matlab OCP solver interface is now also template based.
This closes #765