<s> from unittest import TestCase <EOL> import time <EOL> import numpy as np <EOL> from openmdao . lib . drivers . iterate import FixedPointIterator <EOL> from openmdao . lib . drivers . newton_solver import NewtonSolver <EOL> from openmdao . lib . optproblems import sellar <EOL> from openmdao . main . api import Assembly , Component , set_as_top , Driver <EOL> from openmdao . main . datatypes . api import Float , Array , Str , List <EOL> from openmdao . main . interfaces import implements , ISolver <EOL> from openmdao . main . mpiwrap import MPI , MPIContext <EOL> from openmdao . main . test . simpledriver import SimpleDriver <EOL> from openmdao . test . execcomp import ExecComp <EOL> from openmdao . test . mpiunittest import MPITestCase <EOL> from openmdao . util . testutil import assert_rel_error <EOL> class NoDerivSimpleDriver ( SimpleDriver ) : <EOL> def requires_derivs ( self ) : <EOL> return False <EOL> class NoDerivSimpleDriverSetter ( NoDerivSimpleDriver ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( NoDerivSimpleDriverSetter , self ) . __init__ ( * args , ** kwargs ) <EOL> self . vals = [ ] <EOL> def execute ( self ) : <EOL> self . set_parameters ( self . vals ) <EOL> self . run_iteration ( ) <EOL> class ABCDArrayComp ( Component ) : <EOL> delay = Float ( <NUM_LIT> , iotype = '<STR_LIT>' ) <EOL> in_string = Str ( iotype = '<STR_LIT>' ) <EOL> out_string = Str ( iotype = '<STR_LIT>' ) <EOL> in_list = List ( iotype = '<STR_LIT>' ) <EOL> out_list = List ( iotype = '<STR_LIT>' ) <EOL> def __init__ ( self , arr_size = <NUM_LIT:9> ) : <EOL> super ( ABCDArrayComp , self ) . __init__ ( ) <EOL> self . add_trait ( '<STR_LIT:a>' , Array ( np . ones ( arr_size , float ) , iotype = '<STR_LIT>' ) ) <EOL> self . add_trait ( '<STR_LIT:b>' , Array ( np . ones ( arr_size , float ) , iotype = '<STR_LIT>' ) ) <EOL> self . add_trait ( '<STR_LIT:c>' , Array ( np . ones ( arr_size , float ) , iotype = '<STR_LIT>' ) ) <EOL> self . add_trait ( '<STR_LIT:d>' , Array ( np . ones ( arr_size , float ) , iotype = '<STR_LIT>' ) ) <EOL> def execute ( self ) : <EOL> time . sleep ( self . delay ) <EOL> self . c = self . a + self . b <EOL> self . d = self . a - self . b <EOL> self . out_string = self . in_string + '<STR_LIT:_>' + self . name <EOL> self . out_list = self . in_list [ : ] + [ <NUM_LIT> ] <EOL> def dump ( self , comm ) : <EOL> print "<STR_LIT>" % ( comm . rank , self . name , self . a ) <EOL> print "<STR_LIT>" % ( comm . rank , self . name , self . b ) <EOL> print "<STR_LIT>" % ( comm . rank , self . name , self . c ) <EOL> print "<STR_LIT>" % ( comm . rank , self . name , self . d ) <EOL> class SellarMDF ( Assembly ) : <EOL> """<STR_LIT>""" <EOL> def configure ( self ) : <EOL> """<STR_LIT>""" <EOL> self . add ( '<STR_LIT>' , FixedPointIterator ( ) ) <EOL> C1 = self . add ( '<STR_LIT>' , sellar . Discipline1 ( ) ) <EOL> C2 = self . add ( '<STR_LIT>' , sellar . Discipline2 ( ) ) <EOL> self . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> C1 . z1 = C2 . z1 = <NUM_LIT> <EOL> C1 . z2 = C2 . z2 = <NUM_LIT:0> <EOL> C1 . x1 = <NUM_LIT:0> <EOL> self . driver . max_iteration = <NUM_LIT:5> <EOL> self . driver . tolerance = <NUM_LIT> <EOL> self . driver . print_convergence = False <EOL> class SellarMDFwithDerivs ( Assembly ) : <EOL> """<STR_LIT>""" <EOL> def configure ( self ) : <EOL> """<STR_LIT>""" <EOL> self . add ( '<STR_LIT>' , FixedPointIterator ( ) ) <EOL> C1 = self . add ( '<STR_LIT>' , sellar . Discipline1_WithDerivatives ( ) ) <EOL> C2 = self . add ( '<STR_LIT>' , sellar . Discipline2_WithDerivatives ( ) ) <EOL> self . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> C1 . z1 = C2 . z1 = <NUM_LIT> <EOL> C1 . z2 = C2 . z2 = <NUM_LIT:0> <EOL> C1 . x1 = <NUM_LIT:0> <EOL> self . driver . max_iteration = <NUM_LIT:5> <EOL> self . driver . tolerance = <NUM_LIT> <EOL> self . driver . print_convergence = False <EOL> class MPITests1 ( MPITestCase ) : <EOL> N_PROCS = <NUM_LIT:2> <EOL> def test_sellar_params1 ( self ) : <EOL> top = set_as_top ( SellarMDF ( ) ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> expected = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> top . run ( ) <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> for name , expval in expected . items ( ) : <EOL> val = top . get ( name ) <EOL> assert_rel_error ( self , val , expval , <NUM_LIT> ) <EOL> def test_sellar_params2 ( self ) : <EOL> top = set_as_top ( SellarMDF ( ) ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> expected = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> top . run ( ) <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> for name , expval in expected . items ( ) : <EOL> val = top . get ( name ) <EOL> assert_rel_error ( self , val , expval , <NUM_LIT> ) <EOL> def test_simple_opaque ( self ) : <EOL> size = <NUM_LIT:5> <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( '<STR_LIT>' , SimpleDriver ( ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . C1 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . run ( ) <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> self . assertTrue ( all ( top . C2 . a == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C2 . b == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C2 . c == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C2 . d == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> def test_fan_in ( self ) : <EOL> size = <NUM_LIT:5> <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . C1 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . run ( ) <EOL> self . assertTrue ( all ( top . C3 . a == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . b == np . ones ( size , float ) * - <NUM_LIT:1.> ) ) <EOL> self . assertTrue ( all ( top . C3 . c == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . d == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> def test_fan_in_simpledriver ( self ) : <EOL> size = <NUM_LIT:5> <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( '<STR_LIT>' , SimpleDriver ( ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . C1 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT:1000> , high = <NUM_LIT:1000> ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT:1000> , high = <NUM_LIT:1000> ) <EOL> top . driver . add_objective ( '<STR_LIT>' ) <EOL> top . run ( ) <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> self . assertTrue ( all ( top . C3 . a == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . b == np . ones ( size , float ) * - <NUM_LIT:1.> ) ) <EOL> self . assertTrue ( all ( top . C3 . c == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . d == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> def test_fan_in_simpledriver_noderiv ( self ) : <EOL> size = <NUM_LIT:5> <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( '<STR_LIT>' , NoDerivSimpleDriver ( ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . C1 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT:1000> , high = <NUM_LIT:1000> ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT:1000> , high = <NUM_LIT:1000> ) <EOL> top . driver . add_objective ( '<STR_LIT>' ) <EOL> top . run ( ) <EOL> self . assertTrue ( all ( top . C3 . a == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . b == np . ones ( size , float ) * - <NUM_LIT:1.> ) ) <EOL> self . assertTrue ( all ( top . C3 . c == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . d == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> def test_fan_in_simpledriver_setting_params ( self ) : <EOL> size = <NUM_LIT:5> <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( '<STR_LIT>' , NoDerivSimpleDriverSetter ( ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . C1 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT:1000> , high = <NUM_LIT:1000> ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT:1000> , high = <NUM_LIT:1000> ) <EOL> top . driver . add_objective ( '<STR_LIT>' ) <EOL> top . driver . vals = [ - <NUM_LIT:1.> , - <NUM_LIT:1.> , - <NUM_LIT:1.> , - <NUM_LIT:1.> , - <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> top . run ( ) <EOL> self . assertTrue ( all ( top . C3 . a == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . b == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . c == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . d == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> def test_fan_out_in ( self ) : <EOL> size = <NUM_LIT:5> <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . C1 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . run ( ) <EOL> with MPIContext ( ) : <EOL> self . assertTrue ( all ( top . C4 . a == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C4 . b == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> system = top . driver . workflow . _system <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> else : <EOL> self . assertFalse ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) != system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) != system . is_variable_local ( '<STR_LIT>' ) ) <EOL> def test_fan_out_in_force_serial ( self ) : <EOL> size = <NUM_LIT:5> <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . C1 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . driver . system_type = '<STR_LIT>' <EOL> top . run ( ) <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> self . assertTrue ( all ( top . C4 . a == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C4 . b == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> def test_serial_under_par ( self ) : <EOL> class MyDriver ( SimpleDriver ) : <EOL> implements ( ISolver ) <EOL> def execute ( self ) : <EOL> uvec = self . _system . vec [ '<STR_LIT:u>' ] <EOL> for num in [ <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> ] : <EOL> if '<STR_LIT>' in uvec : <EOL> uvec [ '<STR_LIT>' ] = num <EOL> if '<STR_LIT>' in uvec : <EOL> uvec [ '<STR_LIT>' ] = num <EOL> self . run_iteration ( ) <EOL> def requires_derivs ( self ) : <EOL> return False <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( '<STR_LIT>' , MyDriver ( ) ) <EOL> top . add ( '<STR_LIT>' , ExecComp ( [ '<STR_LIT>' ] ) ) <EOL> top . add ( '<STR_LIT>' , ExecComp ( [ '<STR_LIT>' ] ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT:100> , high = <NUM_LIT:100> ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT:100> , high = <NUM_LIT:100> ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> top . run ( ) <EOL> self . assertTrue ( top . comp1 . x == <NUM_LIT> ) <EOL> self . assertTrue ( top . comp2 . x == <NUM_LIT> ) <EOL> class MPITests2 ( MPITestCase ) : <EOL> N_PROCS = <NUM_LIT:2> <EOL> def test_sellar_cyclic ( self ) : <EOL> top = set_as_top ( SellarMDF ( ) ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> expected = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> top . run ( ) <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> for name , expval in expected . items ( ) : <EOL> val = top . get ( name ) <EOL> assert_rel_error ( self , val , expval , <NUM_LIT> ) <EOL> def test_sellar_parallel ( self ) : <EOL> top = set_as_top ( SellarMDF ( ) ) <EOL> top . driver . max_iteration = <NUM_LIT> <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> expected = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> top . run ( ) <EOL> dist_answers = top . _system . mpi . comm . gather ( [ ( k [ <NUM_LIT:0> ] , v ) for k , v in top . _system . vec [ '<STR_LIT:u>' ] . items ( ) ] , <EOL> root = <NUM_LIT:0> ) <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> for answers in dist_answers : <EOL> for name , val in answers : <EOL> if name in expected : <EOL> assert_rel_error ( self , val [ <NUM_LIT:0> ] , expected [ name ] , <NUM_LIT> ) <EOL> del expected [ name ] <EOL> if expected : <EOL> self . fail ( "<STR_LIT>" % expected . keys ( ) ) <EOL> system = top . driver . workflow . _system <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> else : <EOL> self . assertFalse ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) != system . is_variable_local ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( system . is_variable_local ( '<STR_LIT>' ) != system . is_variable_local ( '<STR_LIT>' ) ) <EOL> def test_sellar_Newton_parallel ( self ) : <EOL> top = set_as_top ( SellarMDFwithDerivs ( ) ) <EOL> top . replace ( '<STR_LIT>' , NewtonSolver ( ) ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> expected = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> top . driver . iprint = <NUM_LIT:0> <EOL> top . driver . max_iteration = <NUM_LIT:20> <EOL> top . run ( ) <EOL> dist_answers = top . _system . mpi . comm . gather ( [ ( k [ <NUM_LIT:0> ] , v ) for k , v in top . _system . vec [ '<STR_LIT:u>' ] . items ( ) ] , <EOL> root = <NUM_LIT:0> ) <EOL> if self . comm . rank == <NUM_LIT:0> : <EOL> for answers in dist_answers : <EOL> for name , val in answers : <EOL> if name in expected : <EOL> assert_rel_error ( self , val [ <NUM_LIT:0> ] , expected [ name ] , <NUM_LIT> ) <EOL> del expected [ name ] <EOL> if expected : <EOL> self . fail ( "<STR_LIT>" ) <EOL> class MPITests3 ( MPITestCase ) : <EOL> N_PROCS = <NUM_LIT:3> <EOL> def test_fan_out_in_noflats ( self ) : <EOL> size = <NUM_LIT:5> <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . C1 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . in_string = '<STR_LIT:foo>' <EOL> top . C1 . in_list = [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> top . run ( ) <EOL> self . assertTrue ( all ( top . C5 . a == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C5 . b == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertEqual ( top . C5 . out_string , '<STR_LIT>' ) <EOL> self . assertEqual ( top . C5 . out_list , [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> class TestCaseSerial ( TestCase ) : <EOL> def test_sellar_p_serial ( self ) : <EOL> top = set_as_top ( SellarMDF ( ) ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> expected = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> top . run ( ) <EOL> for name , expval in expected . items ( ) : <EOL> val = top . get ( name ) <EOL> assert_rel_error ( self , val , expval , <NUM_LIT> ) <EOL> def test_fan_in_simpledriver ( self ) : <EOL> size = <NUM_LIT:5> <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( '<STR_LIT>' , NoDerivSimpleDriver ( ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . add ( "<STR_LIT>" , ABCDArrayComp ( size ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . connect ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> top . C1 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C1 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . a = np . ones ( size , float ) * <NUM_LIT> <EOL> top . C2 . b = np . ones ( size , float ) * <NUM_LIT> <EOL> top . driver . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT:1000> , high = <NUM_LIT:1000> ) <EOL> top . driver . add_objective ( '<STR_LIT>' ) <EOL> top . run ( ) <EOL> self . assertTrue ( all ( top . C3 . a == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . b == np . ones ( size , float ) * - <NUM_LIT:1.> ) ) <EOL> self . assertTrue ( all ( top . C3 . c == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> self . assertTrue ( all ( top . C3 . d == np . ones ( size , float ) * <NUM_LIT> ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from openmdao . test . mpiunittest import mpirun_tests <EOL> mpirun_tests ( ) </s>
