<s> """<STR_LIT>""" <EOL> import unittest <EOL> import numpy as np <EOL> from openmdao . api import Group , Problem , IndepVarComp , ExecComp , DirectSolver , LinearGaussSeidel , Newton <EOL> from openmdao . core . test . test_residual_sign import SimpleImplicitSL <EOL> from openmdao . test . converge_diverge import ConvergeDiverge , SingleDiamond , ConvergeDivergeGroups , SingleDiamondGrouped <EOL> from openmdao . test . sellar import SellarStateConnection <EOL> from openmdao . test . simple_comps import SimpleCompDerivMatVec , FanOut , FanIn , FanOutGrouped , FanInGrouped , ArrayComp2D <EOL> from openmdao . test . util import assert_rel_error <EOL> class TestDirectSolver ( unittest . TestCase ) : <EOL> def test_simple_matvec ( self ) : <EOL> group = Group ( ) <EOL> group . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:1.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> group . add ( '<STR_LIT>' , SimpleCompDerivMatVec ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = group <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_simple_matvec_subbed ( self ) : <EOL> group = Group ( ) <EOL> group . add ( '<STR_LIT>' , SimpleCompDerivMatVec ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = Group ( ) <EOL> prob . root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:1.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> prob . root . add ( '<STR_LIT>' , group , promotes = [ '<STR_LIT:*>' ] ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_array2D ( self ) : <EOL> group = Group ( ) <EOL> group . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , np . ones ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> group . add ( '<STR_LIT>' , ArrayComp2D ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = group <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> Jbase = prob . root . mycomp . _jacobian_cache <EOL> diff = np . linalg . norm ( J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] - Jbase [ '<STR_LIT:y>' , '<STR_LIT:x>' ] ) <EOL> assert_rel_error ( self , diff , <NUM_LIT:0.0> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> diff = np . linalg . norm ( J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] - Jbase [ '<STR_LIT:y>' , '<STR_LIT:x>' ] ) <EOL> assert_rel_error ( self , diff , <NUM_LIT:0.0> , <NUM_LIT> ) <EOL> def test_simple_in_group_matvec ( self ) : <EOL> group = Group ( ) <EOL> sub = group . add ( '<STR_LIT>' , Group ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> group . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:1.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> sub . add ( '<STR_LIT>' , SimpleCompDerivMatVec ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = group <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_simple_jac ( self ) : <EOL> group = Group ( ) <EOL> group . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:1.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> group . add ( '<STR_LIT>' , ExecComp ( [ '<STR_LIT>' ] ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = group <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_fan_out ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = FanOut ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_fan_out_grouped ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = FanOutGrouped ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_fan_in ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = FanIn ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_fan_in_grouped ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = FanInGrouped ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_converge_diverge ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = ConvergeDiverge ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> prob . run ( ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_converge_diverge_groups ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = ConvergeDivergeGroups ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_single_diamond ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = SingleDiamond ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_single_diamond_grouped ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = SingleDiamondGrouped ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_sellar_derivs ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = SellarStateConnection ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . nl_solver . options [ '<STR_LIT>' ] = <NUM_LIT> <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , <NUM_LIT> , <NUM_LIT> ) <EOL> indep_list = [ '<STR_LIT:x>' , '<STR_LIT:z>' ] <EOL> unknown_list = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> Jbase = { } <EOL> Jbase [ '<STR_LIT>' ] = { } <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] = - <NUM_LIT> <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:z>' ] = np . array ( [ - <NUM_LIT> , - <NUM_LIT> ] ) <EOL> Jbase [ '<STR_LIT>' ] = { } <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] = <NUM_LIT> <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:z>' ] = np . array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> Jbase [ '<STR_LIT>' ] = { } <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] = <NUM_LIT> <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:z>' ] = np . array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> for key1 , val1 in Jbase . items ( ) : <EOL> for key2 , val2 in val1 . items ( ) : <EOL> assert_rel_error ( self , J [ key1 ] [ key2 ] , val2 , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> for key1 , val1 in Jbase . items ( ) : <EOL> for key2 , val2 in val1 . items ( ) : <EOL> assert_rel_error ( self , J [ key1 ] [ key2 ] , val2 , <NUM_LIT> ) <EOL> def test_implicit_solve_linear ( self ) : <EOL> p = Problem ( ) <EOL> p . root = Group ( ) <EOL> dvars = ( ( '<STR_LIT:a>' , <NUM_LIT> ) , ( '<STR_LIT:b>' , <NUM_LIT> ) ) <EOL> p . root . add ( '<STR_LIT>' , IndepVarComp ( dvars ) , promotes = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> sg = p . root . add ( '<STR_LIT>' , Group ( ) , promotes = [ "<STR_LIT:*>" ] ) <EOL> sg . add ( '<STR_LIT>' , SimpleImplicitSL ( ) , promotes = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:x>' ] ) <EOL> p . root . add ( '<STR_LIT>' , ExecComp ( '<STR_LIT>' ) , promotes = [ '<STR_LIT:f>' , '<STR_LIT>' , '<STR_LIT:a>' ] ) <EOL> p . root . connect ( '<STR_LIT:x>' , '<STR_LIT>' , src_indices = [ <NUM_LIT:1> ] ) <EOL> p . driver . add_objective ( '<STR_LIT:f>' ) <EOL> p . driver . add_desvar ( '<STR_LIT:a>' ) <EOL> p . root . nl_solver = Newton ( ) <EOL> p . root . nl_solver . options [ '<STR_LIT>' ] = <NUM_LIT> <EOL> p . root . nl_solver . options [ '<STR_LIT>' ] = <NUM_LIT> <EOL> p . root . ln_solver = DirectSolver ( ) <EOL> p . setup ( check = False ) <EOL> p [ '<STR_LIT:x>' ] = np . array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> p . run ( ) <EOL> J = p . calc_gradient ( [ '<STR_LIT:a>' ] , [ '<STR_LIT:f>' ] , mode = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> class TestDirectSolverAssemble ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_simple_matvec ( self ) : <EOL> group = Group ( ) <EOL> group . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:1.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> group . add ( '<STR_LIT>' , SimpleCompDerivMatVec ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = group <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> with self . assertRaises ( RuntimeError ) as cm : <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> expected_msg = "<STR_LIT>" + "<STR_LIT>" <EOL> self . assertEqual ( str ( cm . exception ) , expected_msg ) <EOL> def test_simple_matvec_subbed ( self ) : <EOL> group = Group ( ) <EOL> group . add ( '<STR_LIT>' , SimpleCompDerivMatVec ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = Group ( ) <EOL> prob . root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:1.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> prob . root . add ( '<STR_LIT>' , group , promotes = [ '<STR_LIT:*>' ] ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> with self . assertRaises ( RuntimeError ) as cm : <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> expected_msg = "<STR_LIT>" + "<STR_LIT>" <EOL> self . assertEqual ( str ( cm . exception ) , expected_msg ) <EOL> def test_array2D ( self ) : <EOL> group = Group ( ) <EOL> group . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , np . ones ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> group . add ( '<STR_LIT>' , ArrayComp2D ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = group <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> Jbase = prob . root . mycomp . _jacobian_cache <EOL> diff = np . linalg . norm ( J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] - Jbase [ '<STR_LIT:y>' , '<STR_LIT:x>' ] ) <EOL> assert_rel_error ( self , diff , <NUM_LIT:0.0> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> diff = np . linalg . norm ( J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] - Jbase [ '<STR_LIT:y>' , '<STR_LIT:x>' ] ) <EOL> assert_rel_error ( self , diff , <NUM_LIT:0.0> , <NUM_LIT> ) <EOL> def test_array2D_no_decompose ( self ) : <EOL> group = Group ( ) <EOL> group . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , np . ones ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> group . add ( '<STR_LIT>' , ArrayComp2D ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = group <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> Jbase = prob . root . mycomp . _jacobian_cache <EOL> diff = np . linalg . norm ( J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] - Jbase [ '<STR_LIT:y>' , '<STR_LIT:x>' ] ) <EOL> assert_rel_error ( self , diff , <NUM_LIT:0.0> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> diff = np . linalg . norm ( J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] - Jbase [ '<STR_LIT:y>' , '<STR_LIT:x>' ] ) <EOL> assert_rel_error ( self , diff , <NUM_LIT:0.0> , <NUM_LIT> ) <EOL> def test_simple_in_group_matvec ( self ) : <EOL> group = Group ( ) <EOL> sub = group . add ( '<STR_LIT>' , Group ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> group . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:1.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> sub . add ( '<STR_LIT>' , SimpleCompDerivMatVec ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = group <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> with self . assertRaises ( RuntimeError ) as cm : <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> expected_msg = "<STR_LIT>" + "<STR_LIT>" <EOL> self . assertEqual ( str ( cm . exception ) , expected_msg ) <EOL> def test_simple_jac ( self ) : <EOL> group = Group ( ) <EOL> group . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:1.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> group . add ( '<STR_LIT>' , ExecComp ( [ '<STR_LIT>' ] ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> prob = Problem ( ) <EOL> prob . root = group <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT:y>' ] [ '<STR_LIT:x>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_fan_out ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = FanOut ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_fan_out_grouped ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = FanOutGrouped ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_fan_in ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = FanIn ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_fan_in_grouped ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = FanInGrouped ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_converge_diverge ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = ConvergeDiverge ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> prob . run ( ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_converge_diverge_groups ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = ConvergeDivergeGroups ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_single_diamond ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = SingleDiamond ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_single_diamond_grouped ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = SingleDiamondGrouped ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_sellar_derivs ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = SellarStateConnection ( ) <EOL> prob . root . ln_solver = DirectSolver ( ) <EOL> prob . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . root . nl_solver . options [ '<STR_LIT>' ] = <NUM_LIT> <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , <NUM_LIT> , <NUM_LIT> ) <EOL> indep_list = [ '<STR_LIT:x>' , '<STR_LIT:z>' ] <EOL> unknown_list = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> Jbase = { } <EOL> Jbase [ '<STR_LIT>' ] = { } <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] = - <NUM_LIT> <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:z>' ] = np . array ( [ - <NUM_LIT> , - <NUM_LIT> ] ) <EOL> Jbase [ '<STR_LIT>' ] = { } <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] = <NUM_LIT> <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:z>' ] = np . array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> Jbase [ '<STR_LIT>' ] = { } <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] = <NUM_LIT> <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT:z>' ] = np . array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> for key1 , val1 in Jbase . items ( ) : <EOL> for key2 , val2 in val1 . items ( ) : <EOL> assert_rel_error ( self , J [ key1 ] [ key2 ] , val2 , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> for key1 , val1 in Jbase . items ( ) : <EOL> for key2 , val2 in val1 . items ( ) : <EOL> assert_rel_error ( self , J [ key1 ] [ key2 ] , val2 , <NUM_LIT> ) <EOL> def test_sellar_derivs_under_lin_GS ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = Group ( ) <EOL> prob . root . ln_solver = LinearGaussSeidel ( ) <EOL> nest = prob . root . add ( '<STR_LIT>' , SellarStateConnection ( ) ) <EOL> nest . ln_solver = DirectSolver ( ) <EOL> nest . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> nest . nl_solver . options [ '<STR_LIT>' ] = <NUM_LIT> <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , prob [ '<STR_LIT>' ] , <NUM_LIT> , <NUM_LIT> ) <EOL> indep_list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> unknown_list = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> Jbase = { } <EOL> Jbase [ '<STR_LIT>' ] = { } <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT>' ] = - <NUM_LIT> <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT>' ] = np . array ( [ - <NUM_LIT> , - <NUM_LIT> ] ) <EOL> Jbase [ '<STR_LIT>' ] = { } <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT> <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT>' ] = np . array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> Jbase [ '<STR_LIT>' ] = { } <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT> <EOL> Jbase [ '<STR_LIT>' ] [ '<STR_LIT>' ] = np . array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> for key1 , val1 in Jbase . items ( ) : <EOL> for key2 , val2 in val1 . items ( ) : <EOL> assert_rel_error ( self , J [ key1 ] [ key2 ] , val2 , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , return_format = '<STR_LIT>' ) <EOL> for key1 , val1 in Jbase . items ( ) : <EOL> for key2 , val2 in val1 . items ( ) : <EOL> assert_rel_error ( self , J [ key1 ] [ key2 ] , val2 , <NUM_LIT> ) <EOL> def test_implicit_solve_linear ( self ) : <EOL> p = Problem ( ) <EOL> p . root = Group ( ) <EOL> dvars = ( ( '<STR_LIT:a>' , <NUM_LIT> ) , ( '<STR_LIT:b>' , <NUM_LIT> ) ) <EOL> p . root . add ( '<STR_LIT>' , IndepVarComp ( dvars ) , promotes = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> sg = p . root . add ( '<STR_LIT>' , Group ( ) , promotes = [ "<STR_LIT:*>" ] ) <EOL> sg . add ( '<STR_LIT>' , SimpleImplicitSL ( ) , promotes = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:x>' ] ) <EOL> p . root . add ( '<STR_LIT>' , ExecComp ( '<STR_LIT>' ) , promotes = [ '<STR_LIT:f>' , '<STR_LIT>' , '<STR_LIT:a>' ] ) <EOL> p . root . connect ( '<STR_LIT:x>' , '<STR_LIT>' , src_indices = [ <NUM_LIT:1> ] ) <EOL> p . driver . add_objective ( '<STR_LIT:f>' ) <EOL> p . driver . add_desvar ( '<STR_LIT:a>' ) <EOL> p . root . nl_solver = Newton ( ) <EOL> p . root . nl_solver . options [ '<STR_LIT>' ] = <NUM_LIT> <EOL> p . root . nl_solver . options [ '<STR_LIT>' ] = <NUM_LIT> <EOL> p . root . ln_solver = DirectSolver ( ) <EOL> p . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> p . setup ( check = False ) <EOL> p [ '<STR_LIT:x>' ] = np . array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> p . run ( ) <EOL> J = p . calc_gradient ( [ '<STR_LIT:a>' ] , [ '<STR_LIT:f>' ] , mode = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_unrel_var_in_Jac ( self ) : <EOL> p = Problem ( ) <EOL> root = p . root = Group ( ) <EOL> root . add ( '<STR_LIT:p>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT> ) ) <EOL> root . add ( '<STR_LIT>' , ExecComp ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> root . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> p . driver . add_objective ( '<STR_LIT>' ) <EOL> p . driver . add_desvar ( '<STR_LIT>' ) <EOL> p . root . ln_solver = DirectSolver ( ) <EOL> p . root . ln_solver . options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> p . setup ( check = False ) <EOL> p . run ( ) <EOL> J = p . calc_gradient ( [ '<STR_LIT>' ] , [ '<STR_LIT>' ] , mode = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
