<s> """<STR_LIT>""" <EOL> from unittest import TestCase <EOL> import numpy as np <EOL> from openmdao . lib . drivers . api import SLSQPdriver , COBYLAdriver , CONMINdriver <EOL> from openmdao . main . api import Component , Assembly , set_as_top <EOL> from openmdao . main . datatypes . api import Float <EOL> from openmdao . test . mpiunittest import MPITestCase <EOL> from openmdao . util . testutil import assert_rel_error <EOL> class Parab1 ( Component ) : <EOL> """<STR_LIT>""" <EOL> x = Float ( <NUM_LIT:0.0> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' ) <EOL> y = Float ( <NUM_LIT:0.0> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' ) <EOL> f_xy = Float ( iotype = '<STR_LIT>' , desc = '<STR_LIT>' ) <EOL> def execute ( self ) : <EOL> """<STR_LIT>""" <EOL> x = self . x <EOL> y = self . y <EOL> self . f_xy = ( x - <NUM_LIT> ) ** <NUM_LIT:2> + ( y + <NUM_LIT> ) ** <NUM_LIT:2> <EOL> def provideJ ( self ) : <EOL> """<STR_LIT>""" <EOL> df_dx = <NUM_LIT> * self . x - <NUM_LIT> <EOL> df_dy = <NUM_LIT> * self . y + <NUM_LIT> <EOL> return np . array ( [ [ df_dx , df_dy ] ] ) <EOL> def list_deriv_vars ( self ) : <EOL> input_keys = ( '<STR_LIT:x>' , '<STR_LIT:y>' ) <EOL> output_keys = ( '<STR_LIT>' , ) <EOL> return input_keys , output_keys <EOL> class Parab2 ( Component ) : <EOL> """<STR_LIT>""" <EOL> x = Float ( <NUM_LIT:0.0> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' ) <EOL> y = Float ( <NUM_LIT:0.0> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' ) <EOL> f_xy = Float ( iotype = '<STR_LIT>' , desc = '<STR_LIT>' ) <EOL> def execute ( self ) : <EOL> """<STR_LIT>""" <EOL> x = self . x <EOL> y = self . y <EOL> self . f_xy = x * y - <NUM_LIT> <EOL> def provideJ ( self ) : <EOL> """<STR_LIT>""" <EOL> df_dx = self . y <EOL> df_dy = self . x <EOL> return np . array ( [ [ df_dx , df_dy ] ] ) <EOL> def list_deriv_vars ( self ) : <EOL> input_keys = ( '<STR_LIT:x>' , '<STR_LIT:y>' ) <EOL> output_keys = ( '<STR_LIT>' , ) <EOL> return input_keys , output_keys <EOL> class MPITests1 ( MPITestCase ) : <EOL> N_PROCS = <NUM_LIT:2> <EOL> def test_SLSQP ( self ) : <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( '<STR_LIT>' , Parab1 ( ) ) <EOL> top . add ( '<STR_LIT>' , Parab2 ( ) ) <EOL> top . add ( '<STR_LIT>' , SLSQPdriver ( ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . driver . add_parameter ( [ '<STR_LIT>' , '<STR_LIT>' ] , low = - <NUM_LIT:100> , high = <NUM_LIT:100> ) <EOL> top . driver . add_parameter ( [ '<STR_LIT>' , '<STR_LIT>' ] , low = - <NUM_LIT:100> , high = <NUM_LIT:100> ) <EOL> top . driver . add_objective ( '<STR_LIT>' ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> top . run ( ) <EOL> assert_rel_error ( self , top . parab1 . x , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , top . parab1 . y , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , top . _pseudo_0 . out0 , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_COBYLA ( self ) : <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( '<STR_LIT>' , Parab1 ( ) ) <EOL> top . add ( '<STR_LIT>' , Parab2 ( ) ) <EOL> top . add ( '<STR_LIT>' , COBYLAdriver ( ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . driver . add_parameter ( [ '<STR_LIT>' , '<STR_LIT>' ] , low = - <NUM_LIT:100> , high = <NUM_LIT:100> ) <EOL> top . driver . add_parameter ( [ '<STR_LIT>' , '<STR_LIT>' ] , low = - <NUM_LIT:100> , high = <NUM_LIT:100> ) <EOL> top . driver . add_objective ( '<STR_LIT>' ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> top . run ( ) <EOL> assert_rel_error ( self , top . parab1 . x , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , top . parab1 . y , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , top . _pseudo_0 . out0 , - <NUM_LIT> , <NUM_LIT> ) <EOL> def test_CONMIN ( self ) : <EOL> top = set_as_top ( Assembly ( ) ) <EOL> top . add ( '<STR_LIT>' , Parab1 ( ) ) <EOL> top . add ( '<STR_LIT>' , Parab2 ( ) ) <EOL> top . add ( '<STR_LIT>' , CONMINdriver ( ) ) <EOL> top . driver . workflow . add ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> top . driver . add_parameter ( [ '<STR_LIT>' , '<STR_LIT>' ] , low = - <NUM_LIT:100> , high = <NUM_LIT:100> ) <EOL> top . driver . add_parameter ( [ '<STR_LIT>' , '<STR_LIT>' ] , low = - <NUM_LIT:100> , high = <NUM_LIT:100> ) <EOL> top . driver . add_objective ( '<STR_LIT>' ) <EOL> top . driver . add_constraint ( '<STR_LIT>' ) <EOL> top . run ( ) <EOL> assert_rel_error ( self , top . parab1 . x , <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , top . parab1 . y , - <NUM_LIT> , <NUM_LIT> ) <EOL> assert_rel_error ( self , top . _pseudo_0 . out0 , - <NUM_LIT> , <NUM_LIT> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from openmdao . test . mpiunittest import mpirun_tests <EOL> mpirun_tests ( ) </s>
