def bcmd_proc(beta, n, params, queue, do_perturb, obj): # create the input file seq = obj.baseSeq[:] seq += steps.abcParamSequence(obj.initnames, params) seq += steps.makeSteadySequence(True) seq += steps.abcAbsoluteSequence(obj.times, obj.perturb(do_perturb), obj.vars, outhead=False) input = os.path.join(obj.workdir, '%s_%d_%d.input' % (obj.name, n, beta)) steps.writeSequence(seq, input) output = os.path.join(obj.workdir, '%s_%d_%d.out' % (obj.name, n, beta)) if obj.suppress: # invoke the model succ = abortable.call([obj.program, '-i', input, '-o', output], stdout=obj.DEVNULL, stderr=obj.DEVNULL, timeout=obj.timeout) else: # create files to hold log values stdoutname = os.path.join(obj.workdir, '%s_%d_%d.stdout' % (obj.name, n, beta)) stderrname = os.path.join(obj.workdir, '%s_%d_%d.stderr' % (obj.name, n, beta)) try: f_out = open(stdoutname, 'w') except IOError: f_out = None try: f_err = open(stderrname, 'w') except IOError: f_err = None # invoke the model succ = abortable.call([obj.program, '-i', input, '-o', output], stdout=f_out, stderr=f_err, timeout=obj.timeout) if f_out: f_out.close() if f_err: f_err.close() # read the results result = numpy.zeros([len(obj.times), obj.nspecies]) ii = 0 if succ: with open(output, 'rb') as tabfile: reader = csv.reader(tabfile, delimiter='\t') for row in reader: # first entry in each row is the RADAU5 return code result[ii, :] = [float(x) for x in row[1:]] ii += 1 else: result[:] = float('nan') # send them back to the master process queue.put({'n': n, 'data': result})
def bcmd_proc (beta, n, params, queue, do_perturb, obj): # create the input file seq = obj.baseSeq[:] seq += steps.abcParamSequence(obj.initnames, params) seq += steps.makeSteadySequence(True) seq += steps.abcAbsoluteSequence(obj.times, obj.perturb(do_perturb), obj.vars, outhead=False) input = os.path.join(obj.workdir, '%s_%d_%d.input' % (obj.name, n, beta)) steps.writeSequence(seq, input) output = os.path.join(obj.workdir, '%s_%d_%d.out' % (obj.name, n, beta)) if obj.suppress: # invoke the model succ = abortable.call([obj.program, '-i', input, '-o', output], stdout=obj.DEVNULL, stderr=obj.DEVNULL, timeout=obj.timeout ) else: # create files to hold log values stdoutname = os.path.join(obj.workdir, '%s_%d_%d.stdout' % (obj.name, n, beta)) stderrname = os.path.join(obj.workdir, '%s_%d_%d.stderr' % (obj.name, n, beta)) try: f_out = open(stdoutname, 'w') except IOError: f_out = None try: f_err = open(stderrname, 'w') except IOError: f_err = None # invoke the model succ = abortable.call([obj.program, '-i', input, '-o', output], stdout=f_out, stderr=f_err, timeout=obj.timeout ) if f_out: f_out.close() if f_err: f_err.close() # read the results result = numpy.zeros([len(obj.times), obj.nspecies]) ii = 0 if succ: with open(output, 'rb') as tabfile: reader = csv.reader(tabfile, delimiter='\t') for row in reader: # first entry in each row is the RADAU5 return code result[ii, :] = [float(x) for x in row[1:]] ii += 1 else: result[:] = float('nan') # send them back to the master process queue.put({'n': n, 'data': result})
def run(self, id_beta, id_n, input): outname = os.path.join(self.workdir, '%s_%d_%d.out' % (self.name, id_n, id_beta)) if self.suppress: # invoke the model program as a subprocess succ = abortable.call([self.program, '-i', input, '-o', outname], stdout=self.DEVNULL, stderr=self.DEVNULL, timeout=self.timeout) else: stdoutname = os.path.join( self.workdir, '%s_%d_%d.stdout' % (self.name, id_n, id_beta)) stderrname = os.path.join( self.workdir, '%s_%d_%d.stderr' % (self.name, id_n, id_beta)) # if opening these files fails, we may be in trouble anyway # but don't peg out just because of this -- let the the failure happen somewhere more important try: f_out = open(stdoutname, 'w') except IOError: f_out = None try: f_err = open(stderrname, 'w') except IOError: f_err = None # invoke the model program as a subprocess succ = abortable.call([self.program, '-i', input, '-o', outname], stdout=f_out, stderr=f_err, timeout=self.timeout) if f_out: f_out.close() if f_err: f_err.close() return outname
def run(self, id_beta, id_n, input): outname = os.path.join(self.workdir, '%s_%d_%d.out' % (self.name, id_n, id_beta)) if self.suppress: # invoke the model program as a subprocess succ = abortable.call([self.program, '-i', input, '-o', outname], stdout=self.DEVNULL, stderr=self.DEVNULL, timeout=self.timeout ) else: stdoutname = os.path.join(self.workdir, '%s_%d_%d.stdout' % (self.name, id_n, id_beta)) stderrname = os.path.join(self.workdir, '%s_%d_%d.stderr' % (self.name, id_n, id_beta)) # if opening these files fails, we may be in trouble anyway # but don't peg out just because of this -- let the the failure happen somewhere more important try: f_out = open(stdoutname, 'w') except IOError: f_out = None try: f_err = open(stderrname, 'w') except IOError: f_err = None # invoke the model program as a subprocess succ = abortable.call([self.program, '-i', input, '-o', outname], stdout=f_out, stderr=f_err, timeout=self.timeout ) if f_out: f_out.close() if f_err: f_err.close() return outname