Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define interface in QueueAdapterAbstractClass #343

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions pysqa/base/abstract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from abc import ABC, abstractmethod
from typing import List, Optional, Union

import pandas
from jinja2 import Template


class QueueAdapterAbstractClass(ABC):
@abstractmethod
def submit_job(
self,
queue: Optional[str] = None,
job_name: Optional[str] = None,
working_directory: Optional[str] = None,
cores: Optional[int] = None,
memory_max: Optional[int] = None,
run_time_max: Optional[int] = None,
dependency_list: Optional[List[str]] = None,
command: Optional[str] = None,
submission_template: Optional[Union[str, Template]] = None,
**kwargs,
) -> Union[int, None]:
pass

@abstractmethod
def enable_reservation(self, process_id: int):
pass

@abstractmethod
def delete_job(self, process_id: int) -> Union[str, None]:
pass

@abstractmethod
def get_queue_status(self, user: Optional[str] = None) -> pandas.DataFrame:
"""
Get the status of the queue.

Args:
user (str): The user to filter the queue status for.

Returns:
pandas.DataFrame: The queue status.
"""
pass

@abstractmethod
def get_status_of_my_jobs(self) -> pandas.DataFrame:
"""
Get the status of the user's jobs.

Returns:
pandas.DataFrame: The status of the user's jobs.
"""
pass

@abstractmethod
def get_status_of_job(self, process_id: int) -> Union[str, None]:
"""
Get the status of a job.

Args:
process_id (int): The process ID.

Returns:
str: The status of the job.results_lst.append(df_selected.values[0])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the incorrect docstring in get_status_of_job method.

The Returns section of the docstring includes an unintended code snippet. It currently reads:

str: The status of the job.results_lst.append(df_selected.values[0])

This should be corrected to:

-                str: The status of the job.results_lst.append(df_selected.values[0])
+                str: The status of the job.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
str: The status of the job.results_lst.append(df_selected.values[0])
str: The status of the job.

"""
pass

@abstractmethod
def get_status_of_jobs(self, process_id_lst: List[int]) -> List[str]:
"""
Get the status of multiple jobs.

Args:
process_id_lst (list[int]): List of process IDs.

Returns:
list[str]: List of job statuses.
"""
pass
3 changes: 2 additions & 1 deletion pysqa/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pandas
from jinja2 import Template

from pysqa.base.abstract import QueueAdapterAbstractClass
from pysqa.wrapper.abstract import SchedulerCommands

queue_type_dict = {
Expand Down Expand Up @@ -111,7 +112,7 @@ def get_queue_commands(queue_type: str) -> Union[SchedulerCommands, None]:
)


class QueueAdapterCore(object):
class QueueAdapterCore(QueueAdapterAbstractClass):
"""
The goal of the QueueAdapter class is to make submitting to a queue system as easy as starting another sub process
locally.
Expand Down
6 changes: 5 additions & 1 deletion pysqa/queueadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from typing import List, Optional, Tuple, Union

import pandas
from jinja2 import Template

from pysqa.base.abstract import QueueAdapterAbstractClass
from pysqa.base.config import QueueAdapterWithConfig, read_config
from pysqa.base.core import execute_command
from pysqa.ext.modular import ModularQueueAdapter


class QueueAdapter(object):
class QueueAdapter(QueueAdapterAbstractClass):
"""
The goal of the QueueAdapter class is to make submitting to a queue system as easy as starting another sub process
locally.
Expand Down Expand Up @@ -164,6 +166,7 @@ def submit_job(
run_time_max: Optional[int] = None,
dependency_list: Optional[List[str]] = None,
command: Optional[str] = None,
submission_template: Optional[Union[str, Template]] = None,
**kwargs,
) -> int:
"""
Expand Down Expand Up @@ -194,6 +197,7 @@ def submit_job(
run_time_max=run_time_max,
dependency_list=dependency_list,
command=command,
submission_template=submission_template,
**kwargs,
)

Expand Down
Loading