def handle_eval(self, record):
# This gives a file name / directory name that no other thread can use
my_unique_filename = my_gen.next_filename()
my_unique_filename = str(my_unique_filename) + ".txt"
# Print to the input file
f = open(my_unique_filename, 'w')
f.write(array2str(record.params[0]))
f.close()
# Run the objective function and pass the filename of the input file
self.process = Popen(['./sphere_ext_files', my_unique_filename], stdout=PIPE)
out = self.process.communicate()[0]
# Parse the output
try:
val = float(out) # This raises ValueError if out is not a float
self.finish_success(record, val)
os.remove(my_unique_filename) # Remove input file
except ValueError:
logging.warning("Function evaluation crashed/failed")
self.finish_failure(record)
os.remove(my_unique_filename) # Remove input file
评论列表
文章目录