0
votes

I am missing a point on how to get the 'output' out of a metamodel that is being used as a component in the problem. It is clear the compute part should have an output but how. Below is the simple sin function as a metamodelunstructured component. I tried to modify the samples. But the error is :

File "C:\Users\ebarlas\AppData\Local\Continuum\anaconda3\lib\site-packages\openmdao\core\group.py", line 201, in _setup_procs subsys._setup_procs(subsys.name, sub_comm)

TypeError: _setup_procs() missing 1 required positional argument: 'comm'

import numpy as np
from openmdao.api import Problem, Group, IndepVarComp
from openmdao.api import  ScipyOptimizeDriver
from openmdao.api import  MetaModelUnStructured, FloatKrigingSurrogate
# Below class syntax is not working 
class trig(MetaModelUnStructured):
    def setup(self):
        self.add_input('x', 0., training_data=np.linspace(0,10,20))
        self.add_output('sin_x', 0., surrogate=FloatKrigingSurrogate(), 
                        training_data=.5*np.sin(np.linspace(0,10,20)))

        self.declare_partials(of='sin_x', wrt='x', method='fd')
# If I uncomment 4 lines below and comment out the class above it works fine.
#trig = MetaModelUnStructured()
#trig.add_input('x', 0., training_data=np.linspace(0,10,20))
#trig.add_output('sin_x', 0., surrogate=FloatKrigingSurrogate(), 
#                training_data=.5*np.sin(np.linspace(0,10,20)))
#trig.declare_partials(of='sin_x', wrt='x', method='fd')

prob = Problem()
inputs_comp = IndepVarComp()
inputs_comp.add_output('x',  5)
prob.model.add_subsystem('inputs_comp', inputs_comp)
prob.model.add_subsystem('trig', trig)

prob.model.connect('inputs_comp.x', 'trig.x')

prob.driver = ScipyOptimizeDriver()
prob.driver.options['optimizer'] = 'COBYLA'

prob.driver.options['tol'] = 1e-3
prob.driver.options['disp'] = True

prob.model.add_design_var('inputs_comp.x', lower=4, upper=7)
prob.model.add_objective('trig.sin_x')

prob.setup(check=True)

prob.run_driver()

print(prob['trig.sin_x'])
print(prob['trig.x'])
3

3 Answers

3
votes

You shouldn't implement the compute function for a MetaModel (outputs are predicted not computed).

See the docs here: http://openmdao.org/twodocs/versions/latest/features/building_blocks/components/metamodelunstructured.html

0
votes

thanks for the clarification to the question. Note that the error in your updated example is for passing the class definition trig instead of an instance, but after correcting that I can see the problem.

This is a bug in MetaModelUnStructured... this will be fixed shortly.

0
votes

You are using MetaModelUnstructured component incorrectly, but there is another bug getting in the way first.

The class trig you've defined is not the same thing as the instance named trig in your commented out code. One is a class, the other is an instance. You can't pass a class into add_subsystem.

However, even fixing that problem there is still a bug in MetaModelUnstructured when its sub-classed. We'll get a fix in before OpenMDAO 2.3, but for now the way you've done it in the commented out code will work.