pyomeca / bioptim

An optimization framework that links CasADi, Ipopt, ACADOS and biorbd for Optimal Control Problem
MIT License
94 stars 47 forks source link

Setting integration tolerance #588

Closed jcllau closed 1 year ago

jcllau commented 1 year ago

Hello!

I noticed that one can set convergence tolerance, but is there a way to set integration tolerance too (separate from convergence)? Is there a file / document I can refer to for more information related to the integration tolerance (e.g. its default value)? I looked into ode_solver.py and integrator.py but found nothing.

mickaelbegon commented 1 year ago

@jcllau, bioptim relies on fixed step ODE solver, such as RK4. You can increase the accuracy by increasing the number of steps of the integrators. By experience, using 5-step RK4 (default) or even better collocations (Legendre 4th order) provides good dynamic consistency for our applications (we often use 50-100 intervals/s). There is also CVODES available (https://computing.llnl.gov/projects/sundials/cvodes; (Adams-Moulton and BDF)), but we have limited experience with this solver. Based on our experience, it is slow, but it needs to be further explored. Not sure this solver will work with all features.

Ipuch commented 1 year ago

@jcllau Did it help to solve your problem? Can we close the issue? let us know. Regards, Pierre

jcllau commented 1 year ago

Hi both! Sorry for the late response.

@mickaelbegon I see. Thank you for your explanation. If I want to control the precision of my results, which parameter would it be and how can I add it in my code? Also, so far I know how to change the convergence tolerance by doing solver_ipopt.set_convergence_tolerance(1e-5), but is there a way to change the acceptable tolerance (default 1e-6) as well because both values seem to be related to each other according to the ipopt documentation

Meanwhile, I have another question related to objective function weights, so I will create a new issue in a bit.

Best, Jan

Ipuch commented 1 year ago

The easy way to increase precision is to increase the number of shooting node, I would say. You could increase the number of intermediate steps with RK-type OdeSolvers, and with IRK and COLLOCATION, you can increase the polynomial degree. These are all arguments of subclass of OdeSolver.

Indeed, The other way is to change the tolerance of the solver. Acceptable tolerance and convergence are linked in IPOPT. After multiple trials, we decided to group them as it didn't have any influence otherwise.

I think you can access the parameter like this:

solver_options = SolverOption.IPOPT()
solver_options._constr_viol_tol = XXX
solver_options._acceptable_tol = XXX

If it is enough clear, let me know.

Ipuch commented 1 year ago

up @jcllau

pariterre commented 1 year ago

Closed as this issue was staled