Skip to content

Commit

Permalink
Add submission_script_path to write run_queue.sh script to a differen…
Browse files Browse the repository at this point in the history
…t location
  • Loading branch information
jan-janssen committed Nov 15, 2024
1 parent 40d00a5 commit 805c533
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pysqa/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]:
"""
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions pysqa/queueadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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.
Expand All @@ -228,6 +231,7 @@ def submit_job(
dependency_list=dependency_list,
command=command,
submission_template=submission_template,
submission_script_path=submission_script_path,
**kwargs,
)

Expand Down

0 comments on commit 805c533

Please sign in to comment.