Skip to content

Commit

Permalink
Merge pull request #343 from pyiron/abstract
Browse files Browse the repository at this point in the history
Define interface in QueueAdapterAbstractClass
  • Loading branch information
jan-janssen authored Sep 28, 2024
2 parents 886864f + fd84a44 commit 043358c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
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])
"""
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.base.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

0 comments on commit 043358c

Please sign in to comment.