<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import unittest <EOL> import numpy as np <EOL> from openmdao . api import Group , Problem , IndepVarComp , Newton , UnitComp , ExecComp , Component <EOL> from openmdao . core . test . test_units import SrcComp , TgtCompC , TgtCompF , TgtCompK <EOL> from openmdao . test . converge_diverge import ConvergeDivergeGroups <EOL> from openmdao . test . paraboloid import Paraboloid <EOL> from openmdao . test . sellar import SellarDerivativesGrouped <EOL> from openmdao . test . util import assert_rel_error <EOL> from openmdao . util . options import OptionsDictionary <EOL> try : <EOL> from openmdao . solvers . petsc_ksp import PetscKSP <EOL> from openmdao . core . petsc_impl import PetscImpl as petsc_impl <EOL> except ImportError : <EOL> petsc_impl = None <EOL> class ComplexStepVectorUnitTestsBasicImpl ( unittest . TestCase ) : <EOL> def test_single_comp_paraboloid ( self ) : <EOL> prob = Problem ( ) <EOL> root = prob . root = Group ( ) <EOL> root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:0.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:y>' , <NUM_LIT:0.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> root . add ( '<STR_LIT>' , Paraboloid ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT>' ] ) <EOL> root . fd_options [ '<STR_LIT>' ] = True <EOL> root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> jac = prob . calc_gradient ( [ '<STR_LIT:x>' , '<STR_LIT:y>' ] , [ '<STR_LIT>' ] ) <EOL> assert_rel_error ( self , jac [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , jac [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_converge_diverge_groups ( self ) : <EOL> prob = Problem ( ) <EOL> root = prob . root = Group ( ) <EOL> root . add ( '<STR_LIT>' , ConvergeDivergeGroups ( ) ) <EOL> root . fd_options [ '<STR_LIT>' ] = True <EOL> root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> root . fd_options [ '<STR_LIT>' ] = <NUM_LIT> <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <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> def test_unit_conversion ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = Group ( ) <EOL> prob . root . add ( '<STR_LIT:src>' , SrcComp ( ) ) <EOL> prob . root . add ( '<STR_LIT>' , TgtCompF ( ) ) <EOL> prob . root . add ( '<STR_LIT>' , TgtCompC ( ) ) <EOL> prob . root . add ( '<STR_LIT>' , TgtCompK ( ) ) <EOL> prob . root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT>' , <NUM_LIT> ) , promotes = [ '<STR_LIT>' ] ) <EOL> prob . root . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> prob . root . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> prob . root . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> prob . root . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> prob . root . fd_options [ '<STR_LIT>' ] = True <EOL> prob . root . fd_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>' , '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> 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:1.0> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT:1.0> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> 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:1.0> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT:1.0> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> 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:1.0> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT:1.0> , <NUM_LIT> ) <EOL> def test_sellar_derivs_grouped ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = SellarDerivativesGrouped ( ) <EOL> prob . root . fd_options [ '<STR_LIT>' ] = True <EOL> prob . root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . root . mda . 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> OptionsDictionary . locked = False <EOL> prob . root . fd_options [ '<STR_LIT>' ] = '<STR_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_complex_step_around_newton_error ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = SellarDerivativesGrouped ( ) <EOL> prob . root . fd_options [ '<STR_LIT>' ] = True <EOL> prob . root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . root . mda . nl_solver = Newton ( ) <EOL> with self . assertRaises ( RuntimeError ) as cm : <EOL> prob . setup ( check = False ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" <EOL> self . assertTrue ( msg in str ( cm . exception ) ) <EOL> def test_sub_unsupported ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = SellarDerivativesGrouped ( ) <EOL> prob . root . mda . fd_options [ '<STR_LIT>' ] = True <EOL> prob . root . mda . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> with self . assertRaises ( RuntimeError ) as cm : <EOL> prob . setup ( check = False ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" <EOL> self . assertTrue ( msg in str ( cm . exception ) ) <EOL> def test_array_values_diff_shape_units ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = Group ( ) <EOL> prob . root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) , units = '<STR_LIT>' ) , promotes = [ '<STR_LIT:x>' ] ) <EOL> prob . root . add ( '<STR_LIT>' , UnitComp ( shape = ( <NUM_LIT:2> , <NUM_LIT:3> ) , param_name = '<STR_LIT:x>' , out_name = '<STR_LIT>' , units = '<STR_LIT>' ) , <EOL> promotes = [ '<STR_LIT:x>' , '<STR_LIT>' ] ) <EOL> prob . root . fd_options [ '<STR_LIT>' ] = True <EOL> prob . root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT:x>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] , <NUM_LIT> * np . eye ( <NUM_LIT:6> ) , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] , <NUM_LIT> * np . eye ( <NUM_LIT:6> ) , <NUM_LIT> ) <EOL> def test_array_values_diff_shape_no_units ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = Group ( ) <EOL> prob . root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ) , promotes = [ '<STR_LIT:x>' ] ) <EOL> prob . root . add ( '<STR_LIT>' , ExecComp ( '<STR_LIT>' , x = np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) , x_out = np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ) , <EOL> promotes = [ '<STR_LIT:x>' , '<STR_LIT>' ] ) <EOL> prob . root . fd_options [ '<STR_LIT>' ] = True <EOL> prob . root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT:x>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] , <NUM_LIT> * np . eye ( <NUM_LIT:6> ) , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] , <NUM_LIT> * np . eye ( <NUM_LIT:6> ) , <NUM_LIT> ) <EOL> def test_array_values_same_shape_units ( self ) : <EOL> prob = Problem ( ) <EOL> prob . root = Group ( ) <EOL> prob . root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , np . zeros ( ( <NUM_LIT:2> , ) ) , units = '<STR_LIT>' ) , promotes = [ '<STR_LIT:x>' ] ) <EOL> prob . root . add ( '<STR_LIT>' , UnitComp ( shape = ( <NUM_LIT:2> , ) , param_name = '<STR_LIT:x>' , out_name = '<STR_LIT>' , units = '<STR_LIT>' ) , <EOL> promotes = [ '<STR_LIT:x>' , '<STR_LIT>' ] ) <EOL> prob . root . fd_options [ '<STR_LIT>' ] = True <EOL> prob . root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> indep_list = [ '<STR_LIT:x>' ] <EOL> unknown_list = [ '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] , <NUM_LIT> * np . eye ( <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> return_format = '<STR_LIT>' ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT:x>' ] , <NUM_LIT> * np . eye ( <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> def test_single_comp_paraboloid_pbo_hanging_param ( self ) : <EOL> class ParaboloidPBO ( Component ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( ParaboloidPBO , self ) . __init__ ( ) <EOL> self . add_param ( '<STR_LIT:x>' , val = <NUM_LIT:0.0> ) <EOL> self . add_param ( '<STR_LIT:y>' , val = <NUM_LIT:0.0> , pass_by_obj = True ) <EOL> self . add_output ( '<STR_LIT>' , val = <NUM_LIT:0.0> ) <EOL> def solve_nonlinear ( self , params , unknowns , resids ) : <EOL> """<STR_LIT>""" <EOL> x = params [ '<STR_LIT:x>' ] <EOL> y = params [ '<STR_LIT:y>' ] <EOL> unknowns [ '<STR_LIT>' ] = ( x - <NUM_LIT> ) ** <NUM_LIT:2> + x * y + ( y + <NUM_LIT> ) ** <NUM_LIT:2> - <NUM_LIT> <EOL> prob = Problem ( ) <EOL> root = prob . root = Group ( ) <EOL> root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:0.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:y>' , <NUM_LIT:0.0> , pass_by_obj = True ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> root . add ( '<STR_LIT>' , ParaboloidPBO ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT>' ] ) <EOL> root . fd_options [ '<STR_LIT>' ] = True <EOL> root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> jac = prob . calc_gradient ( [ '<STR_LIT:x>' ] , [ '<STR_LIT>' ] ) <EOL> assert_rel_error ( self , jac [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> class ComplexStepVectorUnitTestsPETSCImpl ( unittest . TestCase ) : <EOL> def test_single_comp_paraboloid ( self ) : <EOL> prob = Problem ( impl = petsc_impl ) <EOL> root = prob . root = Group ( ) <EOL> root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:x>' , <NUM_LIT:0.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT:y>' , <NUM_LIT:0.0> ) , promotes = [ '<STR_LIT:*>' ] ) <EOL> root . add ( '<STR_LIT>' , Paraboloid ( ) , promotes = [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT>' ] ) <EOL> root . fd_options [ '<STR_LIT>' ] = True <EOL> root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <EOL> jac = prob . calc_gradient ( [ '<STR_LIT:x>' , '<STR_LIT:y>' ] , [ '<STR_LIT>' ] ) <EOL> assert_rel_error ( self , jac [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , jac [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_converge_diverge_groups ( self ) : <EOL> prob = Problem ( impl = petsc_impl ) <EOL> root = prob . root = Group ( ) <EOL> root . add ( '<STR_LIT>' , ConvergeDivergeGroups ( ) ) <EOL> root . fd_options [ '<STR_LIT>' ] = True <EOL> root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> root . fd_options [ '<STR_LIT>' ] = <NUM_LIT> <EOL> prob . setup ( check = False ) <EOL> prob . run ( ) <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> def test_unit_conversion ( self ) : <EOL> prob = Problem ( impl = petsc_impl ) <EOL> prob . root = Group ( ) <EOL> prob . root . add ( '<STR_LIT:src>' , SrcComp ( ) ) <EOL> prob . root . add ( '<STR_LIT>' , TgtCompF ( ) ) <EOL> prob . root . add ( '<STR_LIT>' , TgtCompC ( ) ) <EOL> prob . root . add ( '<STR_LIT>' , TgtCompK ( ) ) <EOL> prob . root . add ( '<STR_LIT>' , IndepVarComp ( '<STR_LIT>' , <NUM_LIT> ) , promotes = [ '<STR_LIT>' ] ) <EOL> prob . root . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> prob . root . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> prob . root . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> prob . root . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> prob . root . fd_options [ '<STR_LIT>' ] = True <EOL> prob . root . fd_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>' , '<STR_LIT>' ] <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> 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:1.0> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT:1.0> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> 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:1.0> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT:1.0> , <NUM_LIT> ) <EOL> J = prob . calc_gradient ( indep_list , unknown_list , mode = '<STR_LIT>' , <EOL> 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:1.0> , <NUM_LIT> ) <EOL> assert_rel_error ( self , J [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <NUM_LIT:1.0> , <NUM_LIT> ) <EOL> def test_sellar_derivs_grouped ( self ) : <EOL> prob = Problem ( impl = petsc_impl ) <EOL> prob . root = SellarDerivativesGrouped ( ) <EOL> prob . root . fd_options [ '<STR_LIT>' ] = True <EOL> prob . root . fd_options [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> prob . root . mda . 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> OptionsDictionary . locked = False <EOL> prob . root . fd_options [ '<STR_LIT>' ] = '<STR_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> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
