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

Fixes issue for saving model files with missing keys #1151

Merged
merged 12 commits into from
Nov 10, 2023

Conversation

avdudchenko
Copy link
Contributor

Fixes/Resolves:

This will catch when a result is returned with missing or inactive variables. This can occur when a solve fails or the initialization process fails without re-activating the variable first. Or where some variables will be deactivated by user based on solved condition.

(replace this with the issue # fixed or resolved, if no issue exists then a brief statement of what this PR does)

Summary/Motivation:

When working with NN's I build the NNs on model tree, but deactivate them. they only end up being reactivated if solve is successful, so if it fails, we will return a result with missing keys. This update will attempt to catch missing keys and rebuild them.

Might not be the best implementation.

needs tests

Changes proposed in this PR:

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the license terms described in the LICENSE.txt file at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@avdudchenko avdudchenko changed the title Fises issue for saving model files with missing keys Fixes issue for saving model files with missing keys Sep 26, 2023
@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (4c2f3fa) 94.93% compared to head (1f0949e) 94.95%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1151      +/-   ##
==========================================
+ Coverage   94.93%   94.95%   +0.01%     
==========================================
  Files         343      343              
  Lines       34794    34809      +15     
==========================================
+ Hits        33033    33052      +19     
+ Misses       1761     1757       -4     
Files Coverage Δ
watertap/tools/parameter_sweep/model_manager.py 95.16% <ø> (+1.61%) ⬆️
watertap/tools/parameter_sweep/parameter_sweep.py 96.72% <100.00%> (+0.09%) ⬆️
...ools/analysis_tools/loop_tool/data_merging_tool.py 92.64% <66.66%> (-1.30%) ⬇️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@k1nshuk
Copy link
Contributor

k1nshuk commented Sep 26, 2023

The changes look good to me so far. I can approve it once its out of draft.

@adam-a-a
Copy link
Contributor

Based on the codecov check, it looks like you just need to add some testing.

@ksbeattie ksbeattie added the Priority:Normal Normal Priority Issue or PR label Sep 28, 2023
@avdudchenko avdudchenko marked this pull request as ready for review October 18, 2023 17:38
@avdudchenko
Copy link
Contributor Author

Looks like the tests now pass and are MPI safe. The test do need min 2 parallel workers to properly test the catches. Fails MacOS test as the objective results are not quiet right (1e-3 precision by looks of it...)

Should be good to go/merge. This also includes some additional fixes that were caught during testing/development.

Copy link
Contributor

@k1nshuk k1nshuk left a comment

Choose a reason for hiding this comment

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

Looks good to me so far. I am not sure about how to deal with the MacOS test, however.

def test_parameter_sweep_optimize_with_added_var(self, model, tmp_path):
# this will run a solve function that adds a variable but only in some
# of the solves.
"""THIS TEST IS DESIGNED FOR 2 Parallel workers!!!!!!"""
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be needed to make this test work with an arbitrary number of workers? This could be dealt with in a subsequent PR.

Copy link
Contributor Author

@avdudchenko avdudchenko Oct 19, 2023

Choose a reason for hiding this comment

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

Its a minum number - if you have 1 worker then we don't test for missing keys. I think we should really just change how we store results from each solve (e.g instead of storing all results in arrays inside a result dictionory, we just store the value for each parameter in a dict and store an array of dicts--not sure how MPI safe that is but that would solve this issue. - this would be same as async multiprocessing or ray implementation, where we split parmans into size of 1...

Co-authored-by: Kinshuk Panda <kinshukpanda@gmail.com>
@ksbeattie
Copy link
Contributor

ksbeattie commented Nov 9, 2023

@avdudchenko still for Dec?

@avdudchenko
Copy link
Contributor Author

@avdudchenko still for Dec?

Would be nice, just needs one more review (@bknueven plz) and otherwise its good to go?

@ksbeattie
Copy link
Contributor

@avdudchenko still for Dec?

Would be nice, just needs one more review (@bknueven plz) and otherwise its good to go?

There's still a failing test :(

@bknueven bknueven enabled auto-merge (squash) November 10, 2023 16:25
@bknueven bknueven merged commit 176cd9e into watertap-org:main Nov 10, 2023
24 checks passed
lbianchi-lbl pushed a commit to watertap-org/parameter-sweep that referenced this pull request May 1, 2024
…tertap#1151)

* Fixes issue when key dont exist

* Fixes issue with empty h5 files

* added test for missing key fix and couple other small fixes.

* Fjxes to mpit testing

* Update watertap/tools/parameter_sweep/tests/test_parameter_sweep.py

Co-authored-by: Kinshuk Panda <kinshukpanda@gmail.com>

* mac fix

* Update test_parameter_sweep.py

---------

Co-authored-by: Kinshuk Panda <kinshukpanda@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants