8000 Matlab full template based OCP solver by yzuuang · Pull Request #934 · acados/acados · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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 18 commits into from
Jul 3, 2023
Merged

Matlab full template based OCP solver #934

merged 18 commits into from
Jul 3, 2023

Conversation

yzuuang
Copy link
Contributor
@yzuuang yzuuang commented Jun 2, 2023

The Matlab OCP solver interface is now also template based.
This closes #765

@FreyJo FreyJo changed the title WIP Matlab full template based Matlab full template based OCP solver Jun 16, 2023
Co 10000 py 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.

It looks very good! Happy that it works!
We discussed the cleanup of external QP solver flags to be pushed still.

@FreyJo FreyJo merged commit bb9f1b2 into acados:master Jul 3, 2023
@FreyJo FreyJo mentioned this pull request Mar 14, 2024
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make MEX wrapper around templated solver work on Windows
2 participants
0