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

Make full use of dependency #159

Merged
merged 2 commits into from
Mar 1, 2025
Merged
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
32 changes: 30 additions & 2 deletions utilix/batchq.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class JobSubmission(BaseModel):
None,
description="Define a list of nodes which should be excluded from submission",
)
dependency: Optional[str] = Field(
dependency: Optional[Union[int, List[int]]] = Field(
None, description="Provide list of job ids to wait for before running this job"
)
verbose: bool = Field(False, description="Print the sbatch command before submitting")
Expand Down Expand Up @@ -291,7 +291,7 @@ def check_hours_value(cls, v: Optional[float], values: Dict[Any, Any]) -> Option
raise ValueError("Hours must be between 0 and 72")
return v

@validator("node", "exclude_nodes", "dependency")
@validator("node", "exclude_nodes")
def check_node_format(
cls, v: Optional[str], values: Dict[Any, Any], field: str
) -> Optional[str]:
Expand All @@ -313,6 +313,30 @@ def check_node_format(
raise ValueError("Invalid format for node/exclude_nodes/dependency")
return v

@validator("dependency")
def check_dependency_value(cls, v: Optional[float], values: Dict[Any, Any]) -> Optional[float]:
"""Check if the dependency is int or list of int.

Args:
v (Optional[float]): The dependency to check.

Raises:
ValueError: If the dependency is neither int nor list of int.

Returns:
Optional[float]: The dependency to use.

"""
if cls._skip_validation("dependency", values):
return v
if v is None:
return v
if isinstance(v, int):
return v
if isinstance(v, list) and all(isinstance(i, int) for i in v):
return v
raise ValueError("Dependency must be int or list of int")

@validator("container")
def check_container_format(cls, v: str, values: Dict[Any, Any]) -> str:
"""Check if the container ends with .simg and if it exists.
Expand Down Expand Up @@ -486,8 +510,12 @@ def submit(self) -> Union[int, None]:
else:
print("Job submission failed.")
except Exception as e:
job_id = None
print(f"An error occurred while submitting the job: {str(e)}")

if self.dependency is not None:
print(f"Job {job_id} will wait for job ids: {self.dependency}")

return job_id


Expand Down