Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
finally:
self.call_program('rm test')
self.call_program('rm test.cpp')
if run_result['timeout'] == True:
val = self.args.runtime_limit
else:
val = self.parse_running_time();
self.call_program('rm test.out')
print ("run result: " + str(run_result))
print ("running time: " + str(val))
if run_result['timeout'] == True:
print ("Timed out after " + str(self.args.runtime_limit) + " seconds")
return opentuner.resultsdb.models.Result(time=val)
elif run_result['returncode'] != 0:
if self.args.killed_process_report_runtime_limit == 1 and run_result['stderr'] == 'Killed\n':
print ("process killed " + str(run_result))
return opentuner.resultsdb.models.Result(time=self.args.runtime_limit)
else:
print (str(run_result))
exit()
else:
return opentuner.resultsdb.models.Result(time=val)
def run(args, cfg):
limit = args.limit
cmd = [args.program,
'--time',
'--accuracy',
'--config=' + cfg,
'--max-sec=%.10f' % args.limit,
'-n=%d' % args.n]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
result = opentuner.resultsdb.models.Result()
try:
root = etree.XML(out)
result.time = float(root.find('stats/timing').get('average'))
result.accuracy = float(root.find('stats/accuracy').get('average'))
if result.time < limit + 3600:
result.state = 'OK'
else:
# time will be 2**31 if timeout
result.state = 'TIMEOUT'
except:
log.exception('run error')
log.warning('program crash, out = %s / err = %s', out, err)
result.state = 'ERROR'
result.time = float('inf')
result.accuracy = float('-inf')
return result
if args.program_input:
input_opts = ['--iogen-run=' + args.program_input,
'--iogen-n=%d' % input.input_class.size]
else:
input_opts = ['-n=%d' % input.input_class.size]
cmd = [args.program,
'--time',
'--accuracy',
'--max-sec=%.8f' % limit,
'--config=' + cfgtmp.name] + input_opts
log.debug("cmd: %s", ' '.join(cmd))
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
result = opentuner.resultsdb.models.Result()
try:
root = etree.XML(out)
result.time = float(root.find('stats/timing').get('average'))
result.accuracy = float(root.find('stats/accuracy').get('average'))
if result.time < limit + 3600:
result.state = 'OK'
else:
#time will be 2**31 if timeout
result.state = 'TIMEOUT'
except:
log.warning("program crash, out = %s / err = %s", out, err)
result.state = 'ERROR'
result.time = float('inf')
result.accuracy = float('-inf')
return result
def stats_over_time(session,
run,
extract_fn,
combine_fn,
no_data = None):
'''
return reduce(combine_fn, map(extract_fn, data)) for each quanta of the
tuning run
'''
value_by_quanta = [ no_data ]
start_date = run.start_date
subq = (session.query(resultsdb.models.Result.id)
.filter_by(tuning_run = run, was_new_best = True, state='OK'))
q = (session.query(resultsdb.models.DesiredResult)
.join(resultsdb.models.Result)
.filter(resultsdb.models.DesiredResult.state=='COMPLETE',
resultsdb.models.DesiredResult.tuning_run == run,
resultsdb.models.DesiredResult.result_id.in_(subq.subquery()))
.order_by(resultsdb.models.DesiredResult.request_date))
first_id = None
for dr in q:
if first_id is None:
first_id = dr.id
td = (dr.request_date - start_date)
duration = td.seconds + (td.days * 24 * 3600.0)
# TODO: Make this variable configurable
def run(self, desired_result, input, limit):
cfg = desired_result.configuration.data
sequence = [cfg[i] for i in range(self.args.seq_len)
if cfg[i] < self.num_operators]
# sequence can be shorter than self.args.seq_len with null operator
if len(sequence) > 0:
accuracy = cla_func.calc_fidelity(sequence, self.op, self.Ugoal)
# ~.99 is acceptable
else:
accuracy = 0.0
return opentuner.resultsdb.models.Result(time=0.0,
accuracy=accuracy,
size=len(sequence))
def run(self, desired_result, input, limit):
self.trycount = self.trycount + 1
cfg = desired_result.configuration.data
self.niceprint(cfg)
self.sdk.sendmsg("%s\n"%cfg)
msg = self.sdk.recvmsg()
exetime = float(msg)
if exetime < 0:
print "Error in execution"
return opentuner.resultsdb.models.Result(state='ERROR', time=float('inf'))
else:
print "Execution time is %f"%exetime
return opentuner.resultsdb.models.Result(time=exetime)