def runLocal(self, data): ''' Run a PyURDME run using local compute recources. ''' self.user_data.set_selected(0) ##### pymodel = self.construct_pyurdme_model(data) ##### simulation_algorithm = data[ 'algorithm'] # Don't trust this! I haven't implemented the algorithm selection for this yet simulation_realizations = data['realizations'] # If the seed is negative, this means choose a seed >= 0 randomly if int(data['seed']) < 0: random.seed() data['seed'] = random.randint(0, 2147483647) simulation_seed = data['seed'] ##### path = os.path.abspath(os.path.dirname(__file__)) basedir = path + '/../' dataDir = tempfile.mkdtemp(dir=basedir + 'output') job = SpatialJobWrapper() job.user_id = self.user.user_id() job.startTime = time.strftime("%Y-%m-%d-%H-%M-%S") job.name = data["jobName"] job.indata = json.dumps(data) job.outData = dataDir job.modelName = pymodel.name job.resource = "local" job.status = "Running" model_file_pkl = "{0}/model_file.pkl".format(dataDir) result_dir = "{0}/results/".format(dataDir) os.makedirs(result_dir) # searilize the model and write it to a file in the data dir with open(model_file_pkl, 'w') as fd: pickle.dump(pymodel, fd) cmd = "{0}/../../pyurdme/pyurdme_wrapper.py {1} {2} {3} {4} {5}".format( path, model_file_pkl, result_dir, simulation_algorithm, simulation_realizations, simulation_seed) logging.info("cmd =\n{}".format(cmd)) exstring = '{0}/backend/wrapper.py {1}/stdout.log {1}/stderr.log {1}/return_code {2}'.format( basedir, dataDir, cmd) handle = subprocess.Popen(exstring, shell=True, preexec_fn=os.setsid) job.pid = int(handle.pid) job.put() return job
def runLocal(self, data): ''' Run a PyURDME run using local compute recources. ''' self.user_data.set_selected(0) ##### pymodel = self.construct_pyurdme_model(data) ##### simulation_algorithm = data['algorithm'] # Don't trust this! I haven't implemented the algorithm selection for this yet simulation_realizations = data['realizations'] # If the seed is negative, this means choose a seed >= 0 randomly if int(data['seed']) < 0: random.seed() data['seed'] = random.randint(0, 2147483647) simulation_seed = data['seed'] ##### path = os.path.abspath(os.path.dirname(__file__)) basedir = path + '/../' dataDir = tempfile.mkdtemp(dir = basedir + 'output') job = SpatialJobWrapper() job.user_id = self.user.user_id() job.startTime = time.strftime("%Y-%m-%d-%H-%M-%S") job.name = data["jobName"] job.indata = json.dumps(data) job.outData = dataDir job.modelName = pymodel.name job.resource = "local" job.status = "Running" model_file_pkl = "{0}/model_file.pkl".format(dataDir) result_dir = "{0}/results/".format(dataDir) os.makedirs(result_dir) # searilize the model and write it to a file in the data dir with open(model_file_pkl, 'w') as fd: pickle.dump(pymodel, fd) cmd = "{0}/../../pyurdme/pyurdme_wrapper.py {1} {2} {3} {4} {5}".format(path, model_file_pkl, result_dir, simulation_algorithm, simulation_realizations, simulation_seed) logging.info("cmd =\n{}".format(cmd)) exstring = '{0}/backend/wrapper.py {1}/stdout.log {1}/stderr.log {1}/return_code {2}'.format(basedir, dataDir, cmd) handle = subprocess.Popen(exstring, shell=True, preexec_fn=os.setsid) job.pid = int(handle.pid) job.put() return job