I am just getting started with the tutorials of OpenMDAO, I was trying out the Sellar - A Two-Discipline Problem with a Nonlinear Solver tutorial and soon ran into an error. There are three ways included in the website to promote and connect input-output variables, the third method titled "Variable Promotion and Connect Statements" has the class named SellarMDAPromoteConnect. When I try to run the optimization setup, the code throws a runtime error
<model> <class SellarMDAPromoteConnect>: Output not found for response 'obj'
I ran the following in the console:
!openmdao check -c all <_file name_>.py
which shows the first error:
File "D:\softwares\anaconda\anaconda3\lib\site-packages\openmdao\core\system.py", line 3250, in get_responses key = in_abs = prom2abs_in[name][0]
KeyError: 'obj'
Can anyone kindly explain why this error pops up and how to fix it while using the same class SellarMDAPromoteConnect? I cannot come up with any convincing reason(s) to explain this error. Every line of the code I used is same as given in the website (link attached here), I have attached a screenshot of the code snippet used to run the optimization problem setup, just in case you want to have a look at it
Optimization setup code snippet
Your run script has a namespace detail incorrect. The example you pulled from used a mixture of promotion and connection to be illustrative. The obj
variable is computed and owned by the obj_cmp
ExecComp. Only two of the inputs (x
and z
) were promoted. The other two inputs (y1
and y2
) were not and neither was the output objective (obj
).
To add the objective you would do the following:
# prob.model.add_objective('obj') # wrong scope
prob.model.add_objective('obj_cmp.obj') # correct scope
There are a few ways to easily determine the correct names for variables:
list_outputs
method on a group that owns the variables in question.prob.model.list_outputs(prom_name=True)
gives:
varname val prom_name
-------- ---- -------------
cycle
d1
y1 [1.] d1.y1
d2
y2 [1.] d2.y2
obj_cmp
obj [1.] obj_cmp.obj
con_cmp1
con1 [1.] con_cmp1.con1
con_cmp2
con2 [1.] con_cmp2.con2
If you prefer a more visual layout, the N2 also has the information you want: