def start_job(job_id: int) -> subprocess.Popen: job = Job.query.get_or_404(job_id) driver, series, label, config = job.driver, job.series, job.label, job.config # Create a directory for the simulation sim = Simulation(series, label) simdir = sim.simdir() try: os.mkdir(simdir) except PermissionError as e: raise e # TODO except FileExistsError as e: raise SimulationAlreadyExistsError(series, label, driver) # Put the uploaded config file there saveto = sim.config_fn() if os.path.exists(saveto): raise SimulationAlreadyExistsError(series, label, driver) with open(saveto, "w") as fp: fp.write(config) logging.info(f"Saved config file to {saveto}") # Queue the simulation executable = os.path.join(DPMDIR, driver) stdout_f = open(sim.out_fn(), "a") stderr_f = open(sim.err_fn(), "a") command = [executable, saveto, "-name", label] print(command) subp = subprocess.Popen(['echo'] + command, cwd=simdir, stdout=stdout_f, stderr=stderr_f) job.status = 1 db.session.commit() return subp
def simulation_view(sername, simname): """Serve a page showing some summary statistics of this simulation, as well as links to more details such as individual files, and logs. """ sim = Simulation(sername, simname) if not os.path.isdir(sim.simdir()): raise SimulationNotFoundError(sername, simname) simstatus = sim.status() print(simstatus) max_data_index = simstatus['dataFileCounter'] - 1 print(max_data_index) max_fstat_index = simstatus['fStatFileCounter'] - 1 return render_template('simulation.html', sername=sername, simname=simname, simstatus=simstatus, dt=simstatus['timeStep'] * simstatus['dataFileSaveCount'], mdi=max_data_index, mfi=max_fstat_index, ind=0)