mockslurm.mock_sbatch
Implement a mock of the sbatch command of slurm.
The implementation mimics the sbatch API, while using subprocess to start the processes on the host machine without slurm daemons.
Double fork is used to detach the subprocess, allowing the sbatch mock to return while the created process is still running.
Classes:
| Name | Description |
|---|---|
DependencyActions |
Scheduler behaviour with respect to job dependencies. |
Functions:
| Name | Description |
|---|---|
check_dependency |
Check if a job's dependency are satisfied. |
launch_job |
Run |
parse_dependency |
Parse a job's dependency specification string in sbatch format. |
DependencyActions
Bases: Enum
flowchart TD
mockslurm.mock_sbatch.DependencyActions[DependencyActions]
click mockslurm.mock_sbatch.DependencyActions href "" "mockslurm.mock_sbatch.DependencyActions"
Scheduler behaviour with respect to job dependencies.
Source code in src/mockslurm/mock_sbatch.py
check_dependency
Check if a job's dependency are satisfied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_dependency
|
Tuple[bool, List[Dict[str, List[int]]]]
|
Job dependencies. Each tuple in the list corresponds to a dependency specification.
See |
required |
Warning
This function only supports the "afterok" dependency specification, anything else causes
a NotImplementedError to be raised.
Raise
NotImplementedError If the dependency type is not "afterok"
Returns:
| Type | Description |
|---|---|
DependencyActions
|
The action to follow based on the dependency evaluation, for instance to wait, to start job, etc. |
Source code in src/mockslurm/mock_sbatch.py
launch_job
Run cmd as a detached subprocess.
The return code of cmd is retrieved by the detached subprocess and updated in the DB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
Command to run, similar to the content of the --wrap= argument of sbatch |
required |
stdout
|
str
|
Path to a file where the output of |
required |
stderr
|
str
|
Path to a file where the errors of |
required |
job_idx
|
int
|
Index of the job in the DB |
required |
job_dependency
|
List[Tuple[bool, Dict[str, List[int]]]]
|
Job dependencies. Each tuple in the list corresponds to a dependency specification.
See |
required |
Source code in src/mockslurm/mock_sbatch.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
parse_dependency
Parse a job's dependency specification string in sbatch format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_dependency
|
str
|
sbatch job's dependency string. Examples: afterok:20:21,afterany:23 |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, List[Dict[str, List[int]]]]
|
Tuple 1st element is whether all dependencies must be satisfied for a job to start (True, "," in slurm str), or if a single dependency is enough (False, "?" in slurm str). When a single dependency is present: True. The list values are dictionaries with a single key been the dependency type ("afterok", "afterany", etc.) and the values been the job IDs for these dependency |
Example
parse_dependency("afterok:20:21?afterany:23") (False, [{'afterok': [20, 21]}, {'afterany': [23]}])