brocksam / pycollo

General-purpose optimal control, trajectory optimisation and parameter optimisation using direct collocation
https://brocksam.github.io/pycollo/
MIT License
8 stars 3 forks source link

Bug fix for multiphase problems with variable time non-first phases #47

Closed brocksam closed 2 years ago

brocksam commented 2 years ago

This PR fixes a bug in the pycollo/solution/casadi_solution.py module in which phase final times tF were incorrectly extracted (extracted as phase initial times t0). This bug was only present in the CasADi backend and caused phase stretch scaling to be evaluated as 0 (due to t0 = tF), which in turn caused RuntimeWarnings to be raised due to divisions by 0. This then caused Pycollo to crash during a second mesh iteration due to a RuntimeError being raised as a result of attempting to index an array of variables out-of-bounds.

This PR also fixes a bug in the pycollo/solution/casadi_solution.py and pycollo/mesh_refinement.py modules in which the all_phase_mapping symbol mapping was incorrectly constructed for multiphase problems with variable numbers of discretisation nodes in their different phases. The creation of all_phase_mapping now ensures that only symbols associated with the relevant phase are included, and that phase-specified indices for decision variables are not exceeded.