optimizationbayesianopenmdao

Bayesian optimization in OpenMDAO?


I have a model built in OpenMDAO that I am interested in trying with Bayesian optimization. I have found some work in this area for older versions of OpenMDAO, but nothing for the current OpenMDAO version 3.34.

There is a driver built here for OpenMDAO version 1.7.1: https://github.com/metamorph-inc/bayesopt_openmdao.

I can, of course, use one of the existing Bayesian optimization package with my model as a black box, but I would prefer to use a more direct approach through OpenMDAO. I'm wondering if anyone has any suggestions for how to best approach Bayesian optimization with an OpenMDAO model.


Solution

  • With the command openmdao find_repos you get a list of openmdao-related repositories from Github. As far as I know, there are only two repositories related to bayesian optimization drivers:

    With the second one, you can use a bayesian optimizer from the egobox library (Disclaimer: I am the author of the package).

    pip install egobox openmdao_extensions

    Then you can run the Sellar example using BO like this:

    import openmdao.api as om
    from openmdao.test_suite.components.sellar_feature import SellarMDA
    from openmdao_extensions.egobox_egor_driver import EgoboxEgorDriver
    
    import egobox as egx
    
    # To display Egor optimizer traces
    # import logging
    # logging.basicConfig(level=logging.INFO)
    
    prob = om.Problem()
    prob.model = SellarMDA()
    
    prob.model.add_design_var("x", lower=0, upper=10)
    prob.model.add_design_var("z", lower=0, upper=10)
    prob.model.add_objective("obj")
    prob.model.add_constraint("con1", upper=0)
    prob.model.add_constraint("con2", upper=0)
    
    prob.driver = EgoboxEgorDriver()
    
    # To display available options
    # help(egx.Egor)
    prob.driver.opt_settings["maxiter"] = 20
    prob.driver.opt_settings["infill_strategy"] = egx.InfillStrategy.WB2
    prob.driver.opt_settings["infill_optimizer"] = egx.InfillOptimizer.SLSQP
    
    prob.setup()
    prob.set_solver_print(level=0)
    
    prob.run_driver()
    
    print("minimum found at")
    print(prob.get_val("x")[0])
    print(prob.get_val("z"))
    
    print("minimum objective")
    print(prob.get_val("obj")[0])