SLURM API Reference
This page provides API reference documentation for the SLURM module, which contains functions and classes for managing batch simulations on SLURM-based HPC clusters.
Utility Functions
bmtool.SLURM.check_job_status(job_id)
Checks the status of a SLURM job using scontrol.
Args: job_id (str): The SLURM job ID.
Returns: str: The state of the job.
Source code in bmtool/SLURM.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
bmtool.SLURM.submit_job(script_path)
Submits a SLURM job script.
Args: script_path (str): The path to the SLURM job script.
Returns: str: The job ID of the submitted job.
Raises: Exception: If there is an error in submitting the job.
Source code in bmtool/SLURM.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
bmtool.SLURM.send_teams_message(webhook, message)
Sends a message to a teams channel or chat
Args: webhook (str): A microsoft teams webhook message (str): A message to send in the chat/channel
Source code in bmtool/SLURM.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
Parameter Sweep Classes
bmtool.SLURM.seedSweep
Source code in bmtool/SLURM.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
__init__(json_file_path, param_name)
Initializes the seedSweep instance.
Args: json_file_path (str): Path to the JSON file to be updated. param_name (str): The name of the parameter to be modified.
Source code in bmtool/SLURM.py
85 86 87 88 89 90 91 92 93 94 |
|
edit_json(new_value)
Updates the JSON file with a new parameter value.
Args: new_value: The new value for the parameter.
Source code in bmtool/SLURM.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
change_json_file_path(new_json_file_path)
Source code in bmtool/SLURM.py
113 114 |
|
bmtool.SLURM.multiSeedSweep
Bases: seedSweep
MultSeedSweeps are centered around some base JSON cell file. When that base JSON is updated, the other JSONs change according to their ratio with the base JSON.
Source code in bmtool/SLURM.py
118 119 120 121 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 |
|
__init__(base_json_file_path, param_name, syn_dict, base_ratio=1)
Initializes the multipleSeedSweep instance.
Args: base_json_file_path (str): File path for the base JSON file. param_name (str): The name of the parameter to be modified. syn_dict_list (list): A list containing dictionaries with the 'json_file_path' and 'ratio' (in comparison to the base_json) for each JSON file. base_ratio (float): The ratio between the other JSONs; usually the current value for the parameter.
Source code in bmtool/SLURM.py
123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
edit_all_jsons(new_value)
Updates the base JSON file with a new parameter value and then updates the other JSON files based on the ratio.
Args: new_value: The new value for the parameter in the base JSON.
Source code in bmtool/SLURM.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
Simulation Block Management
bmtool.SLURM.SimulationBlock
Source code in bmtool/SLURM.py
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
__init__(block_name, time, partition, nodes, ntasks, mem, simulation_cases, output_base_dir, account=None, additional_commands=None, status_list=['COMPLETED', 'FAILED', 'CANCELLED'], component_path=None)
Initializes the SimulationBlock instance.
Args: block_name (str): Name of the block. time (str): Time limit for the job. partition (str): Partition to submit the job to. nodes (int): Number of nodes to request. ntasks (int): Number of tasks. mem (int) : Number of gigabytes (per node) simulation_cases (dict): Dictionary of simulation cases with their commands. output_base_dir (str): Base directory for the output files. account (str) : account to charge on HPC additional commands (list): commands to run before bmtk model starts useful for loading modules status_list (list): List of things to check before running next block. Adding RUNNING runs blocks faster but uses MUCH more resources and is only recommended on large HPC
Source code in bmtool/SLURM.py
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 |
|
create_batch_script(case_name, command)
Creates a SLURM batch script for the given simulation case.
Args: case_name (str): Name of the simulation case. command (str): Command to run the simulation.
Returns: str: Path to the batch script file.
Source code in bmtool/SLURM.py
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
submit_block()
Submits all simulation cases in the block as separate SLURM jobs.
Source code in bmtool/SLURM.py
244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
check_block_status()
Checks the status of all jobs in the block.
Returns: bool: True if all jobs in the block are completed, False otherwise.
Source code in bmtool/SLURM.py
258 259 260 261 262 263 264 265 266 267 268 269 |
|
check_block_completed()
checks if all the jobs in the block have been completed by slurm
Returns: bool: True if all block jobs have been ran, false if job is still running
Source code in bmtool/SLURM.py
271 272 273 274 275 276 277 278 279 280 281 282 |
|
check_block_running()
checks if a job is running
Returns: bool: True if jobs are RUNNING false if anything else
Source code in bmtool/SLURM.py
284 285 286 287 288 289 290 291 292 293 294 |
|
check_block_submited()
checks if a job is running
Returns: bool: True if jobs are RUNNING false if anything else
Source code in bmtool/SLURM.py
296 297 298 299 300 301 302 303 304 305 306 |
|
File Transfer
bmtool.SLURM.get_relative_path(endpoint, absolute_path)
Convert absolute path to relative path for Globus transfer.
Source code in bmtool/SLURM.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
bmtool.SLURM.globus_transfer(source_endpoint, dest_endpoint, source_path, dest_path)
Transfers file using custom globus transfer function. For more info see https://github.com/GregGlickert/transfer-files/blob/main/globus_transfer.sh work in progress still... kinda forgot about this
Source code in bmtool/SLURM.py
333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
BlockRunner
bmtool.SLURM.BlockRunner
Class to handle submitting multiple blocks sequentially.
Attributes: blocks (list): List of SimulationBlock instances to be run. json_editor (seedSweep or multiSweep): Instance of seedSweep to edit JSON file. param_values (list): List of values for the parameter to be modified. webhook (str): a microsoft webhook for teams. When used will send teams messages to the hook!
Source code in bmtool/SLURM.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
|
__init__(blocks, json_editor=None, json_file_path=None, param_name=None, param_values=None, check_interval=60, syn_dict=None, webhook=None)
Source code in bmtool/SLURM.py
360 361 362 363 364 365 366 367 368 369 370 |
|
submit_blocks_sequentially()
Submits all blocks sequentially, ensuring each block starts only after the previous block has completed or is running. Updates the JSON file with new parameters before each block run.
Source code in bmtool/SLURM.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
|
submit_blocks_parallel()
submits all the blocks at once onto the queue. To do this the components dir will be cloned and each block will have its own. Also the json_file_path should be the path after the components dir
Source code in bmtool/SLURM.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
|