slurm_manager
SLURM job manager with queued sbatch submission and direct srun fallback.
This module accepts scheduler-ready run manifests and sweep-summary payloads,
writes per-run batch scripts, submits them to Slurm, and refreshes status from
squeue/sacct.
SlurmJobManager
Bases: MADABaseJobManager
Slurm job manager that supports queued sbatch and direct srun execution.
Attributes:
| Name | Type | Description |
|---|---|---|
aggregate_manifest_fields |
Accepted aggregate manifest reference fields. |
|
per_run_manifest_fields |
Accepted per-run manifest reference fields. |
|
job_sets |
Dict[str, SlurmJobSetRecord]
|
Local MADA job set ID to Slurm job set metadata mapping. |
sbatch_available |
Whether |
|
srun_available |
Whether |
|
squeue_available |
Whether |
|
sacct_available |
Whether |
Methods:
| Name | Description |
|---|---|
submit_jobs |
Submit generated run manifests through |
get_job_status |
Refresh and return tracked Slurm job status. |
continuously_check_job_status |
Poll Slurm status until a bounded wait condition is met. |
run_command |
Execute one command through |
list_queue |
Return current |
get_cluster_info |
Return current |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
112 113 114 115 116 117 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 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 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 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 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 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
continuously_check_job_status(job_set_id=None, slurm_job_id=None, *, wait_until='terminal', poll_interval_seconds=10.0, timeout_seconds=3600.0)
Poll Slurm job status until a bounded wait condition is met.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_set_id
|
Optional[str]
|
Job set ID to monitor. If not provided, monitors all tracked job sets. |
None
|
slurm_job_id
|
Optional[str]
|
Real Slurm job ID to monitor. Mutually exclusive with |
None
|
wait_until
|
str
|
|
'terminal'
|
poll_interval_seconds
|
float
|
Seconds between status checks. |
10.0
|
timeout_seconds
|
float
|
Maximum seconds to wait before returning. |
3600.0
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple of (success, JSON containing polling metadata plus the last status response). |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
execute()
The Slurm backend does not support scheduler-side staging/execute flow.
Returns:
| Type | Description |
|---|---|
None
|
Generator yielding error message. |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
get_cluster_info()
Get information about the cluster nodes using sinfo.
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
A tuple of (success, status message). |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
get_job_status(job_set_id=None, slurm_job_id=None)
Return scheduler-backed status for one job set, one Slurm job, or all job sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_set_id
|
Optional[str]
|
Local job set ID to query. |
None
|
slurm_job_id
|
Optional[str]
|
Slurm job ID to query directly. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple of (success, JSON string containing job status information). |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
list_queue()
List all jobs in the SLURM queue using squeue.
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
A tuple of (success, status message). |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
stage(dims, num_samples, lower_bounds, upper_bounds, output_dir, parameter_file)
Staging is handled by simulation servers, not the scheduler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dims
|
int
|
Number of parameter dimensions. |
required |
num_samples
|
int
|
Number of parameter sets to generate. |
required |
lower_bounds
|
List[float]
|
Lower bounds for each dimension. |
required |
upper_bounds
|
List[float]
|
Upper bounds for each dimension. |
required |
output_dir
|
str
|
Directory for output files. |
required |
parameter_file
|
str
|
Name of parameter file. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple of (False, error_message) since staging is not supported. |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
submit_command(command, nodes, tasks, working_directory=None)
Submit one ad hoc command using srun.
Use this for running a single known command, not for generated run manifests
or parameter sweeps. For batch simulation runs, use submit_jobs instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
Command to execute |
required |
nodes
|
int
|
Number of nodes (default: 1) |
required |
tasks
|
int
|
Number of tasks (default: 1) |
required |
working_directory
|
Optional[str]
|
Working directory for the command (optional) |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple of (success, command output and status) |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
submit_jobs(run_info_json, *, blocking=False, nodes=1, tasks=1, time_limit='01:00:00', account=None, partition=None, exclusive=False, cpus_per_task=None, job_name_prefix='mada')
Submit batch jobs from a run manifest file or JSON string.
This is the primary method for submitting generated simulation runs. It accepts run manifests in multiple formats: inline JSON with {"runs": [...]}, a bare list like run_instances.json, or a file path to either format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_info_json
|
str
|
JSON string, list, or file path (e.g., "run_instances.json"). |
required |
blocking
|
bool
|
If False (default), submit to queue via sbatch and return immediately. If True, use direct execution for small debugging runs (not for production). |
False
|
nodes
|
int
|
Number of nodes per job. |
1
|
tasks
|
int
|
Number of tasks per job. |
1
|
time_limit
|
str
|
Time limit string (e.g., "01:00:00"). |
'01:00:00'
|
account
|
Optional[str]
|
Slurm account name. |
None
|
partition
|
Optional[str]
|
Slurm partition name. |
None
|
exclusive
|
bool
|
Whether to request exclusive node access. |
False
|
cpus_per_task
|
Optional[int]
|
Number of CPUs per task. |
None
|
job_name_prefix
|
str
|
Prefix for job names. |
'mada'
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple of (success, payload) where payload is JSON submission summary. |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
submit_jobs_async(run_info_json, *, nodes=1, tasks=1, time_limit='01:00:00', account=None, partition=None, exclusive=False, cpus_per_task=None, job_name_prefix='mada')
Submit each run as a queued Slurm batch job and return immediately.
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
SlurmJobRecord
dataclass
One tracked run submitted through the Slurm backend.
Attributes:
| Name | Type | Description |
|---|---|---|
local_job_id |
str
|
Local MADA tracking ID. |
run_id |
str
|
Run identifier from the scheduler manifest. |
run_location |
str
|
Working directory for the run. |
status |
str
|
Normalized job status. |
stdout_path |
str
|
Path to the run stdout log. |
stderr_path |
str
|
Path to the run stderr log. |
slurm_job_id |
Optional[str]
|
Real Slurm job ID when submitted through |
script_path |
Optional[str]
|
Generated batch script path for queued jobs. |
raw_state |
Optional[str]
|
Raw Slurm job state from scheduler query. |
exit_code |
Optional[int]
|
Job exit code if completed. |
error_message |
Optional[str]
|
Error message if submission or execution failed. |
submitted_at |
Optional[float]
|
Timestamp when job was submitted. |
started_at |
Optional[float]
|
Timestamp when job started running. |
ended_at |
Optional[float]
|
Timestamp when job finished. |
Methods:
| Name | Description |
|---|---|
to_dict |
Return a JSON-serializable job record. |
Source code in src/mada_tools/scheduler/slurm/slurm_manager.py
to_dict()
Return a JSON-serializable representation of the job record.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing all job record fields. |
SlurmJobSetRecord
dataclass
One tracked collection of runs submitted together.
Attributes:
| Name | Type | Description |
|---|---|---|
job_set_id |
str
|
Local MADA tracking ID for the submitted collection. |
submission_mode |
str
|
Execution mode, such as queued |
total_runs |
int
|
Number of runs in the collection. |
requested_resources |
Dict[str, Any]
|
Scheduler resource request used for submission. |
submitted_at |
float
|
Submission timestamp. |
jobs |
list[SlurmJobRecord]
|
Per-run job records. |
max_parallel |
Optional[int]
|
Direct execution concurrency limit, if applicable. |
error |
Optional[str]
|
Collection-level error message, if any. |