ValueError: shapes (6,108) and (36,) not aligned: 108 (dim 1) != 36 (dim 0)

ValueError: shapes (6,108) and (36,) not aligned: 108 (dim 1) != 36 (dim 0)

我发现线性化方法存在一些尺寸错误。具体来说,

File "/usr/local/lib/python2.7/site-packages/openmdao/core/system.py", line 726, in _apply_linear_jac
    arg_vec[param] += J.T.dot(dresids._flat(unknown)).reshape(shape)
ValueError: shapes (6,108) and (36,) not aligned: 108 (dim 1) != 36 (dim 0)

我有一些二维数组,它们为所有输入向量定义了单个输出向量的雅可比矩阵的一部分。我无法查明错误的确切原因,因为有几种情况符合给定的形状。我想知道这个问题是否可以通过自己展平数组来解决。

如果您有任何其他关于如何解决此错误的想法,我们将不胜感激。这些渐变在 pre-1.0 中运行良好。

完整的错误信息如下:

Traceback (most recent call last):
  File "/Users/user/directory/exampleOptimization.py", line 82, in <module>
    prob.run()
  File "/usr/local/lib/python2.7/site-packages/openmdao/core/problem.py", line 789, in run
    self.driver.run(self)
  File "/usr/local/lib/python2.7/site-packages/openmdao/drivers/scipy_optimizer.py", line 191, in run
    options=self.opt_settings)
  File "/usr/local/lib/python2.7/site-packages/scipy/optimize/_minimize.py", line 452, in minimize
    constraints, callback=callback, **options)
  File "/usr/local/lib/python2.7/site-packages/scipy/optimize/slsqp.py", line 383, in _minimize_slsqp
    g = append(fprime(x),0.0)
  File "/usr/local/lib/python2.7/site-packages/scipy/optimize/optimize.py", line 285, in function_wrapper
    return function(*(wrapper_args + args))
  File "/usr/local/lib/python2.7/site-packages/openmdao/drivers/scipy_optimizer.py", line 306, in _gradfunc
    return_format='array')
  File "/usr/local/lib/python2.7/site-packages/openmdao/core/driver.py", line 666, in calc_gradient
    sparsity=sparsity)
  File "/usr/local/lib/python2.7/site-packages/openmdao/core/problem.py", line 899, in calc_gradient
    sparsity=sparsity)
  File "/usr/local/lib/python2.7/site-packages/openmdao/core/problem.py", line 1261, in _calc_gradient_ln_solver
    dx_mat = root.ln_solver.solve(rhs, root, mode)
  File "/usr/local/lib/python2.7/site-packages/openmdao/solvers/scipy_gmres.py", line 104, in solve
    callback=self.monitor)
  File "<string>", line 2, in gmres
  File "/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/iterative.py", line 85, in non_reentrant
    return func(*a, **kw)
  File "/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/iterative.py", line 478, in gmres
    work[slice2] += sclr1*matvec(work[slice1])
  File "/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/interface.py", line 220, in matvec
    y = self._matvec(x)
  File "/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/interface.py", line 460, in _matvec
    return self.__matvec_impl(x)
  File "/usr/local/lib/python2.7/site-packages/openmdao/solvers/scipy_gmres.py", line 162, in mult
    system._sys_apply_linear(mode, ls_inputs=self.system._ls_inputs, vois=(voi,))
  File "/usr/local/lib/python2.7/site-packages/openmdao/core/group.py", line 680, in _sys_apply_linear
    gs_outputs=gs_outputs)
  File "/usr/local/lib/python2.7/site-packages/openmdao/core/group.py", line 680, in _sys_apply_linear
    gs_outputs=gs_outputs)
  File "/usr/local/lib/python2.7/site-packages/openmdao/core/system.py", line 619, in _sys_apply_linear
    self.apply_linear(self.params, self.unknowns, dparams, dunknowns, dresids, mode)
  File "/usr/local/lib/python2.7/site-packages/openmdao/core/component.py", line 512, in apply_linear
    mode)
  File "/usr/local/lib/python2.7/site-packages/openmdao/core/system.py", line 726, in _apply_linear_jac
    arg_vec[param] += J.T.dot(dresids._flat(unknown)).reshape(shape)
ValueError: shapes (6,108) and (36,) not aligned: 108 (dim 1) != 36 (dim 0)

刚刚向 dev 推送了一个修复程序,改进了错误大小的 Jacobian 矩阵的错误消息。它们现在看起来像这样:

"In component 'comp', the derivative of 'y2' wrt 'x1' should have shape '(3, 2)' but has shape '(3, 3)' instead."

如果你拉下最新的再试试运行,我想新的消息将有助于查明问题。