rJonatan
rJonatan

Reputation: 41

OpenMDAO Singular Entry

I'm trying to understand the OpenMDAO error messages

RuntimeError: Singular entry found in '' for column associated with state/residual 'x'.

and

RuntimeError: Singular entry found in '' for row associated with state/residual 'y'.

Can someone explain these? E.g. When running the code

from openmdao.api import Problem, Group, IndepVarComp, ImplicitComponent, ScipyOptimizeDriver, NewtonSolver, DirectSolver, view_model, view_connections


class Test1Comp(ImplicitComponent):

    def setup(self):
        self.add_input('x', 0.5)
        self.add_input('design_x', 1.0)
        self.add_output('z', val=0.0)
        self.add_output('obj')

        self.declare_partials(of='*', wrt='*', method='fd', form='central', step=1.0e-4)

    def apply_nonlinear(self, inputs, outputs, resids):
        x = inputs['x']
        design_x = inputs['design_x']
        z = outputs['z']

        resids['z'] = x*z + z - 4
        resids['obj'] = (z/5.833333 - design_x)**2


if __name__ == "__main__":

    prob = Problem()
    model = prob.model = Group()

    model.add_subsystem('p1', IndepVarComp('x', 0.5))
    model.add_subsystem('d1', IndepVarComp('design_x', 1.0))
    model.add_subsystem('comp', Test1Comp())

    model.connect('p1.x', 'comp.x')
    model.connect('d1.design_x', 'comp.design_x')

    prob.driver = ScipyOptimizeDriver()
    prob.driver.options["optimizer"] = 'SLSQP'
    model.add_design_var("d1.design_x", lower=0.5, upper=1.5)
    model.add_objective('comp.obj')

    model.nonlinear_solver = NewtonSolver()
    model.nonlinear_solver.options['iprint'] = 2
    model.nonlinear_solver.options['maxiter'] = 20
    model.linear_solver = DirectSolver()

    prob.setup()
    prob.run_model()
    print(prob['comp.z'])

I get the error message:

  File "C:\Scripts/mockup_component3.py", line 46, in <module>
    prob.run_model()
  File "C:\Python_32\lib\site-packages\openmdao\core\problem.py", line 315, in run_model
    return self.model.run_solve_nonlinear()
  File "C:\Python_32\lib\site-packages\openmdao\core\system.py", line 2960, in run_solve_nonlinear
    result = self._solve_nonlinear()
  File "C:\Python_32\lib\site-packages\openmdao\core\group.py", line 1420, in _solve_nonlinear
    result = self._nonlinear_solver.solve()
  File "C:\Python_32\lib\site-packages\openmdao\solvers\solver.py", line 602, in solve
    fail, abs_err, rel_err = self._run_iterator()
  File "C:\Python_32\lib\site-packages\openmdao\solvers\solver.py", line 349, in _run_iterator
    self._iter_execute()
  File "C:\Python_32\lib\site-packages\openmdao\solvers\nonlinear\newton.py", line 234, in _iter_execute
    system._linearize()
  File "C:\Python_32\lib\site-packages\openmdao\core\group.py", line 1562, in _linearize
    self._linear_solver._linearize()
  File "C:\Python_32\lib\site-packages\openmdao\solvers\linear\direct.py", line 199, in _linearize
    raise RuntimeError(format_singluar_error(err, system, mtx))
RuntimeError: Singular entry found in '' for column associated with state/residual 'comp.obj'.

This error I was able to solve, by adding - outputs['obj'] in the equation for resids['obj']. But I still have little understanding as to what the two error messages mean. What matrix is it that is singular? And what does it mean to have

1) a singular entry for a column?

2) a singular entry for a row?

Upvotes: 1

Views: 175

Answers (1)

rJonatan
rJonatan

Reputation: 41

I realized that the cause for the singular row was that I had not defined the partial derivatives for the component. I fixed this problem by adding the command declare_partials to the top level system. The traceback gave me the clue that the matrix was related to linearization.

The case with the singular column seems related to that I had two equations in apply_nonlinear, but only one unknown (z).

Upvotes: 1

Related Questions