Run a Driver

Contents

Run a Driver#

Once setup() is done, you can then run the optimization with run_driver().

run_driver() executes the driver, running the optimization, DOE, etc. that you’ve set up.

Examples#

Set up a simple optimization problem and run it, by calling run_driver.

import numpy as np
import openmdao.api as om
from openmdao.test_suite.components.sellar_feature import SellarDerivatives

prob = om.Problem(model=SellarDerivatives())

model = prob.model
model.nonlinear_solver = om.NonlinearBlockGS()
model.linear_solver = om.ScipyKrylov()

prob.driver = om.ScipyOptimizeDriver()
prob.driver.options['optimizer'] = 'SLSQP'
prob.driver.options['tol'] = 1e-9

model.add_design_var('z', lower=np.array([-10.0, 0.0]), upper=np.array([10.0, 10.0]))
model.add_design_var('x', lower=0.0, upper=10.0)
model.add_objective('obj')
model.add_constraint('con1', upper=0.0)
model.add_constraint('con2', upper=0.0)

prob.setup()
prob.run_driver()

print(prob.get_val('x'))
NL: NLBGS Converged in 8 iterations
NL: NLBGS Converged in 1 iterations
NL: NLBGS Converged in 9 iterations
NL: NLBGS Converged in 10 iterations
NL: NLBGS Converged in 10 iterations
NL: NLBGS Converged in 9 iterations
NL: NLBGS Converged in 6 iterations
Optimization terminated successfully    (Exit mode 0)
            Current function value: 3.183393951728078
            Iterations: 6
            Function evaluations: 6
            Gradient evaluations: 6
Optimization Complete
-----------------------------------
[3.56410563e-15]
print(prob.get_val('y1'))
[3.16]
print(prob.get_val('y2'))
[3.75527777]
print(prob.get_val('z'))
[1.97763888 0.        ]
print(prob.get_val('obj'))
[3.18339395]