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

Fixed a bug that caused bounds to not be respected by Nelder-Mead optimizer through ScipyOptimizeDriver. #3098

Merged
merged 1 commit into from Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion openmdao/drivers/scipy_optimizer.py
Expand Up @@ -25,7 +25,7 @@
'trust-ncg', 'trust-constr', 'basinhopping', 'shgo'}
_hessian_optimizers = {'trust-constr', 'trust-ncg'}
_bounds_optimizers = {'L-BFGS-B', 'TNC', 'SLSQP', 'trust-constr', 'dual_annealing', 'shgo',
'differential_evolution', 'basinhopping'}
'differential_evolution', 'basinhopping', 'Nelder-Mead'}
if Version(scipy_version) >= Version("1.11"):
# COBYLA supports bounds starting with SciPy Version 1.11
_bounds_optimizers |= {'COBYLA'}
Expand Down
36 changes: 36 additions & 0 deletions openmdao/drivers/tests/test_scipy_optimizer.py
Expand Up @@ -2224,6 +2224,42 @@ def test_con_and_obj_duplicate(self):
assert_near_equal(p.get_val('exec.z')[0], 25)
assert_near_equal(p.get_val('exec.z')[50], -75)

def test_nelder_mead_bounded(self):

class dummy_function(om.ExplicitComponent):
def setup(self):
self.add_input('x', val=0.)
self.add_output('y', val=0.)

def compute(self, inputs, outputs):
x = inputs['x']

outputs['y'] = 2*x + 1

model = om.Group()
model.add_subsystem('dummy_function',
dummy_function(),
promotes=['*'])
prob = om.Problem(model=model)

model.add_objective('y')
model.add_design_var('x', lower=0, upper=100)
model.set_input_defaults('x', 25)

driver = prob.driver = om.ScipyOptimizeDriver()
driver.options["optimizer"] = 'Nelder-Mead'

driver.options['debug_print'] = ['desvars',
'nl_cons', 'ln_cons', 'objs', 'totals']

prob.setup()

prob.run_driver()

y_out = prob.get_val('y')

assert_near_equal(y_out, 1.0, tolerance=1.0E-3)


if __name__ == "__main__":
unittest.main()