Skip to content

Update multistart solver, add method for multistart NLP initialization - #3994

Open
stephenscini wants to merge 85 commits into
Pyomo:mainfrom
stephenscini:multistart-init
Open

stephenscini wants to merge 85 commits into
Pyomo:mainfrom
stephenscini:multistart-init

Conversation

@stephenscini

@stephenscini stephenscini commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes # .

Summary/Motivation:

Additional method in devel/initialization to use multistart optimization as a way for initializing nonlinear models.

Changes proposed in this PR:

  • Updating contrib/multistart solver for reproducibility, and adding support for new solver interface.
  • Adding support for uniform, lhs, and sobol sampling within the multistart solver
  • Adding method to devel/initialization

AI-Use Disclosure

  • AI tools contributed to the development of this PR

    • AI tools generated code (apart from tests)

    Review process (select ONE):

    • Rewritten: All AI-generated content was rewritten by me before being committed.

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:

  1. I agree my contributions are submitted under the BSD license.
  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.

@stephenscini

Copy link
Copy Markdown
Contributor Author

Opening PR, but still in active development. Dependent on #3991 first as it includes those changes.

@stephenscini stephenscini changed the title Adding method for multistart initialization of nonlinear models. [Depends on #3991] Adding method for multistart initialization of nonlinear models. Jul 21, 2026
@stephenscini

stephenscini commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Note for 7/21 Dev meeting

Method implemented with support for new solver interface. All original tests passing locally.

Tasks before ready for review:

  • It looks like there is an issue with changing the SolverFactory version in a different place, which I will address.
  • Try and simplify interface, check with mentors.
  • Add tests for new functionality

@stephenscini

Copy link
Copy Markdown
Contributor Author

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.

@stephenscini

Copy link
Copy Markdown
Contributor Author

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.

@stephenscini

Copy link
Copy Markdown
Contributor Author

@michaelbynum @blnicho
Can the osx/3.14 be rerun please? Not sure why it failed. Thanks!

@blnicho

blnicho commented Nov 15, 2026

Copy link
Copy Markdown
Member

@stephenscini could you resolve the conflicts and merge main into this PR when you have a minute?

@mrmundt

mrmundt commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@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?

@sscini

sscini commented Nov 17, 2026

Copy link
Copy Markdown
Member

@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!

@blnicho blnicho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sscini here are a few initial comments. I'm still reviewing the rest of the files.

Comment on lines +102 to +103
with self.assertRaises(ValueError):
SolverFactory('multistart').solve(m, strategy="rand_vector")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a short comment explaining why we expect a ValueError in this case?

Comment on lines +182 to +191
# 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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These two cases are identical. Copy/paste error?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will switch to parameterized. Thank you

@sscini

sscini commented Nov 18, 2026

Copy link
Copy Markdown
Member

@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!

Comment on lines +36 to +37
parameterized, param_available = attempt_import('parameterized')
parameterized = parameterized.parameterized

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Comment on lines +72 to +76
- "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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)?

Comment on lines +82 to +86
ConfigValue(
default=None,
description="Solver to use. If None, defaults to ipopt. "
"Accepts solver names as strings or solver objects.",
),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this correct? I would think that available should always be True. The subsolver availability should be obtainable through self.config.subsolver.available(), right?

Comment on lines +277 to +278
current = (0, 2, 0)
return current

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why assign to a local variable?


if self.remaining_time_limit is not None:
self._timing_lim = True
if self.remaining_time_limit == 0:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

== 0 or <= 0?

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.

5 participants