pyoptsparse icon indicating copy to clipboard operation
pyoptsparse copied to clipboard

`isMajor` not returned for non-major iterations using getValues

Open joanibal opened this issue 3 years ago • 1 comments

Description

The code incorrectly assumes that isMajor is only defined at major iterations. The code makes the check for the isMajor flag as part of the check here

Possibly related to issue #250

Steps to reproduce issue

  1. create a history file using SNOPT
  2. optHist = History(hist_file) histValues = optHist.getValues('isMajor',major=False)

Current behavior

raises the warning

"The major flag has been set to True, since some names specified only exist on major iterations."

and returns the values of isMajor at only major iterations

Expected behavior

returns the value lf isMajor at all iterations

Code versions

List versions only if relevant

  • pyoptsparse: 2.6.2

joanibal avatar Jul 19 '21 20:07 joanibal

It does look that the two issues are essentially the same, and I think what @nwu63 recommended (showing all the shared values, and add the major-only where applies) still makes sense. With some luck we should be able to fix this directly within getValues().

I append an example to show the difference between major and minor history entries:

Major --> 74 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor', 'nMajor', 'nMinor', 'step', 'merit', 'feasibility', 'optimality', 'penalty'])
Minor --> 76 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor'])
Gradient evaluation --> 77 dict_keys(['xuser', 'funcsSens', 'fail', 'iter', 'isMajor'])  (all calls to func or funcSens increase the counter, then the iteration number is "corrected" at a later stage, we discussed a bit of this in #252 and related #182 )

How a bit of history might look like:

78 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor'])
79 dict_keys(['xuser', 'funcsSens', 'fail', 'iter', 'isMajor'])
80 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor'])
81 dict_keys(['xuser', 'funcsSens', 'fail', 'iter', 'isMajor'])
83 dict_keys(['xuser', 'funcsSens', 'fail', 'iter', 'isMajor'])
82 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor', 'nMajor', 'nMinor', 'step', 'merit', 'feasibility', 'optimality', 'penalty'])
84 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor'])
85 dict_keys(['xuser', 'funcsSens', 'fail', 'iter', 'isMajor'])
86 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor'])
87 dict_keys(['xuser', 'funcsSens', 'fail', 'iter', 'isMajor'])
88 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor'])
89 dict_keys(['xuser', 'funcsSens', 'fail', 'iter', 'isMajor'])
91 dict_keys(['xuser', 'funcsSens', 'fail', 'iter', 'isMajor'])
90 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor', 'nMajor', 'nMinor', 'step', 'merit', 'feasibility', 'optimality', 'penalty'])
93 dict_keys(['xuser', 'funcsSens', 'fail', 'iter', 'isMajor'])
92 dict_keys(['xuser', 'funcs', 'fail', 'iter', 'isMajor', 'nMajor', 'nMinor', 'step', 'merit', 'feasibility', 'optimality', 'penalty'])

marcomangano avatar Jul 19 '21 21:07 marcomangano