我有一个输入是int的组件,所以我设置pass_by_obj = True。但是,当我使用check_partial_derivatives()检查衍生物时,会抛出此错误:
data = prob.check_partial_derivatives(out_stream=sys.stdout)
File "/usr/local/lib/python2.7/site-packages/openmdao/core/problem.py", line 1711, in check_partial_derivatives
jac_rev[(u_name, p_name)][idx, :] = dinputs._dat[p_name].val
TypeError: float() argument must be a string or a number
它似乎试图采取衍生物,即使它不能。这是一个简单的例子:
import sys
from openmdao.api import IndepVarComp, Problem, Group, Component
class Comp(Component):
def __init__(self):
super(Comp, self).__init__()
self.add_param('x', val=0.0)
self.add_param('y', val=3, pass_by_obj=True)
self.add_output('z', val=0.0)
def solve_nonlinear(self, params, unknowns, resids):
unknowns['z'] = params['y']*params['x']
def linearize(self, params, unknowns, resids):
J = {}
J['z', 'x'] = params['y']
return J
prob = Problem()
prob.root = Group()
prob.root.add('comp', Comp(), promotes=['*'])
prob.root.add('p1', IndepVarComp('x', 0.0), promotes=['x'])
prob.root.add('p2', IndepVarComp('y', 3, pass_by_obj=True), promotes=['y'])
prob.setup(check=False)
prob['x'] = 2.0
prob['y'] = 3
prob.run()
print prob['z']
data = prob.check_partial_derivatives(out_stream=sys.stdout)
对于具有指定为pass_by_obj的输入的组件,可以使用check_partial_derivatives()方法吗?我不关心指定为pass_by_obj的输入的衍生物,但我关心其他输入。
答案 0 :(得分:2)
感谢您的报告和测试。这是一个我们没有排除声明为pass_by_obj的设计变量的错误。我已经通过修复程序在OpenMDAO repo上获得了拉取请求。它可能会在一天内合并为主人。
编辑 - 修复已合并。 https://github.com/OpenMDAO/OpenMDAO/commit/b123b284e46aac7e15fa9bce3751f9ad9bb63b95