<s> """<STR_LIT>""" <EOL> __all__ = [ '<STR_LIT>' ] <EOL> from numpy import zeros , ones , putmask <EOL> from numpy import int as numpy_int <EOL> from openmdao . main . datatypes . api import Array , Float , Int , Bool <EOL> from openmdao . main . exceptions import RunStopped <EOL> from openmdao . main . hasparameters import HasParameters <EOL> from openmdao . main . hasconstraints import HasIneqConstraints <EOL> from openmdao . main . hasobjective import HasObjective <EOL> from openmdao . main . driver_uses_derivatives import Driver <EOL> from openmdao . util . decorators import add_delegate <EOL> from openmdao . main . interfaces import IHasParameters , IHasIneqConstraints , IHasObjective , implements , IOptimizer <EOL> import newsumt . newsumtinterruptible as newsumtinterruptible <EOL> def user_function ( info , x , obj , dobj , ddobj , g , dg , n2 , n3 , n4 , imode , driver ) : <EOL> """<STR_LIT>""" <EOL> if info in [ <NUM_LIT:1> , <NUM_LIT:2> ] : <EOL> if imode == <NUM_LIT:1> : <EOL> driver . set_parameters ( x ) <EOL> super ( NEWSUMTdriver , driver ) . run_iteration ( ) <EOL> else : <EOL> driver . set_parameters ( x ) <EOL> super ( NEWSUMTdriver , driver ) . run_iteration ( ) <EOL> if info == <NUM_LIT:1> : <EOL> obj = driver . eval_objective ( ) <EOL> if info == <NUM_LIT:2> : <EOL> for i , v in enumerate ( driver . eval_ineq_constraints ( driver . parent ) ) : <EOL> g [ i ] = - v <EOL> if imode != <NUM_LIT:1> : <EOL> driver . constraint_vals = g <EOL> elif info == <NUM_LIT:3> : <EOL> if driver . newsumt_diff : <EOL> return obj , dobj , ddobj , g , dg <EOL> msg = "<STR_LIT>" <EOL> raise NotImplementedError ( msg ) <EOL> elif info in [ <NUM_LIT:4> , <NUM_LIT:5> ] : <EOL> if info == <NUM_LIT:5> : <EOL> if driver . newsumt_diff : <EOL> return obj , dobj , ddobj , g , dg <EOL> raise RuntimeError ( "<STR_LIT>" % info ) <EOL> return obj , dobj , ddobj , g , dg <EOL> class _contrl ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . clear ( ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . c = <NUM_LIT:0.0> <EOL> self . epsgsn = <NUM_LIT:0.0> <EOL> self . epsodm = <NUM_LIT:0.0> <EOL> self . epsrsf = <NUM_LIT:0.0> <EOL> self . fdch = <NUM_LIT:0.0> <EOL> self . g0 = <NUM_LIT:0.0> <EOL> self . ifd = <NUM_LIT:0> <EOL> self . iflapp = <NUM_LIT:0> <EOL> self . iprint = <NUM_LIT:0> <EOL> self . jsigng = <NUM_LIT:0> <EOL> self . lobj = <NUM_LIT:0> <EOL> self . maxgsn = <NUM_LIT:0> <EOL> self . maxodm = <NUM_LIT:0> <EOL> self . maxrsf = <NUM_LIT:0> <EOL> self . mflag = <NUM_LIT:0> <EOL> self . ndv = <NUM_LIT:0> <EOL> self . ntce = <NUM_LIT:0> <EOL> self . p = <NUM_LIT:0.0> <EOL> self . ra = <NUM_LIT:0.0> <EOL> self . racut = <NUM_LIT:0.0> <EOL> self . ramin = <NUM_LIT:0.0> <EOL> self . stepmx = <NUM_LIT:0.0> <EOL> self . tftn = <NUM_LIT:0.0> <EOL> class _countr ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . clear ( ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . iobjct = <NUM_LIT:0> <EOL> self . iobapr = <NUM_LIT:0> <EOL> self . iobgrd = <NUM_LIT:0> <EOL> self . iconst = <NUM_LIT:0> <EOL> self . icongr = <NUM_LIT:0> <EOL> self . inlcgr = <NUM_LIT:0> <EOL> self . icgapr = <NUM_LIT:0> <EOL> @ add_delegate ( HasParameters , HasIneqConstraints , HasObjective ) <EOL> class NEWSUMTdriver ( Driver ) : <EOL> """<STR_LIT>""" <EOL> implements ( IHasParameters , IHasIneqConstraints , IHasObjective , IOptimizer ) <EOL> itmax = Int ( <NUM_LIT:10> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> default_fd_stepsize = Float ( <NUM_LIT> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ilin = Array ( dtype = numpy_int , default_value = zeros ( <NUM_LIT:0> , '<STR_LIT>' ) , iotype = '<STR_LIT>' , <EOL> desc = '<STR_LIT>' ) <EOL> epsgsn = Float ( <NUM_LIT> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> epsodm = Float ( <NUM_LIT> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> epsrsf = Float ( <NUM_LIT> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> g0 = Float ( <NUM_LIT:0.1> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ra = Float ( <NUM_LIT:1.0> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' ) <EOL> racut = Float ( <NUM_LIT:0.1> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ramin = Float ( <NUM_LIT> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> stepmx = Float ( <NUM_LIT> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> iprint = Int ( <NUM_LIT:0> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , high = <NUM_LIT:4> , low = <NUM_LIT:0> ) <EOL> lobj = Int ( <NUM_LIT:0> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' ) <EOL> maxgsn = Int ( <NUM_LIT:20> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> maxodm = Int ( <NUM_LIT:6> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> maxrsf = Int ( <NUM_LIT:15> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> mflag = Int ( <NUM_LIT:0> , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> newsumt_diff = Bool ( True , iotype = '<STR_LIT>' , desc = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def __init__ ( self ) : <EOL> super ( NEWSUMTdriver , self ) . __init__ ( ) <EOL> self . iter_count = <NUM_LIT:0> <EOL> self . contrl = _contrl ( ) <EOL> self . countr = _countr ( ) <EOL> self . design_vals = zeros ( <NUM_LIT:0> , '<STR_LIT:d>' ) <EOL> self . constraint_vals = [ ] <EOL> self . __design_vals_tmp = zeros ( <NUM_LIT:0> , '<STR_LIT:d>' ) <EOL> self . _ddobj = zeros ( <NUM_LIT:0> ) <EOL> self . _dg = zeros ( <NUM_LIT:0> ) <EOL> self . _dh = zeros ( <NUM_LIT:0> ) <EOL> self . _dobj = zeros ( <NUM_LIT:0> ) <EOL> self . _g = zeros ( <NUM_LIT:0> ) <EOL> self . _gb = zeros ( <NUM_LIT:0> ) <EOL> self . _g1 = zeros ( <NUM_LIT:0> ) <EOL> self . _g2 = zeros ( <NUM_LIT:0> ) <EOL> self . _g3 = zeros ( <NUM_LIT:0> ) <EOL> self . _s = zeros ( <NUM_LIT:0> ) <EOL> self . _sn = zeros ( <NUM_LIT:0> ) <EOL> self . _x = zeros ( <NUM_LIT:0> ) <EOL> self . _iik = zeros ( <NUM_LIT:0> , dtype = int ) <EOL> self . _ilin = zeros ( <NUM_LIT:0> , dtype = int ) <EOL> self . _lower_bounds = zeros ( <NUM_LIT:0> ) <EOL> self . _upper_bounds = zeros ( <NUM_LIT:0> ) <EOL> self . _iside = zeros ( <NUM_LIT:0> ) <EOL> self . fdcv = zeros ( <NUM_LIT:0> ) <EOL> self . n1 = self . n2 = self . n3 = self . n4 = <NUM_LIT:0> <EOL> self . _obj = <NUM_LIT:0.0> <EOL> self . _objmin = <NUM_LIT:0.0> <EOL> self . isdone = False <EOL> self . resume = False <EOL> def check_config ( self , strict = False ) : <EOL> """<STR_LIT>""" <EOL> super ( NEWSUMTdriver , self ) . check_config ( strict = strict ) <EOL> if self . newsumt_diff is False : <EOL> msg = "<STR_LIT>" <EOL> raise NotImplementedError ( msg ) <EOL> def start_iteration ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( NEWSUMTdriver , self ) . run_iteration ( ) <EOL> self . _config_newsumt ( ) <EOL> self . iter_count = <NUM_LIT:0> <EOL> self . design_vals = self . eval_parameters ( self . parent ) <EOL> self . __design_vals_tmp = self . design_vals . copy ( ) <EOL> self . isdone = False <EOL> self . resume = False <EOL> def continue_iteration ( self ) : <EOL> """<STR_LIT>""" <EOL> return not self . isdone and self . iter_count < self . itmax <EOL> def pre_iteration ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( NEWSUMTdriver , self ) . pre_iteration ( ) <EOL> if self . _stop : <EOL> self . raise_exception ( '<STR_LIT>' , RunStopped ) <EOL> def run_iteration ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _load_common_blocks ( ) <EOL> try : <EOL> ( fmin , self . _obj , self . _objmin , self . design_vals , <EOL> self . __design_vals_tmp , self . isdone , self . resume ) = newsumtinterruptible . newsuminterruptible ( user_function , <EOL> self . _lower_bounds , self . _upper_bounds , <EOL> self . _ddobj , self . _dg , self . _dh , self . _dobj , <EOL> self . fdcv , self . _g , <EOL> self . _gb , self . _g1 , self . _g2 , self . _g3 , <EOL> self . _obj , self . _objmin , <EOL> self . _s , self . _sn , self . design_vals , self . __design_vals_tmp , <EOL> self . _iik , self . _ilin , self . _iside , <EOL> self . n1 , self . n2 , self . n3 , self . n4 , <EOL> self . isdone , self . resume , analys_extra_args = ( self , ) ) <EOL> except Exception as err : <EOL> self . _logger . error ( str ( err ) ) <EOL> raise <EOL> self . _save_common_blocks ( ) <EOL> self . iter_count += <NUM_LIT:1> <EOL> if not self . continue_iteration ( ) : <EOL> self . set_parameters ( self . design_vals ) <EOL> super ( NEWSUMTdriver , self ) . run_iteration ( ) <EOL> def _config_newsumt ( self ) : <EOL> """<STR_LIT>""" <EOL> ndv = self . total_parameters ( ) <EOL> if ndv < <NUM_LIT:1> : <EOL> self . raise_exception ( '<STR_LIT>' , RuntimeError ) <EOL> self . _lower_bounds = self . get_lower_bounds ( ) <EOL> self . _upper_bounds = self . get_upper_bounds ( ) <EOL> self . _iside = ones ( ndv ) * <NUM_LIT:3> <EOL> self . fdcv = ones ( ndv ) * self . default_fd_stepsize <EOL> fd_steps = self . get_fd_steps ( dtype = None ) <EOL> putmask ( self . fdcv , fd_steps , fd_steps ) <EOL> if self . newsumt_diff : <EOL> ifd = - <NUM_LIT:4> <EOL> else : <EOL> ifd = <NUM_LIT:0> <EOL> self . n1 = ndv <EOL> ncon = self . total_ineq_constraints ( ) <EOL> if ncon > <NUM_LIT:0> : <EOL> self . n2 = ncon <EOL> else : <EOL> self . n2 = <NUM_LIT:1> <EOL> self . n3 = ( ndv * ( ndv + <NUM_LIT:1> ) ) / <NUM_LIT:2> <EOL> if ncon > <NUM_LIT:0> : <EOL> self . n4 = ndv * ncon <EOL> else : <EOL> self . n4 = <NUM_LIT:1> <EOL> self . design_vals = zeros ( ndv ) <EOL> self . constraint_vals = zeros ( ncon ) <EOL> if len ( self . ilin ) == <NUM_LIT:0> : <EOL> if ncon > <NUM_LIT:0> : <EOL> self . ilin = zeros ( ncon , dtype = int ) <EOL> self . _ilin = self . ilin <EOL> else : <EOL> self . _ilin = zeros ( <NUM_LIT:1> , dtype = int ) <EOL> elif len ( self . ilin ) != ncon : <EOL> msg = "<STR_LIT>" "<STR_LIT>" <EOL> self . raise_exception ( msg , RuntimeError ) <EOL> else : <EOL> self . _ilin = self . ilin <EOL> self . countr . clear ( ) <EOL> self . contrl . clear ( ) <EOL> self . contrl . c = <NUM_LIT> <EOL> self . contrl . epsgsn = self . epsgsn <EOL> self . contrl . epsodm = self . epsodm <EOL> self . contrl . epsrsf = self . epsrsf <EOL> self . contrl . fdch = <NUM_LIT> <EOL> self . contrl . g0 = self . g0 <EOL> self . contrl . ifd = ifd <EOL> self . contrl . iflapp = <NUM_LIT:0> <EOL> self . contrl . jprint = self . iprint - <NUM_LIT:1> <EOL> self . contrl . jsigng = <NUM_LIT:1> <EOL> self . contrl . lobj = self . lobj <EOL> self . contrl . maxgsn = self . maxgsn <EOL> self . contrl . maxodm = self . maxodm <EOL> self . contrl . maxrsf = self . maxrsf <EOL> self . contrl . mflag = self . mflag <EOL> self . contrl . ndv = ndv <EOL> self . contrl . ntce = ncon <EOL> self . contrl . p = <NUM_LIT:0.5> <EOL> self . contrl . ra = self . ra <EOL> self . contrl . racut = self . racut <EOL> self . contrl . ramin = self . ramin <EOL> self . contrl . stepmx = self . stepmx <EOL> self . contrl . tftn = <NUM_LIT:0.0> <EOL> self . __design_vals_tmp = zeros ( self . n1 , '<STR_LIT:d>' ) <EOL> self . _ddobj = zeros ( self . n3 ) <EOL> self . _dg = zeros ( self . n4 ) <EOL> self . _dh = zeros ( self . n1 ) <EOL> self . _dobj = zeros ( self . n1 ) <EOL> self . _g = zeros ( self . n2 ) <EOL> self . _gb = zeros ( self . n2 ) <EOL> self . _g1 = zeros ( self . n2 ) <EOL> self . _g2 = zeros ( self . n2 ) <EOL> self . _g3 = zeros ( self . n2 ) <EOL> self . _s = zeros ( self . n1 ) <EOL> self . _sn = zeros ( self . n1 ) <EOL> self . _iik = zeros ( self . n1 , dtype = int ) <EOL> def _load_common_blocks ( self ) : <EOL> """<STR_LIT>""" <EOL> for name , value in self . contrl . __dict__ . items ( ) : <EOL> setattr ( newsumtinterruptible . contrl , name , value ) <EOL> for name , value in self . countr . __dict__ . items ( ) : <EOL> setattr ( newsumtinterruptible . countr , name , value ) <EOL> def _save_common_blocks ( self ) : <EOL> """<STR_LIT>""" <EOL> common = self . contrl <EOL> for name , value in common . __dict__ . items ( ) : <EOL> setattr ( common , name , <EOL> type ( value ) ( getattr ( newsumtinterruptible . contrl , name ) ) ) <EOL> common = self . countr <EOL> for name , value in common . __dict__ . items ( ) : <EOL> setattr ( common , name , <EOL> type ( value ) ( getattr ( newsumtinterruptible . countr , name ) ) ) <EOL> def requires_derivs ( self ) : <EOL> return True </s>
