Setting Options in Jupyter Notebook#
When working in a Jupyter notebook, you can quickly see and set options on the driver and systems in your model.
Here we demonstrate the ability to interactively set the driver options for the Sellar MDA model from the Basic User Guide.
import openmdao.api as om
from openmdao.test_suite.components.sellar_feature import SellarMDA
import numpy as np
# define Sellar MDA problem
prob = om.Problem(model=SellarMDA())
model = prob.model
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)
# set driver and show driver options
prob.driver = om.ScipyOptimizeDriver()
prob.driver.options
[1790952347.358947] [runnervm8df0l:10144:0] ib_iface.c:1269 UCX ERROR mana_0: iface 0x561aa11887b0 failed to create UD QP TX wr:256 sge:6 inl:64 resp:0 RX wr:4096 sge:1 resp:0 failed: Operation not supported
[1790952347.359211] [runnervm8df0l:10144:0] ucp_worker.c:1412 UCX ERROR uct_iface_open(ud_verbs/mana_0:1) failed: Input/output error
[runnervm8df0l:10144] pml_ucx.c:313 Error: Failed to create UCP worker
Try changing some of the options above and then seeing how the options have changed by running the cell below:
from pprint import pprint
pprint(list(prob.driver.options.items()))
[('debug_print', []),
('invalid_desvar_behavior', 'warn'),
('optimizer', 'SLSQP'),
('tol', 1e-06),
('maxiter', 200),
('disp', True),
('singular_jac_behavior', 'warn'),
('singular_jac_tol', 1e-16)]
Similarly, we can set recording options:
prob.driver.recording_options
pprint(list(prob.driver.recording_options.items()))
[('record_desvars', True),
('record_responses', False),
('record_objectives', True),
('record_constraints', True),
('includes', []),
('excludes', []),
('record_derivatives', False),
('record_inputs', True),
('record_outputs', True),
('record_residuals', False)]
# run the optimization
prob.setup()
prob.run_driver()
=====
cycle
=====
NL: NLBGS Converged in 8 iterations
=====
cycle
=====
NL: NLBGS Converged in 1 iterations
=====
cycle
=====
NL: NLBGS Converged in 9 iterations
=====
cycle
=====
NL: NLBGS Converged in 9 iterations
=====
cycle
=====
NL: NLBGS Converged in 10 iterations
=====
cycle
=====
NL: NLBGS Converged in 9 iterations
=====
cycle
=====
NL: NLBGS Converged in 8 iterations
=====
cycle
=====
NL: NLBGS Converged in 7 iterations
=====
cycle
=====
NL: NLBGS Converged in 7 iterations
=====
cycle
=====
NL: NLBGS Converged in 6 iterations
=====
cycle
=====
NL: NLBGS Converged in 5 iterations
Optimization terminated successfully (Exit mode 0)
Current function value: 3.183394111653364
Iterations: 9
Function evaluations: 10
Gradient evaluations: 9
Optimization Complete
-----------------------------------
Problem: problem
Driver: ScipyOptimizeDriver
success : True
iterations : 11
runtime : 1.4491E-01 s
model_evals : 11
model_time : 2.2829E-02 s
deriv_evals : 9
deriv_time : 9.1155E-02 s
exit_status : SUCCESS
Note that options that are not editable, such as the guess_func function reference for a BalanceComp, will be shown but disabled:
def guess_function(inputs, outputs, residuals):
outputs['x'] = np.sqrt(inputs['rhs:x'])
bal = om.BalanceComp('x', guess_func=guess_function)
bal.options