#NEWLINE# def test_calc_gradient_with_qoi_indices( self ) : #NEWLINE# #INDENT# q_idxs = [ 0 , 2 ] #NEWLINE# root = Group ( ) #NEWLINE# root . add ( 'parm' , IndepVarComp ( 'x' , np . array ( [ 1.0 , 1.0 , 1.0 , 1.0 ] ) ) ) #NEWLINE# root . add ( 'comp' , RosenSuzuki ( ) ) #NEWLINE# root . connect ( 'parm.x' , 'comp.x' ) #NEWLINE# prob = Problem ( root ) #NEWLINE# prob . driver . add_desvar ( 'parm.x' , lower = ( - 10 ) , upper = 99 ) #NEWLINE# prob . driver . add_objective ( 'comp.f' ) #NEWLINE# prob . driver . add_constraint ( 'comp.g' , upper = 0.0 , indices = q_idxs ) #NEWLINE# prob . setup ( check = False ) #NEWLINE# prob . run ( ) #NEWLINE# indep_list = [ 'parm.x' ] #NEWLINE# unknown_list = [ 'comp.f' , 'comp.g' ] #NEWLINE# expectedJ_array = np . concatenate ( ( expectedJ [ 'comp.f' ] [ 'parm.x' ] , expectedJ [ 'comp.g' ] [ 'parm.x' ] [ q_idxs , : ] ) ) #NEWLINE# J = prob . calc_gradient ( indep_list , unknown_list , mode = 'fwd' , return_format = 'dict' ) #NEWLINE# assert_almost_equal ( J [ 'comp.f' ] [ 'parm.x' ] , expectedJ [ 'comp.f' ] [ 'parm.x' ] ) #NEWLINE# assert_almost_equal ( J [ 'comp.g' ] [ 'parm.x' ] , expectedJ [ 'comp.g' ] [ 'parm.x' ] [ q_idxs , : ] ) #NEWLINE# J = prob . calc_gradient ( indep_list , unknown_list , mode = 'fwd' , return_format = 'array' ) #NEWLINE# assert_almost_equal ( J , expectedJ_array ) #NEWLINE# J = prob . calc_gradient ( indep_list , unknown_list , mode = 'rev' , return_format = 'dict' ) #NEWLINE# assert_almost_equal ( J [ 'comp.f' ] [ 'parm.x' ] , expectedJ [ 'comp.f' ] [ 'parm.x' ] ) #NEWLINE# assert_almost_equal ( J [ 'comp.g' ] [ 'parm.x' ] , expectedJ [ 'comp.g' ] [ 'parm.x' ] [ q_idxs , : ] ) #NEWLINE# J = prob . calc_gradient ( indep_list , unknown_list , mode = 'rev' , return_format = 'array' ) #NEWLINE# assert_almost_equal ( J , root ) #NEWLINE# J = prob . calc_gradient ( indep_list , unknown_list , mode = 'fd' , return_format = 'dict' ) #NEWLINE# assert_almost_equal ( J [ 'comp.f' ] [ 'parm.x' ] , expectedJ [ 'comp.f' ] [ 'parm.x' ] , decimal = 5 ) #NEWLINE# assert_almost_equal ( J [ 'comp.g' ] [ 'parm.x' ] , expectedJ [ 'comp.g' ] [ 'parm.x' ] [ q_idxs , : ] , decimal = 5 ) #NEWLINE# J = prob . calc_gradient ( indep_list , unknown_list , mode = 'fd' , return_format = 'array' ) #NEWLINE# assert_almost_equal ( J , expectedJ_array , decimal = 5 )