Skip to content

Remove initial_state() in favor of history()

Tjerk Vreeken requested to merge remove-initial-state into master

Before we had the supposed default implementation in OptimizationProblem that history() also returned values in initial_state(), and vice versa. This would never actually work properly, as one would end up in an endless loop.

The reason this bug was not encountered until this point, is that ModelicaMixin did not call super() for initial_state(). Furthermore, PIMixin/IOMixin did not call super() either. So in practice we never got the behavior that history() referred to values in intial_state() and vice versa.

The "mother" method of the two is history(), as this is the only method actually called in CollocatedIntegratedOptimizationProblem. This means that when a user uses any IOMixin class, but implements their own initial_state() method, this method would never actually be called.

Furthermore, initial_state() on the user's class would be overruled by the history of e.g. PIMixin (a super class). This is very counter-intuitive.

To fix this bug, the only way is to remove initial_state(). This is API breaking, but the current implementation with both history() and initial_state() is very much broken as outlined above.

The option of letting history() also return scalar values would make the transition easier, but would also break a lot of code that relies on history() returning only Timeseries. We therefore keep the return value of history() as-is; an AliasDict[str, Timeseries].

Closes #1123 (closed)

Merge request reports