alphaville / optimization-engine

Nonconvex embedded optimization: code generation for fast real-time optimization + ROS support
https://alphaville.github.io/optimization-engine/
Other
499 stars 53 forks source link

Preconditioning #292

Closed alphaville closed 1 year ago

alphaville commented 1 year ago

Main Changes

To activate the preconditioning use

solver_cfg = og.config.SolverConfiguration() \
    .with_preconditioning(True)

A number of changes have been reviewed in PRs which have been merged into this one. In particular (older to newer),

Associated Issues

Releases

TODOs

alphaville commented 1 year ago

@smokinmirror @Arun-R-M this is almost done I believe. Can you guys have a quick look and do a first review? I would like to send it to Emil as well. There are a couple more things that need to be done, but I would like to merge this in a few days if nothing unexpected comes up.

alphaville commented 1 year ago

Found error during compilation in windows pycharm environment: UnicodeEncodeError: 'charmap' codec can't encode character '\u03c1' in position 9215: character maps to

Analysed to be due to symbol 'ρ' used in the generated files. Similar issues found for symbols 'ξ' and 'θ' as well.

Thanks, @Arun-R-M. How/when does this error occur?

Arun-R-M commented 1 year ago

@alphaville It is just compilation issue stating that the above mentioned special characters are not supported. This brings to the question if the test is run on windows. I see continuous integration tests for Ubuntu and macos, but not for windows.

alphaville commented 1 year ago

@alphaville It is just compilation issue stating that the above mentioned special characters are not supported. This brings to the question if the test is run on windows. I see continuous integration tests for Ubuntu and macos, but not for windows.

We use Appveyor for testing on Windows. Now GitHub Actions support Windows as well, but we haven't set it up. However, we test only the Rust code on Windows. I had tried to run the Python tests there too, and this led to #36, which has been open since June 2019.

It will be great if you can set up GitHub Actions to run on Windows too.

Could you paste here the output you get and all the compilation errors?

Arun-R-M commented 1 year ago

The earlier issue in special symbol was fixed fixed with a recent push.

Arun-R-M commented 1 year ago

Below is the current issue being faced:

[INFO] Building optimizer
error: failed to parse manifest at `D:\PycharmProjects\OpEn_Fix_107\open-codegen\opengen\my_optimizers\rosenbrock\Cargo.toml`
Caused by:
  could not parse input as TOML
Caused by:
  TOML parse error at line 19, column 35
     |
  19 | optimization_engine = {path = "D:\PycharmProjects\OpEn_Fix_107\"}
     |                                   ^
  Unexpected `P`
  While parsing escape sequence
  While parsing a Basic String
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm 2021.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2021.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/PycharmProjects/OpEn_Fix_107/open-codegen/opengen/main.py", line 47, in <module>
    builder.build()
  File "D:\PycharmProjects\OpEn_Fix_107\venv\lib\site-packages\opengen\builder\optimizer_builder.py", line 804, in build
    self.__build_optimizer()             # build overall project
  File "D:\PycharmProjects\OpEn_Fix_107\venv\lib\site-packages\opengen\builder\optimizer_builder.py", line 570, in __build_optimizer
    raise Exception('Rust build failed')
Exception: Rust build failed

The issue has been analysed to be due to the function get_open_local_absolute_path() in main.py providing an address path incompatible with windows.

alphaville commented 1 year ago

Below is the current issue being faced:

[INFO] Building optimizer
error: failed to parse manifest at `D:\PycharmProjects\OpEn_Fix_107\open-codegen\opengen\my_optimizers\rosenbrock\Cargo.toml`
Caused by:
  could not parse input as TOML
Caused by:
  TOML parse error at line 19, column 35
     |
  19 | optimization_engine = {path = "D:\PycharmProjects\OpEn_Fix_107\"}
     |                                   ^
  Unexpected `P`
  While parsing escape sequence
  While parsing a Basic String
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm 2021.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2021.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/PycharmProjects/OpEn_Fix_107/open-codegen/opengen/main.py", line 47, in <module>
    builder.build()
  File "D:\PycharmProjects\OpEn_Fix_107\venv\lib\site-packages\opengen\builder\optimizer_builder.py", line 804, in build
    self.__build_optimizer()             # build overall project
  File "D:\PycharmProjects\OpEn_Fix_107\venv\lib\site-packages\opengen\builder\optimizer_builder.py", line 570, in __build_optimizer
    raise Exception('Rust build failed')
Exception: Rust build failed

The issue has been analysed to be due to the function get_open_local_absolute_path() in main.py providing an address path incompatible with windows.

The reason is that Windows uses \ as a separator and when you use it in your Cargo.toml, it escapes the closing quotation mark. The question is how to create paths with / that work both on Windown and Linux/MacOS. This affects only developers (no user will use with_local_path).

@Arun-R-M and @smokinmirror I will leave this to you to figure out as you - for some reason - use Windows. I cannot reproduce the error.

alphaville commented 1 year ago

@korken89 we have implemented a preconditioning that seems to speed things up and lead to a more robust behaviour. For example, we noticed that the preconditioned solver can solve certain problems that the previous version cannot. It also seems to perform better with multiple shooting formulations. Can you have a look at this PR? Any comments are welcome.

@smokinmirror and @Arun-R-M any final comments from your side? If not, can you approve this PR?

@Arun-R-M there seems to be a bug on Windows when using local_path. I believe this does not need to be addressed in this PR, so the best way forward is to create an issue (a bug report) and resolve this in a separate PR.

korken89 commented 1 year ago

I gave it a quick spin on an calibration problem I am currently working on that was a bit sensitive to starting guess. This did indeed help make it more robust! Awesome work!

alphaville commented 1 year ago

Thank you all for contributing to this PR. I am going to merge it now.