-
Notifications
You must be signed in to change notification settings - Fork 58
Simplify the TimeIndependentMDCObjectiveFunction class #515
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
Merged
sserita
merged 18 commits into
develop
from
simplify-TimeIndependentMDCObjectiveFunction
Jan 20, 2025
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f0edb04
initial commit simplifying TimeIndependentMDCObjectiveFunction
rileyjmurray 768f248
bugfixes
rileyjmurray 609b7a9
improve readability
rileyjmurray a62de79
inline comment
rileyjmurray dd764cf
add pytest dispatcher for MPI test in test_packages
rileyjmurray 4590263
move simple MPI test from test/test_packages into test/unit, and rena…
rileyjmurray 00e4d16
implement changes discussed in 12/17 dev meeting
rileyjmurray 8b304c3
expand scope of exception handling
rileyjmurray 8f641da
add separate TimeIndpendentMDCObjectiveFunction.dlsvec back
rileyjmurray 1d32520
resolve an infuriating sign error. Will probably want to clean this up.
rileyjmurray 3f8029a
check in slightly simpler (but still complicated) implementation. Nex…
rileyjmurray 6efa45e
simplifications complete
rileyjmurray c33542e
adjust size of perturbation from zero in test_stdgst_prunedpath
rileyjmurray 157d999
split out duplicated complicated line into its own function; remove T…
rileyjmurray 588cd78
have perturbation from zero be closer to what it was before (only inc…
rileyjmurray ec105d6
fix LM bugs
rileyjmurray 5779011
simplify bugfix from last commit
rileyjmurray 59ab4d3
remove variable added for debugging
rileyjmurray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import subprocess | ||
| import pytest | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| try: | ||
| from mpi4py import MPI | ||
| except (ImportError, RuntimeError): | ||
rileyjmurray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| MPI = None | ||
|
|
||
|
|
||
| class MPITester: | ||
|
|
||
| @pytest.mark.skipif(MPI is None, reason="mpi4py could not be imported") | ||
| def test_all(self, capfd: pytest.LogCaptureFixture): | ||
| current_filepath = Path(os.path.abspath(__file__)) | ||
| to_run = current_filepath.parents[0] / Path('run_me_with_mpiexec.py') | ||
| subprocess_args = (f"mpiexec -np 4 python -W ignore {str(to_run)}").split(' ') | ||
|
|
||
| result = subprocess.run(subprocess_args, capture_output=False, text=True) | ||
| out, err = capfd.readouterr() | ||
| if len(out) + len(err) > 0: | ||
| msg = out + '\n'+ 80*'-' + err | ||
| raise RuntimeError(msg) | ||
| return | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhhh .... if I didn't make it, then the test failed nastily. The optimizer just didn't converge.
I can compare side by side and see what the threshold is for the old code vs new code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sserita, I'm very glad you asked this question. It turns out that the non-convergence I observed stemmed from a bug in the LM optimizer. Specifically, it stemmed from how the LM optimizer decided to update the "best_x."
The implementations on develop (i.e., both the default SimplerLMOptimizer and the backup CustomLMOptimizer) would only update
best_xifnorm_f < min_norm_fand a boolean flag callednew_x_is_known_in_boundswas True. Butnew_x_is_known_in_boundsis really more of a sufficient condition for being in bounds than a necessary condition. It makes more sense to do this:If I make that change then the test passes without making the change that prompted your comment.
See below for my investigation, written to a future pyGSTi developer who might come across this.
Investigation
Stefan's comment concerned a change I made in
test/test_packages/drivers/test_calcmethods1Q.py::test_stdgst_prunedpath. The change was to replace a scalar that was hard-coded to 1e-10 with a scalar hard-coded to 1e-9. Let's call that scalarperturb. So the old value isperturb=1e-10.I ran this test on develop with different values of
perturb; those runs passed whenperturb >= 5e-13and failed whenperturb <= 2.5e-13. Then I ran this test on the current branch using the commit at the time that Stefan left his comment. Those runs passed whenperturb >= 2e-10and failed whenperturb <= 1.125.I started to write a report of these observations when I noticed something funny. In the test log it was clear that the LM optimizer was terminating outer iterations with a much larger value for
norm_fthan the minimum value seen across the outer iterations (specific logs are shown below). This made me suspect thatbest_xwasn't being set properly. Sure enough, I found this issue where a sufficient condition for an iterate being in-bounds (new_x_is_known_in_bounds) was effectively used as a necessary condition. After updating the termination criteria I was able to get this problematic unit test to pass whenperturb==1e-10. In fact, it passed withperturb==1e-12. I didn't bother checking smaller values.develop, passing with 5e-13
develop, passing with 2e-10
This PR, passing with 2e-10
This PR, failing with 1e-10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work tracking this down, @rileyjmurray!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @coreyostrove! I feel pretty good about this one. Who knows how many past calls to LM suffered from this bug. It's wild to think about, since LM was already performing very well, and now it'll perform even better :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, nice work and as always, the detailed writeups are incredibly appreciated!