diff --git a/pysqa/base/core.py b/pysqa/base/core.py index 496b293..5513026 100644 --- a/pysqa/base/core.py +++ b/pysqa/base/core.py @@ -146,6 +146,7 @@ def submit_job( dependency_list: Optional[List[str]] = None, command: Optional[str] = None, submission_template: Optional[Union[str, Template]] = None, + submission_script_path: Optional[str] = None, **kwargs, ) -> Union[int, None]: """ @@ -160,6 +161,8 @@ def submit_job( run_time_max (int/None): The maximum run time for the job. dependency_list (list[str]/None): List of job dependencies. command (str/None): The command to execute for the job. + submission_template (str/Template): Jinja2 template to write submission script. + submission_script_path (str/None): path to write the submission script to. Returns: int: The job ID. @@ -170,7 +173,7 @@ def submit_job( ) if submission_template is None: submission_template = self._submission_template - working_directory, queue_script_path = self._write_queue_script( + working_directory, submission_script_path = self._write_queue_script( queue=queue, job_name=job_name, working_directory=working_directory, @@ -180,11 +183,12 @@ def submit_job( command=command, dependency_list=dependency_list, submission_template=submission_template, + submission_script_path=submission_script_path, **kwargs, ) out = self._execute_command( commands=self._list_command_to_be_executed( - queue_script_path=queue_script_path + submission_script_path=submission_script_path ), working_directory=working_directory, split_output=False, @@ -297,17 +301,17 @@ def get_status_of_jobs(self, process_id_lst: List[int]) -> List[str]: results_lst.append("finished") return results_lst - def _list_command_to_be_executed(self, queue_script_path: str) -> list: + def _list_command_to_be_executed(self, submission_script_path: str) -> list: """ Get the list of commands to be executed. Args: - queue_script_path (str): The path to the queue script. + submission_script_path (str): The path to the queue script. Returns: list: The list of commands to be executed. """ - return self._commands.submit_job_command + [queue_script_path] + return self._commands.submit_job_command + [submission_script_path] def _execute_command( self, @@ -349,6 +353,7 @@ def _write_queue_script( run_time_max: Optional[int] = None, dependency_list: Optional[List[int]] = None, command: Optional[str] = None, + submission_script_path: Optional[str] = None, **kwargs, ) -> Tuple[str, str]: """ @@ -385,10 +390,11 @@ def _write_queue_script( ) if not os.path.exists(working_directory): os.makedirs(working_directory) - queue_script_path = os.path.join(working_directory, "run_queue.sh") - with open(queue_script_path, "w") as f: + if submission_script_path is None: + submission_script_path = os.path.join(working_directory, "run_queue.sh") + with open(submission_script_path, "w") as f: f.writelines(queue_script) - return working_directory, queue_script_path + return working_directory, submission_script_path def _job_submission_template( self, diff --git a/pysqa/queueadapter.py b/pysqa/queueadapter.py index 76bdb35..9bf1a4d 100644 --- a/pysqa/queueadapter.py +++ b/pysqa/queueadapter.py @@ -197,6 +197,7 @@ def submit_job( dependency_list: Optional[List[str]] = None, command: Optional[str] = None, submission_template: Optional[Union[str, Template]] = None, + submission_script_path: Optional[str] = None, **kwargs, ) -> int: """ @@ -212,6 +213,8 @@ def submit_job( run_time_max (int/None): Maximum runtime in seconds (optional) dependency_list(list[str]/None: Job ids of jobs to be completed before starting (optional) command (str/None): shell command to run in the job + submission_template (str/Template): Jinja2 template to write submission script. + submission_script_path (str/None): path to write the submission script to. **kwargs: allows writing additional parameters to the job submission script if they are available in the corresponding template. @@ -228,6 +231,7 @@ def submit_job( dependency_list=dependency_list, command=command, submission_template=submission_template, + submission_script_path=submission_script_path, **kwargs, )