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

Save more variables by default in SNOPT history file #347

Merged
merged 6 commits into from
May 29, 2023

Conversation

ewu63
Copy link
Collaborator

@ewu63 ewu63 commented May 19, 2023

Purpose

I updated the snSTOP function to save more variables by default in the Python layer. The option Save major iteration variables now defaults to an empty list. The following variables are saved (the user cannot turn these off)

  • isMajor
  • nMajor
  • nMinor
  • step
  • feasibility
  • optimality
  • merit
  • condZHZ
  • penalty

and the following can be added via the option

  • Hessian
  • slack
  • lambda
  • condZHZ
  • nS
  • BSwap
  • maxVi
  • penalty_vector

Happy to discuss names/which ones should be saved by default. I think it's possible to have everything in the major iteration log saved, but the defaults I feel are the ones people actually care about (at least given my limited knowledge of SNOPT).

Expected time until merged

A few days. Maybe we can do a minor release after this and #346 are both merged?

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (non-backwards-compatible fix or feature)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Documentation update
  • Maintenance update
  • Other (please describe)

I don't believe this is a backwards-breaking change, but happy to discuss. Also please run tests since the CI will not check SNOPT-related stuff.

Testing

I updated the existing tests. As usual, the CI will not test SNOPT so please test this locally.

Checklist

  • I have run flake8 and black to make sure the Python code adheres to PEP-8 and is consistently formatted
  • I have formatted the Fortran code with fprettify or C/C++ code with clang-format as applicable
  • I have run unit and regression tests which pass locally with my changes
  • I have added new tests that prove my fix is effective or that my feature works
  • I have added necessary documentation

@ewu63 ewu63 requested a review from a team as a code owner May 19, 2023 22:33
@ewu63 ewu63 requested review from lamkina and sseraj May 19, 2023 22:33
@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #347 (adfb0b6) into main (b029888) will decrease coverage by 11.41%.
The diff coverage is 18.18%.

@@             Coverage Diff             @@
##             main     #347       +/-   ##
===========================================
- Coverage   84.02%   72.61%   -11.41%     
===========================================
  Files          22       22               
  Lines        3349     3345        -4     
===========================================
- Hits         2814     2429      -385     
- Misses        535      916      +381     
Impacted Files Coverage Δ
pyoptsparse/pySNOPT/pySNOPT.py 16.81% <18.18%> (-73.28%) ⬇️

... and 8 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

tests/test_other.py Show resolved Hide resolved
elif saveVar == "maxVi":
iterDict[saveVar] = maxvi
else:
warnings.warn(f"Received unknown SNOPT save variable {saveVar}")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think an error would be better here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought about it, and decided on warning since I don't want to kill a whole optimization just because someone made a typo or had a duplicate variable. Can change if preferred.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on this @lamkina?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather this be an error with a more descriptive message. If you are expecting to have variables to postprocess afer an optimization, you don't want to have to re-run the entire optimization (especially for high-fidelity cases) just to get that information. Especially because most users initially won't understand this warning and might just ignore the warning.

An error with a message like Received unkown SNOPT save variable {saveVar}. Please see "Save major iteration variables" option in the pyOptSparse documentation under "SNOPT".

pyoptsparse/pySNOPT/pySNOPT.py Outdated Show resolved Hide resolved
doc/optimizers/SNOPT_options.yaml Outdated Show resolved Hide resolved
list,
["step", "merit", "feasibility", "optimality", "penalty"],
],
"Save major iteration variables": [list, []],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to add to the default list than have variables that cannot be turned off. This would make the code easier to understand, and it would be consistent with how we handle saving variables in ADflow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I also debated about this. I think the reason I preferred this is because, if I want to add another one then I have to copy/paste the list of defaults first from somewhere (probably docs) which is a little annoying. Also, given the small storage requirement I don't think it's necessary to allow users to remove the default ones. Happy to change things though.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think @lamkina?

Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree with @nwu63 in this case. The storage requirement for the default variables is pretty insignificant and from an OptView perspective it's nice to have an expected minimal set of data for every SNOPT case.

From the user perspective, I'm always against extra steps to get simple cases working. If the proposed alternative means users need to read the docs to understand the default usage of recoring, I think that is too complicated for the intended impact of these changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, that fine with me. I would like the defaults to be documented though because the empty list suggests nothing is saved by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good compromise imo.

@ewu63 ewu63 requested a review from marcomangano May 22, 2023 17:40
@ewu63
Copy link
Collaborator Author

ewu63 commented May 25, 2023

Bumping this PR @sseraj @lamkina

Copy link
Contributor

@lamkina lamkina left a comment

Choose a reason for hiding this comment

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

See my comment about changing the warning to an error. Once that's resolved I think the rest of this is looking good to go.

Copy link
Contributor

@marcomangano marcomangano left a comment

Choose a reason for hiding this comment

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

Sorry for my late review, I agree with the comments above. It's not really a new feature and there are no big changes in behavior so I don't think a new release is necessary just for this PR, but we might think about a version bump soon.

@marcomangano marcomangano merged commit c7b3784 into mdolab:main May 29, 2023
11 of 13 checks passed
@ewu63 ewu63 deleted the feature/improve-snstop branch May 30, 2023 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants