Repository navigation
Update multistart solver, add method for multistart NLP initialization - #3994
stephenscini wants to merge 85 commits into
Conversation
|
Opening PR, but still in active development. Dependent on #3991 first as it includes those changes. |
|
Note for 7/21 Dev meeting Method implemented with support for new solver interface. All original tests passing locally. Tasks before ready for review:
|
|
Note from 08/25 dev meeting: Not necessarily a bad design choice but technically precedent in Pyomo is to allow users to change the solver during solve after initialization. Worth future discussion. |
Followed precedent and added back config option. Also adjusted so availability checks subsolver, and is rechecked during solve in case of change. |
|
@michaelbynum @blnicho |
|
@stephenscini could you resolve the conflicts and merge main into this PR when you have a minute? |
|
@sscini , @stephenscini - Similar comment as to your other PR! We are trying to cut a release this week; are you able to address the issues this week? |
@mrmundt @blnicho Merged in main and addressed comments. Failing test failed at windows update. Should be ready for review. Thanks! |
| with self.assertRaises(ValueError): | ||
| SolverFactory('multistart').solve(m, strategy="rand_vector") |
There was a problem hiding this comment.
Could you add a short comment explaining why we expect a ValueError in this case?
| # Provided with config | ||
| with self.assertRaises(TypeError): | ||
| solver = SolverFactory('multistart') | ||
| solver.config.subsolver = bad_solver | ||
| solver.solve(m) | ||
| # Provided during solve | ||
| with self.assertRaises(TypeError): | ||
| solver = SolverFactory('multistart') | ||
| solver.config.subsolver = bad_solver | ||
| solver.solve(m) |
There was a problem hiding this comment.
These two cases are identical. Copy/paste error?
There was a problem hiding this comment.
Yes, each should only do it one way. They both set it twice. I will fix. Thank you
| seed = 145 | ||
| # For the simple model, check all sampling methods converge | ||
| simple_model = build_model() | ||
| for method, strategy in product(sampling_methods, strategies): |
There was a problem hiding this comment.
We typically don't want to embed a for-loop in a test to check distinct test cases. Consider using parameterized or a unittest subTest instead.
There was a problem hiding this comment.
Will switch to parameterized. Thank you
…l formatting issues
…est for requiring uniform for hcs
|
@blnicho @michaelbynum Hello! I addressed the reviewer comments but also noticed some things I missed or should have addressed sooner. If this PR needs to be done after the release I do not think it is incredibly high priority from my perspective. Thank you and best of luck with the release! |
| parameterized, param_available = attempt_import('parameterized') | ||
| parameterized = parameterized.parameterized |
There was a problem hiding this comment.
What is the intent here? This is a hard dependency on parameterized (which is OK in tests). There is no reason to use attempt_import, right?
| if rng is not None: | ||
| self.rng = rng | ||
| else: | ||
| self.rng = np.random.default_rng(seed) |
There was a problem hiding this comment.
This seems to be the only use of numpy. Is it really necessary? Why not make the default random source just use python's random.random?
| - "rand": random choice between variable bounds | ||
| - "midpoint_guess_and_bound": midpoint between current value and farthest bound | ||
| - "rand_guess_and_bound": random choice between current value and farthest bound | ||
| - "rand_distributed": random choice among evenly distributed values | ||
| - "midpoint": exact midpoint between the bounds. If using this option, multiple iterations are useless. |
There was a problem hiding this comment.
Should these keys be members of an Enum (then this documentation can be in the Enum documentation - which should help to keep it up to date as additional strategies are added)?
| ConfigValue( | ||
| default=None, | ||
| description="Solver to use. If None, defaults to ipopt. " | ||
| "Accepts solver names as strings or solver objects.", | ||
| ), |
There was a problem hiding this comment.
Shouldn't this use a custom domain= that takes either a string or an actual Solver object? Then default can be 'ipopt' (which simplifies the description and the code later on)?
| default=0.5, | ||
| description="Maximum allowable estimated missing mass of optima.", | ||
| doc="""Maximum allowable estimated missing mass of optima for the | ||
| high confidence stopping rule, only used with the random strategy. |
There was a problem hiding this comment.
Several of these options are only applicable to a single strategy. Should they be moved to a strategy_options (like the subsolver options) instead of putting it at the top level (where they may confuse things)?
| self.sampling_method = self.declare( | ||
| "sampling_method", | ||
| ConfigValue( | ||
| default="random_uniform", |
There was a problem hiding this comment.
Should this have a domain; should that domain be an Enum?
| solver = self._resolve_subsolver(self.config.subsolver) | ||
| except TypeError: | ||
| return False | ||
| return solver.available() |
There was a problem hiding this comment.
Is this correct? I would think that available should always be True. The subsolver availability should be obtainable through self.config.subsolver.available(), right?
| current = (0, 2, 0) | ||
| return current |
There was a problem hiding this comment.
Why assign to a local variable?
|
|
||
| if self.remaining_time_limit is not None: | ||
| self._timing_lim = True | ||
| if self.remaining_time_limit == 0: |
Fixes # .
Summary/Motivation:
Additional method in devel/initialization to use multistart optimization as a way for initializing nonlinear models.
Changes proposed in this PR:
AI-Use Disclosure
AI tools contributed to the development of this PR
Review process (select ONE):
Notes for reviewers (optional):
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: