Пример #1
0
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})
Пример #2
0
 def writeInput(self, id_beta, id_n, params, do_perturb=True):
     seq = self.baseSeq[:]
     
     names = self.initnames + self.fixnames
     vals = numpy.concatenate((params, self.fixvals))
     
     seq += steps.abcParamSequence(names, vals)
     seq += steps.abcAbsoluteSequence(self.times, self.perturb(do_perturb), self.vars, outhead=False, steady=self.steady)
     
     filename = os.path.join(self.workdir, '%s_%d_%d.input' % (self.name, id_n, id_beta))
     steps.writeSequence(seq, filename)
     
     return filename
Пример #3
0
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})
Пример #4
0
    def writeInput(self, id_beta, id_n, params, do_perturb=True):
        seq = self.baseSeq[:]

        names = self.initnames + self.fixnames
        vals = numpy.concatenate((params, self.fixvals))

        seq += steps.abcParamSequence(names, vals)
        seq += steps.abcAbsoluteSequence(self.times,
                                         self.perturb(do_perturb),
                                         self.vars,
                                         outhead=False,
                                         steady=self.steady)

        filename = os.path.join(self.workdir,
                                '%s_%d_%d.input' % (self.name, id_n, id_beta))
        steps.writeSequence(seq, filename)

        return filename