Deltares / rtc-tools

The Deltares toolbox for control and optimization of environmental systems.
GNU Lesser General Public License v3.0
0 stars 2 forks source link

Draft: adjust goals and homotopy parameter during optimization. #1560

Closed SGeeversAtVortech closed 1 month ago

SGeeversAtVortech commented 1 month ago

In GitLab by @SGeeversAtVortech on May 16, 2024, 11:51

This branch introduces ways to adjust the list of goals during optimization and making it depend on for example the homotopy parameter. It also enables the homotopy parameter theta to depend on time.

This branch seems unnecessary, since there are simpler ways to implement these properties without adding additional features to rtc-tools; see, for example, the comments in this MR and https://gitlab.com/deltares/bos-rijnland/-/merge_requests/42.

SGeeversAtVortech commented 1 month ago

In GitLab by @SGeeversAtVortech on May 16, 2024, 11:51

requested review from @SGeeversAtVortech

SGeeversAtVortech commented 1 month ago

In GitLab by @SGeeversAtVortech on May 16, 2024, 13:03

Commented on src/rtctools/optimization/goal_programming_mixin.py line 629

Why is subproblems replaced by self.__subproblems? It doesn't seem to be accessed outside of this method and it is a private variable, so you should not access it from outside this class.

SGeeversAtVortech commented 1 month ago

In GitLab by @SGeeversAtVortech on May 16, 2024, 13:24

There seems to be a new feature for setting theta as a timeseries, but this doesn't seem to be tested. Please add a unit test for this feature.

SGeeversAtVortech commented 1 month ago

In GitLab by @SGeeversAtVortech on May 16, 2024, 13:30

Commented on src/rtctools/optimization/homotopy_mixin.py line 65

Why not use self.__theta here? That should be correct.

SGeeversAtVortech commented 1 month ago

In GitLab by @SGeeversAtVortech on May 16, 2024, 13:55

Commented on src/rtctools/optimization/homotopy_mixin.py line 40

This syntax seems wrong. We're comparing a boolean with a float here. Please also check other comparisons involving .any().

SGeeversAtVortech commented 1 month ago

In GitLab by @SGeeversAtVortech on May 16, 2024, 17:01

Commented on src/rtctools/optimization/homotopy_mixin.py line 58

Can users set this parameter? How should they know?

SGeeversAtVortech commented 1 month ago

In GitLab by @SGeeversAtVortech on May 16, 2024, 17:07

It seems that in some applications, the private variable __subproblems are accessed and adjusted based on the homotopy parameter theta. Instead, we could adjust the goals and pathgoals method to select goals of certain priorities based on the theta parameter.

The goals method could look something like this:

def goals(self, ...):
    goals = ...  # usual calculation of goals
    theta = self.parameters()["theta"]
    priorities = ... # some logic based on theta
    goals = [goal for goal in goals if goal.priority in priorities]
    return goals
SGeeversAtVortech commented 1 month ago

In GitLab by @SGeeversAtVortech on May 16, 2024, 17:21

It seems that here, we try to add a feature for setting a homotopy parameter theta that can depend on time in a very specific way. Instead, the user could do the following: call the homotopy parameter parameter Real theta_ and add an input input Real theta(fixed=true) to the Modelica file. Then overwrite the homotopy_options method to set homotopy_parameter to theta_. Then extend the priority_started method to calculate theta. This method could look as follows.

def priority_started()
    ... # usual stuff
    theta_ = self.parameters()["theta_"]
    times = ...
    theta = ... # calculate theta
    self.set_timeseries("theta", times, theta)