When using Newton solver-based shooting with a Krylov linear solver, the LinearRunOnce preconditioner fails with the following error.
It seems the error comes from the DirectSolver attached to indep_states component.
Dymos 1.9.0 didn't cause this error because indep_states didn't have a DirectSolver for the shooting settings. I believe the behavior changed since PR #991 .
Error message
Traceback (most recent call last):
File "/Users/shugo/dymos_bug/brachistochrone_shooting.py", line 77, in <module>
dm.run_problem(p, run_driver=False)
File "/Users/shugo/packages/dymos/dymos/run_problem.py", line 100, in run_problem
failed = problem.run_model()
^^^^^^^^^^^^^^^^^^^
File "/Users/shugo/packages/openmdao-dev/openmdao/core/problem.py", line 654, in run_model
self.model.run_solve_nonlinear()
File "/Users/shugo/packages/openmdao-dev/openmdao/core/system.py", line 4552, in run_solve_nonlinear
self._solve_nonlinear()
File "/Users/shugo/packages/openmdao-dev/openmdao/core/group.py", line 3593, in _solve_nonlinear
self._nonlinear_solver._solve_with_cache_check()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/nonlinear/nonlinear_runonce.py", line 26, in _solve_with_cache_check
self.solve() # don't use caching
^^^^^^^^^^^^
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/nonlinear/nonlinear_runonce.py", line 45, in solve
self._gs_iter()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/solver.py", line 803, in _gs_iter
subsys._solve_nonlinear()
File "/Users/shugo/packages/openmdao-dev/openmdao/core/group.py", line 3593, in _solve_nonlinear
self._nonlinear_solver._solve_with_cache_check()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/nonlinear/nonlinear_runonce.py", line 26, in _solve_with_cache_check
self.solve() # don't use caching
^^^^^^^^^^^^
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/nonlinear/nonlinear_runonce.py", line 45, in solve
self._gs_iter()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/solver.py", line 803, in _gs_iter
subsys._solve_nonlinear()
File "/Users/shugo/packages/openmdao-dev/openmdao/core/group.py", line 3593, in _solve_nonlinear
self._nonlinear_solver._solve_with_cache_check()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/nonlinear/nonlinear_runonce.py", line 26, in _solve_with_cache_check
self.solve() # don't use caching
^^^^^^^^^^^^
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/nonlinear/nonlinear_runonce.py", line 45, in solve
self._gs_iter()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/solver.py", line 803, in _gs_iter
subsys._solve_nonlinear()
File "/Users/shugo/packages/openmdao-dev/openmdao/core/group.py", line 3593, in _solve_nonlinear
self._nonlinear_solver._solve_with_cache_check()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/solver.py", line 845, in _solve_with_cache_check
self.solve()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/solver.py", line 592, in solve
raise err
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/solver.py", line 588, in solve
self._solve()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/solver.py", line 674, in _solve
self._single_iteration()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/nonlinear/newton.py", line 227, in _single_iteration
system._linearize(my_asm_jac, sub_do_ln=do_sub_ln)
File "/Users/shugo/packages/openmdao-dev/openmdao/core/group.py", line 3822, in _linearize
subsys._linear_solver._linearize()
File "/Users/shugo/packages/openmdao-dev/openmdao/solvers/linear/direct.py", line 277, in _linearize
matrix = self._assembled_jac._int_mtx._matrix
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '_matrix'
Workarounds
Switch back to Dymos 1.9.0
Comment out the DirectSolver line added in PR #991 .
Remove the DirectSolver in runscript. For example, after the setup, traj.phases.phase0.indep_states.linear_solver = None.
Potential fix
I believe attaching aDirectSolver for indep_states is not necessary for shooting cases, because Dymos has a DirectSolver at the phase level anyway.
Example
Here is a Brachistochrone example. I made a few changes to the collocation example in the Dymos docs:
1. Use solver-based shooting
I'm thinking the correct way to handle this is to noisily add a Newton and Direct solver when appropriate by default, but to let the user know how to easily replace these with the PetscKrylov solver.
Description
When using Newton solver-based shooting with a Krylov linear solver, the
LinearRunOnce
preconditioner fails with the following error. It seems the error comes from theDirectSolver
attached toindep_states
component.Dymos 1.9.0 didn't cause this error because
indep_states
didn't have aDirectSolver
for the shooting settings. I believe the behavior changed since PR #991 .Error message
Workarounds
DirectSolver
in runscript. For example, after the setup,traj.phases.phase0.indep_states.linear_solver = None
.Potential fix
I believe attaching a
DirectSolver
forindep_states
is not necessary for shooting cases, because Dymos has aDirectSolver
at the phase level anyway.Example
Here is a Brachistochrone example. I made a few changes to the collocation example in the Dymos docs: 1. Use solver-based shooting
2. Change the phase-level linear solver to PETScKrylov
Complete script
Dymos Version
1.9.1
Relevant environment information
OpenMDAO 3.28.0