Reputation: 51
I am trying to change from ''connect'' to ''promotes'' for paraboloid example (without constraint) and I receive the output error. Output not found for response 'parab.f_xy' in system ''.
Feel free to have a look at the code below, I tried to make it similar to the topic explained in the ""Linking Variables with Promotion vs. Connection"". The code is independent from the released paraboloid component.
from openmdao.api import Problem, ScipyOptimizeDriver, IndepVarComp
from openmdao.core.explicitcomponent import ExplicitComponent
class Paraboloid(ExplicitComponent):
def setup(self):
self.add_input('x', val=0.0)
self.add_input('y', val=0.0)
self.add_output('f_xy', val=0.0)
self.declare_partials('*', '*')
def compute(self, inputs, outputs):
x = inputs['x']
y = inputs['y']
outputs['f_xy'] = (x-3.0)**2 + x*y + (y+4.0)**2 - 3.0
def compute_partials(self, inputs, partials):
x = inputs['x']
y = inputs['y']
partials['f_xy', 'x'] = 2.0*x - 6.0 + y
partials['f_xy', 'y'] = 2.0*y + 8.0 + x
# build the model
prob = Problem()
indeps = prob.model.add_subsystem('indeps', IndepVarComp(), promotes=['*'])
indeps.add_output('x', 3.0)
indeps.add_output('y', -4.0)
prob.model.add_subsystem('parab', Paraboloid(), promotes_inputs=['x','y'] , promotes_outputs=['f_xy'])
# setup the optimization
prob.driver = ScipyOptimizeDriver()
prob.driver.options['optimizer'] = 'SLSQP'
prob.model.add_design_var('indeps.x', lower=-50, upper=50)
prob.model.add_design_var('indeps.y', lower=-50, upper=50)
prob.model.add_objective('parab.f_xy')
prob.setup()
prob.run_driver()
Upvotes: 1
Views: 186
Reputation: 754
Because you promoted 'f_xy' up from the 'parab' component, your objective should now be named 'f_xy' instead of 'parab.f_xy', and because you promoted 'x' and 'y' up from the 'indeps' component, your design variables should be named 'x' and 'y' instead of 'indeps.x' and 'indeps.y'.
Upvotes: 3