#NEWLINE# def run( self , desired_result , input , limit ) : #NEWLINE# #INDENT# limit = min ( limit , self . args . upper_limit ) #NEWLINE# with tempfile . NamedTemporaryFile ( suffix = '.petabricks.cfg' ) as cfgtmp : #NEWLINE# #INDENT# for ( k , v ) in self . build_config ( desired_result . configuration . data ) . items ( ) : #NEWLINE# #INDENT# ( ( print >> cfgtmp ) , k , '=' , v ) #NEWLINE# #UNINDENT# cfgtmp . flush ( ) #NEWLINE# if args . program_input : #NEWLINE# #INDENT# input_opts = [ ( '--iogen-run=' + args . program_input ) , ( '--iogen-n=%d' % input . input_class . size ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# input_opts = [ ( '-n=%d' % input . input_class . size ) ] #NEWLINE# #UNINDENT# cmd = ( [ args . program , '--time' , '--accuracy' , ( '--max-sec=%.8f' % limit ) , ( '--config=' + cfgtmp . name ) ] + input_opts ) #NEWLINE# log . debug ( 'cmd: %s' , ' ' . join ( cmd ) ) #NEWLINE# p = subprocess . Popen ( cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) #NEWLINE# ( out , err ) = p . communicate ( ) #NEWLINE# #UNINDENT# result = opentuner . resultsdb . models . Result ( ) #NEWLINE# try : #NEWLINE# #INDENT# root = etree . XML ( out ) #NEWLINE# result . time = float ( root . find ( 'stats/timing' ) . get ( 'average' ) ) #NEWLINE# result . accuracy = float ( root . find ( 'stats/accuracy' ) . get ( 'average' ) ) #NEWLINE# if ( result . time < ( limit + 3600 ) ) : #NEWLINE# #INDENT# result . state = 'OK' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result . state = 'TIMEOUT' #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# log . warning ( 'program crash, out = %s / err = %s' , out , err ) #NEWLINE# result . state = 'ERROR' #NEWLINE# result . time = float ( 'inf' ) #NEWLINE# result . accuracy = float ( '-inf' ) #NEWLINE# #UNINDENT# return result