def add_job_from_run_arg(self, run_arg, res_config, max_runtime, ok_cb, exit_cb): job_name = run_arg.job_name run_path = run_arg.runpath job_script = res_config.queue_config.job_script num_cpu = res_config.queue_config.num_cpu if num_cpu == 0: num_cpu = res_config.ecl_config.num_cpu job = JobQueueNode( job_script=job_script, job_name=job_name, run_path=run_path, num_cpu=num_cpu, status_file=self.status_file, ok_file=self.ok_file, exit_file=self.exit_file, done_callback_function=ok_cb, exit_callback_function=exit_cb, callback_arguments=[run_arg, res_config], max_runtime=max_runtime, ) if job is None: return run_arg._set_queue_index(self.add_job(job, run_arg.iens))
def create_queue(script, max_submit=2): driver = Driver(driver_type=QueueDriverEnum.LOCAL_DRIVER, max_running=5) job_queue = JobQueue(driver, max_submit=max_submit) with open(dummy_config["job_script"], "w") as f: f.write(script) os.chmod(dummy_config["job_script"], stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG) for i in range(10): os.mkdir(dummy_config["run_path"].format(i)) job = JobQueueNode( job_script=dummy_config["job_script"], job_name=dummy_config["job_name"].format(i), run_path=os.path.realpath(dummy_config["run_path"].format(i)), num_cpu=dummy_config["num_cpu"], status_file=job_queue.status_file, ok_file=job_queue.ok_file, exit_file=job_queue.exit_file, done_callback_function=dummy_config["ok_callback"], exit_callback_function=dummy_config["exit_callback"], callback_arguments=[ { "job_number": i }, os.path.realpath(dummy_config["run_path"].format(i)), ]) job_queue.add_job(job) return job_queue
def create_queue(): driver = Driver(driver_type=QueueDriverEnum.LOCAL_DRIVER, max_running=5) job_queue = JobQueue(driver) with open(dummy_config["job_script"], "w") as f: f.write("#!/usr/bin/env python\n"\ "with open('STATUS', 'w') as f:"\ " f.write('finished successfully')"\ "\n") os.chmod(dummy_config["job_script"], stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG) for i in range(10): os.mkdir(dummy_config["run_path"].format(i)) job = JobQueueNode( job_script=dummy_config["job_script"], job_name=dummy_config["job_name"].format(i), run_path=os.path.realpath(dummy_config["run_path"].format(i)), num_cpu=dummy_config["num_cpu"], status_file=job_queue.status_file, ok_file=job_queue.ok_file, exit_file=job_queue.exit_file, done_callback_function=dummy_config["ok_callback"], exit_callback_function=dummy_config["exit_callback"], callback_arguments=[ { "job_number": i }, os.path.realpath(dummy_config["run_path"].format(i)), ]) job_queue.add_job(job) return job_queue
def test_num_cpu_submitted_correctly(self): with TestAreaContext("job_node_test"): os.putenv("PATH", os.getcwd() + ":" + os.getenv("PATH")) driver = Driver(driver_type=QueueDriverEnum.LSF_DRIVER, max_running=1) with open(dummy_config["job_script"], "w") as f: f.write(simple_script) os.chmod(dummy_config["job_script"], stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG) with open("bsub", "w") as f: f.write(mock_bsub) os.chmod("bsub", stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG) job_id = 0 num_cpus = 4 os.mkdir(dummy_config["run_path"].format(job_id)) job = JobQueueNode( job_script=dummy_config["job_script"], job_name=dummy_config["job_name"].format(job_id), run_path=os.path.realpath( dummy_config["run_path"].format(job_id)), num_cpu=num_cpus, status_file="STATUS", ok_file="OK", exit_file="ERROR", done_callback_function=dummy_config["ok_callback"], exit_callback_function=dummy_config["exit_callback"], callback_arguments=[ { "job_number": job_id }, os.path.realpath(dummy_config["run_path"].format(job_id)), ], ) pool_sema = BoundedSemaphore(value=2) job.run(driver, pool_sema) job.stop() job.wait_for() with open("test.out") as f: bsub_argv = f.read().split() found_cpu_arg = False for arg_i, arg in enumerate(bsub_argv): if arg == "-n": self.assertEqual( bsub_argv[arg_i + 1], str(num_cpus), "num_cpu argument does not match specified number of cpus", ) found_cpu_arg = True self.assertTrue(found_cpu_arg, "num_cpu argument not found")
def add_job(self, run_arg, res_config, job_queue): job_name = run_arg.job_name run_path = run_arg.runpath job_script = res_config.queue_config.job_script num_cpu = res_config.queue_config.num_cpu if num_cpu == 0: num_cpu = res_config.ecl_config.num_cpu job = JobQueueNode(job_script=job_script, job_name=job_name, run_path=run_path, num_cpu=num_cpu, status_file=job_queue.status_file, ok_file=job_queue.ok_file, exit_file=job_queue.exit_file, done_callback_function=EnKFState.forward_model_ok_callback, exit_callback_function=EnKFState.forward_model_exit_callback, callback_arguments=[run_arg, res_config]) if job is None: return run_arg._set_queue_index(job_queue.add_job(job))
def add_ee_stage(self, stage): job = JobQueueNode( job_script=stage.get_job_script(), job_name=stage.get_job_name(), run_path=stage.get_run_path(), num_cpu=stage.get_num_cpu(), status_file=self.status_file, ok_file=self.ok_file, exit_file=self.exit_file, done_callback_function=stage.get_done_callback(), exit_callback_function=stage.get_exit_callback(), callback_arguments=stage.get_callback_arguments(), max_runtime=stage.get_max_runtime(), ) if job is None: raise ValueError("JobQueueNode constructor created None job") iens = stage.get_run_arg().iens stage.get_run_arg()._set_queue_index(self.add_job(job, iens))