コード例 #1
0
    def call_Builder(self, num_simulations):
        myBuilder = Builder(doReaction, [
            num_simulations, self.simulation_time, self.reaction_type,
            self.dataset_type, self.strands_list, self.sodium, self.magnesium,
            self.kinetic_parameters_simulation, self.bimolecular_reaction,
            self.temperature, self.temperature_change,
            self.join_concentration_change, self.join_concentration,
            rate_method, self.use_initialfinalfrompathway, self.startStates
        ])
        start_time = timeit.default_timer()
        if self.num_simulations > 0:
            myBuilder.genAndSavePathsFile(
                supplyInitialState=self.startStates[0])
            builderpath = self.dataset_path + "/" + myenums.Permanent_Folder.MYBUILDER.value + "/" + myenums.Permanent_Folder.MYBUILDER.value + str(
                self.docID)
            lenp = len(myBuilder.protoSpace)
            start = 0
            myBuilder.protoSpacebackup = copy.deepcopy(myBuilder.protoSpace)
            pathuniqueid = builderpath + myenums.EDITIONAL.UNIQUEID.value
            with open(pathuniqueid, "wb") as p:
                pickle.dump(myBuilder.uniqueID_number, p)
            pathspace = builderpath + myenums.EDITIONAL.PROTOSPACEBACKUP.value
            with open(pathspace, "wb") as p:
                pickle.dump(myBuilder.protoSpacebackup, p)
            pathsequences = builderpath + myenums.EDITIONAL.PROTOSEQUENCES.value
            with open(pathsequences, "wb") as p:
                pickle.dump(myBuilder.protoSequences, p)
            pathoptions = builderpath + myenums.EDITIONAL.PATHOPTIONS.value
            with open(pathoptions, "wb") as p:
                pickle.dump(myBuilder.optionsArgs, p)
            batchsize = 2000
            while start < lenp:
                st = timeit.default_timer()
                end = min(lenp, start + batchsize)
                print "progress ", str(end), " / ", str(lenp), self.docID

                # There was some memory leak issues when I used the fattenStateSpace function in builder.py, so  I added fatten helper to avoid the memory issues by saving intermediate results, restarting Multistrand, and restoring the intermediate results
                command = [
                    "python", "fattenhelper.py",
                    str(start),
                    str(end), builderpath, pathspace, pathsequences,
                    pathoptions, pathuniqueid
                ]
                shell = call(command)
                ft = timeit.default_timer()
                #print "making fatten state space time" , ft-st
                del shell
                with open(
                        builderpath + myenums.EDITIONAL.TEMPSTATESPACE.value +
                        str(start) + "-" + str(end), "rb") as p:
                    tempstatespace = pickle.load(p)
                with open(
                        builderpath + myenums.EDITIONAL.TEMPTRANSITIONS.value +
                        str(start) + "-" + str(end), "rb") as p:
                    temptransitions = pickle.load(p)
                os.remove(builderpath +
                          myenums.EDITIONAL.TEMPSTATESPACE.value + str(start) +
                          "-" + str(end))
                os.remove(builderpath +
                          myenums.EDITIONAL.TEMPTRANSITIONS.value +
                          str(start) + "-" + str(end))
                myBuilder.mergeSet(myBuilder.protoSpace, tempstatespace)
                myBuilder.mergeSet(myBuilder.protoTransitions_FPEI,
                                   temptransitions)
                start = end
                with open(pathuniqueid, "rb") as p:
                    myBuilder.uniqueID_number = pickle.load(p)
            os.remove(pathuniqueid)
            os.remove(pathspace)
            os.remove(pathsequences)
            os.remove(pathoptions)
            del myBuilder.protoSpacebackup
            del myBuilder.uniqueID_number
            print "Statistics: ", "statespace: ", len(
                myBuilder.protoSpace), "finalstates: ", len(
                    myBuilder.protoFinalStates), "initialstates: ", len(
                        myBuilder.protoInitialStates)

        return myBuilder
コード例 #2
0
pathuniqueid = sys.argv[7]

mytime = open("times_log_remove.txt", "a")
mytime.write(pathbuilder + "   start " + str(start) + "end " + str(end) + "\n")
st = time.time()

with open(pathoptions, "rb") as p:
    optionsArg = pickle.load(p)

myBuilder = Builder(parent.doReaction, optionsArg)

with open(pathspace, "rb") as p:
    myBuilder.protoSpacebackup = pickle.load(p)

with open(pathuniqueid, "rb") as p:
    myBuilder.uniqueID_number = pickle.load(p)

with open(pathsequences, "rb") as p:
    myBuilder.protoSequences = pickle.load(p)

mytime.write("load time " + str(time.time() - st) + "\n")

st = time.time()
myBuilder.fattenStateSpace(start=int(start), end=int(end))

mytime.write("fatten time time " + str(time.time() - st) + "\n")

st = time.time()

with open(pathuniqueid, "wb") as p:
    pickle.dump(myBuilder.uniqueID_number, p)