Deltares / rtc-tools

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

Delayed feedback expressions - [merged] #1260

Closed SGeeversAtVortech closed 1 week ago

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 17, 2018, 18:01

Merges delayed-feedback-expressions -> master

To Do:

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 18, 2018, 24:22

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 18, 2018, 24:22

marked the checklist item Compute and prepend history for delayed expression. as completed

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 18, 2018, 24:23

unmarked as a Work In Progress

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 18, 2018, 21:42

added 20 commits

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 18, 2018, 21:44

marked as a Work In Progress

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 18, 2018, 22:08

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 19, 2018, 02:03

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1034

I imagine np.unique() could really clean this line up.

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 19, 2018, 05:51

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1034

changed this line in version 6 of the diff

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 19, 2018, 05:51

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 19, 2018, 06:22

@vreeken I got a model with a delay element to work. Its rudimentary, and has issues with defining the initial states. Probably need to rework the logic on this.

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 19, 2018, 17:32

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1057

Right. This needs to use the direct output of OptimizationProblem.constant_inputs() instead of the pre-interpolated dictionary. Clearly, we need a unit test here.

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 19, 2018, 17:33

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1037

That is much nicer indeed!

By convention (and code in case of CSVMixin) the last item in the history time series is the t0 value, hence the [:-1].

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 20, 2018, 14:26

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1037

ok, good to know. I will put in an assertion just to avoid confusing errors, in case the convention is not followed.

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 20, 2018, 14:36

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1057

Maybe we could just store the interpolated constant_input values as interpolated_constant_inputs instead of overwriting the constant_inputs variable.

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 20, 2018, 14:41

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1057

or the give the direct output of constant_inputs() the name raw_constant_inputs. I think this less confusing than changing the meaning of the variable halfway though the method.

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 21, 2018, 19:47

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1057

changed this line in version 7 of the diff

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 21, 2018, 19:47

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1037

changed this line in version 7 of the diff

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 21, 2018, 19:47

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 21, 2018, 19:49

resolved all discussions

SGeeversAtVortech commented 6 years ago

In GitLab by @vreeken on May 21, 2018, 20:02

Commented on src/rtctools/optimization/modelica_mixin.py line 185

Does this also work with inputs (and not just parameters)? We need that to work for the homotopy/convexity fix.

SGeeversAtVortech commented 6 years ago

In GitLab by @vreeken on May 21, 2018, 20:12

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1033

I don't think we use this type of comment formatting anywhere else, so I'd prefer the original comment.

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 21, 2018, 20:13

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1033

changed this line in version 8 of the diff

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 21, 2018, 20:13

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 21, 2018, 20:19

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1085

Instead of time, @baayen had a value of 0.0 here. I imagine this was on accident, otherwise there would be no need for enumerate().

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 21, 2018, 20:29

Commented on src/rtctools/optimization/modelica_mixin.py line 185

That is next.

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 21, 2018, 23:24

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1085

Good catch!

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 23, 2018, 04:59

Commented on src/rtctools/optimization/modelica_mixin.py line 185

changed this line in version 9 of the diff

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 23, 2018, 04:59

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 24, 2018, 06:49

added 2 commits

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 24, 2018, 07:16

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 24, 2018, 08:04

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1059

Using numpy here rather than casadi is probably more efficient. All historical values are numerical.

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 24, 2018, 08:06

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1130

Do we need the above call?

Either delay depends on symbol_list, in which we case we abort with an assertion failure.

Or it does not, but then we don't need the substitution.

SGeeversAtVortech commented 6 years ago

In GitLab by @baayen on May 24, 2018, 08:08

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1141

in_times -> collocation_times

(Later on, we do collocation_times - delay, so the array lengths should match up)

SGeeversAtVortech commented 6 years ago

In GitLab by @vreeken on May 24, 2018, 12:11

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1130

I haven't checked myself in this particular case, but according to Jesse we do have to do a substitution (either here or in Pymoca) for cached models. CasADi thinks there's a dependency on states etc., because the delay_function was defined that way and called that way (with MX symbols, so lazy evalulation). depends_on is generally quite an accurate check, but anything else (sparsity, is_zero, ...) cannot be expected to give the right answer, including apparently numerical function calls with not all arguments specified.

I think the solution/workaround is to either pass NaNs in when you want to get a numeric value, or use .expand() (before .map()) on the function 'delay_values' below for (more accurate, but possibly still wrong) numeric values/sparsity/is_zero stuff. Fun stuff.

I do feel (as I told Jesse) that these checks/substitutions would belong better in Pymoca, but they will be quite similar (almost copy-paste).

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 24, 2018, 15:37

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1130

I agree with moving them to pymoca. I will move it over- just wanted to get it working last night. When done in pymoca, the delay will behave the same with cached and unchached models, even if the internal structure is different.

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 24, 2018, 15:38

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1141

good point.

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 25, 2018, 05:04

Not sure why gitlab is not showing my latest commit on this MR...

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 25, 2018, 05:06

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1130

Fix is now here: https://github.com/pymoca/pymoca/pull/118/commits/2fc8607d9b0c7466ceef9c4a7156da721d374ca7

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 25, 2018, 05:37

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1130

changed this line in version 13 of the diff

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 25, 2018, 05:37

Commented on src/rtctools/optimization/collocated_integrated_optimization_problem.py line 1141

changed this line in version 13 of the diff

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 25, 2018, 05:37

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 25, 2018, 18:29

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 25, 2018, 19:24

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 25, 2018, 19:26

added 2 commits

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @jvande42b on May 25, 2018, 19:26

unmarked as a Work In Progress

SGeeversAtVortech commented 6 years ago

In GitLab by @vreeken on May 25, 2018, 22:51

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @vreeken on May 26, 2018, 01:23

added 1 commit

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @vreeken on May 26, 2018, 01:34

added 2 commits

Compare with previous version

SGeeversAtVortech commented 6 years ago

In GitLab by @vreeken on May 26, 2018, 01:41

merged