Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix: Scale Microgrid Error #30

Merged
merged 5 commits into from
Dec 11, 2024
Merged

BugFix: Scale Microgrid Error #30

merged 5 commits into from
Dec 11, 2024

Conversation

reid-g
Copy link
Collaborator

@reid-g reid-g commented Dec 2, 2024

This pull request fixes issue #16 .

Changed the error estimation to norm based instead of element wise. All test cases pass now. Solution vectors from the same system solved as a DAE are provided (from MATLAB).

Numerical differences in elements of the vector seems to be bottoming out any improvements on error. Step size drops to be quite small initially as well (h_0 < reltol). However, as discussed this does not seem to be an issue.

@reid-g reid-g added the bug Something isn't working label Dec 2, 2024
@reid-g reid-g self-assigned this Dec 2, 2024
@reid-g reid-g requested a review from pelesh December 2, 2024 18:44
@pelesh pelesh requested a review from nkoukpaizan December 9, 2024 18:44
Copy link
Collaborator

@nkoukpaizan nkoukpaizan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little worried that moving to the two norm is not fixing the underlying issue and may give a false-negative. If we expect the vectors to be close element-wise, then that should be the right thing to check for the test.

Examples/ScaleMicrogrid/ScaleMicrogrid.cpp Outdated Show resolved Hide resolved
Examples/ScaleMicrogrid/ScaleMicrogrid.cpp Show resolved Hide resolved
Copy link
Collaborator

@pelesh pelesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tolerances in the example need to be better documented. Use Doxygen @todo keyword to document issues we have not clarified yet.

Comment on lines 35 to 36
real_type error_tol = 8e-5;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There has to be comment justifying this tolerance. How was it estimated?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, all tolerances should be defined in SolutionKeys.hpp file because they depend on how these values in the solution key are generated. I would implement it like:

Suggested change
real_type error_tol = 8e-5;
real_type error_tol = MICROGRID_TOL;

and define MICROGRID_TOL in the SolutionKeys.hpp file. There should be an explanation why you picked 8e-5 and not 7e-5, for example. The explanation should be commented in the code using Doxygen format.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was roughly the best error obtained.
The N=8 case hovers around 1e-5 to 3e-5 when reltol=1e-7; abstol=1e-7. This the point where the error on the N=8 system "bottoms out". Higher and lower tolerances increase error. error_tol was chosen based of this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think how you came up to the tolerance used for testing needs to be documented in the code. The argument for selecting that specific tolerance is unconvincing. Eventually we will want to improve this test and it would be good to have documented what has been done to this point.

Also, I would put numerical value for the tolerance and the comments in the SolutionKeys.hpp file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added documentation on why it was chosen. Results are commented in showing why as well.

Examples/ScaleMicrogrid/ScaleMicrogrid.cpp Outdated Show resolved Hide resolved
Comment on lines +7 to +11
* Data generated with Matlab ode23tb solver with tolerances set to
* abstol = 1e-12 and reltol = 1e-12 for the ODE derivation.
*
* DAE keys are generated with Matlab IDA interface with tolerances set to
* abstol = 1e-10 and reltol = 1e-10 for the DAE derivation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one of the two is true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both give correct solutions. The DAE formulation has slightly better 2-norm error (due to different numerical algorithms). I left them in for comparison since the model has trivial constraints. Should one be removed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one set of data with reference results. Comments in the code should describe only the data that is included.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??? There are two set of keys. ODE keys are denoted answer_key_N* and DAE keys are denoted answer_key_N*_DAE. Both reference data sets are in the solution keys file.

Examples/ScaleMicrogrid/SolutionKeys.hpp Outdated Show resolved Hide resolved
@pelesh
Copy link
Collaborator

pelesh commented Dec 10, 2024

I am a little worried that moving to the two norm is not fixing the underlying issue and may give a false-negative. If we expect the vectors to be close element-wise, then that should be the right thing to check for the test.

SUNDIALS is using weighted 2-norm to compare with relative tolerance. Ideally, we should use the same. For this PR, it should be at least documented where these tolerances come from, why particular numbers are used and why we believe this is a reasonable verification of results.

@reid-g
Copy link
Collaborator Author

reid-g commented Dec 10, 2024

I am a little worried that moving to the two norm is not fixing the underlying issue and may give a false-negative. If we expect the vectors to be close element-wise, then that should be the right thing to check for the test.

SUNDIALS is using weighted 2-norm to compare with relative tolerance. Ideally, we should use the same. For this PR, it should be at least documented where these tolerances come from, why particular numbers are used and why we believe this is a reasonable verification of results.

The weighted 2-norm used is an estimate of temporal error. Since we have a reference solution to compare then the raw temporal accuracy measure I think should be used (standard 2norm relative error).

It was my mistake to originally have the element-wise relative error setup. The methods accuracy is bounded from analysis by the 2norm. Not the element-wise.

@pelesh pelesh force-pushed the scale-microgrid-fix branch from 78124d9 to 1c094d9 Compare December 11, 2024 18:17
@pelesh pelesh merged commit 5bef9ca into develop Dec 11, 2024
This was referenced Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants