# slurm_script_generator

*module*

Public package exports for :mod:`slurm_script_generator`.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/__init__.py#L1-L1)

## slurm_script_generator.Run

*class* · *dataclass*

```python
class Run
```

Re-exported from: `slurm_script_generator.runs`

One run directory of a :class:`RunSet` and where it stands.

Attributes
----------
directory : pathlib.Path
    The run directory.
task : int
    Its position in the set, counted from 1: the array task ID it is
    submitted as.
state : str
    ``'finished'``, ``'new'`` (never submitted), a SLURM state in capitals
    (``'PENDING'``, ``'RUNNING'``, ``'FAILED'``, ``'TIMEOUT'``, ...),
    ``'ended'`` (it has left the queue and accounting does not say how), or
    ``'unknown'`` (submitted, and neither ``sacct`` nor ``squeue`` is
    available to ask).
job_id : int, optional
    The array job it was last submitted with.
job_task : int, optional
    The task ID it had in that job.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L92-L138)

### slurm_script_generator.Run.directory

*attribute* · *instance attribute*

```python
directory: Path
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L115-L115)

### slurm_script_generator.Run.job_id

*attribute* · *class attribute* · *instance attribute*

```python
job_id: Optional[int] = None
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L118-L118)

### slurm_script_generator.Run.job_task

*attribute* · *class attribute* · *instance attribute*

```python
job_task: Optional[int] = None
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L119-L119)

### slurm_script_generator.Run.state

*attribute* · *class attribute* · *instance attribute*

```python
state: str = 'new'
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L117-L117)

### slurm_script_generator.Run.task

*attribute* · *instance attribute*

```python
task: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L116-L116)

### slurm_script_generator.Run.is_active

*property*

```python
is_active: bool
```

True if the run is pending or running in the queue.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L127-L129)

### slurm_script_generator.Run.is_finished

*property*

```python
is_finished: bool
```

True if the run is done.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L122-L124)

### slurm_script_generator.Run.needs_submit

*property*

```python
needs_submit: bool
```

True if the run is neither finished nor in the queue.

A run in the state ``'unknown'`` does not count: it may be in the
queue, and submitting it again could run it twice.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L132-L138)

## slurm_script_generator.RunSet

*class*

```python
class RunSet
```

Re-exported from: `slurm_script_generator.runs`

Run directories with one resource request, submitted as a job array.

Parameters
----------
directories : iterable of str or pathlib.Path
    The run directories. Their order fixes the array task ID of each
    (counted from 1), so keep it the same between calls.
script : SlurmScript
    The resource request, the modules and the commands of one run. The
    commands are executed inside the run directory. It must not set
    ``--array``.
name : str
    Name of the set: the job name unless the script has one, and the stem
    of the array script and of the output files of SLURM.
root : str or pathlib.Path, optional
    Where the array script and the output files of SLURM go. Defaults to
    the parent of the first run directory.
is_finished : callable, optional
    ``is_finished(directory) -> bool``: whether a run is done, judged from
    what it wrote. Without it a run is finished when SLURM reports its
    task as ``COMPLETED``, which needs accounting.
log_to_run_directory : bool
    Send the output of the commands to
    ``slurm-<job>_<task>.out`` in the run directory (the default) instead
    of the output file of SLURM under *root*.

Examples
--------
>>> script = SlurmScript(
...     nodes=1, ntasks_per_node=32, time="12:00:00",
...     custom_commands=["srun ./solver -i input.nml > solver.out"],
... )
>>> runs = RunSet(sorted(Path("scan").glob("case_*")), script, name="scan")
>>> runs.submit(throttle=8)  # doctest: +SKIP
4242
>>> print(runs)  # doctest: +SKIP

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L141-L433)

### slurm_script_generator.RunSet.directories

*attribute* · *instance attribute*

```python
directories = [Path(d).resolve() for d in directories]
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L189-L189)

### slurm_script_generator.RunSet.is_finished

*attribute* · *instance attribute*

```python
is_finished = is_finished
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L199-L199)

### slurm_script_generator.RunSet.log_to_run_directory

*attribute* · *instance attribute*

```python
log_to_run_directory = log_to_run_directory
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L200-L200)

### slurm_script_generator.RunSet.name

*attribute* · *instance attribute*

```python
name = name
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L197-L197)

### slurm_script_generator.RunSet.root

*attribute* · *instance attribute*

```python
root = Path(root).resolve() if root else self.directories[0].parent
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L198-L198)

### slurm_script_generator.RunSet.script

*attribute* · *instance attribute*

```python
script = script
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L196-L196)

### slurm_script_generator.RunSet.array_script

*method*

```python
def array_script(tasks: Optional[Iterable[int]] = None, throttle: Optional[int] = None) -> SlurmScript
```

Return the script that runs the given tasks as a job array.

It is the script of the set with ``--array`` added, a job name and an
output file unless the script has them, and in front of the commands
the list of all run directories and a ``cd`` into the one of the task.
The list is part of the script, which SLURM copies when the job is
submitted, so a task that starts later still finds its directory even
if the set has changed in the meantime.

Parameters
----------
tasks : iterable of int, optional
    Task IDs to run. Defaults to all.
throttle : int, optional
    Maximum number of tasks running at once.

Returns
-------
SlurmScript
    The array script.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L204-L254)

### slurm_script_generator.RunSet.cancel

*method*

```python
def cancel(verbose: bool = False) -> List[str]
```

Cancel the runs of the set that are pending or running.

Parameters
----------
verbose : bool
    Print the ``scancel`` command.

Returns
-------
list of str
    The tasks that were cancelled, as ``<job>_<task>``.

Raises
------
RuntimeError
    If ``scancel`` fails.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L383-L409)

### slurm_script_generator.RunSet.counts

*method*

```python
def counts() -> Dict[str, int]
```

Return how many runs are in each state.

Returns
-------
dict of str -> int
    For example ``{'finished': 12, 'RUNNING': 8, 'PENDING': 10}``.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L308-L319)

### slurm_script_generator.RunSet.status

*method*

```python
def status() -> List[Run]
```

Return every run of the set with its current state.

One ``sacct`` and one ``squeue`` call are made for all the jobs the
runs were submitted with (see :func:`~slurm_script_generator.squeue.task_states`).

Returns
-------
list of Run
    In the order of the directories.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L267-L306)

### slurm_script_generator.RunSet.submit

*method*

```python
def submit(throttle: Optional[int] = None, retry: bool = True, force: bool = False, verbose: bool = False) -> Optional[int]
```

Submit, as one job array, the runs that need it.

These are the runs that were never submitted and, with *retry*, those
that left the queue without finishing (failed, timed out, cancelled).
Runs that are finished, pending or running are left alone, so calling
this twice submits nothing the second time. The array script is
written to ``<root>/<name>.sh``, and each submitted run directory
gets a file ``slurm_run.json`` with the job and task ID.

Parameters
----------
throttle : int, optional
    Maximum number of tasks running at once.
retry : bool
    Also submit runs that ended without finishing. Defaults to True.
force : bool
    Submit every run that is not pending or running, finished ones and
    those in an unknown state included.
verbose : bool
    Print what ``sbatch`` answers.

Returns
-------
int or None
    The ID of the array job, or None if there was nothing to submit.

Raises
------
ValueError
    If the script holds a combination of pragmas ``sbatch`` rejects.
RuntimeError
    If ``sbatch`` fails.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/runs.py#L323-L381)

## slurm_script_generator.SAcct

*class*

```python
class SAcct
```

Re-exported from: `slurm_script_generator.squeue`

Interface to SLURM job accounting via ``sacct``.

Parameters
----------
user : str, optional
    If given, fetch only jobs for this user.
days : int
    Number of days of history to look back (default: 7).
partition : str, optional
    If given, filter to this partition.
me : bool
    If True, fetch only jobs belonging to the current OS user.
    Mutually exclusive with *user*. Defaults to False.

Examples
--------
>>> a = SAcct(user='alice', days=30)
>>> a.summary()
{'total': 42, 'completed': 30, 'failed': 5, ...}

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1476-L1633)

### slurm_script_generator.SAcct.jobs

*method*

```python
def jobs(user: Optional[str] = None, state: Optional[str] = None, partition: Optional[str] = None) -> List[SAcctJob]
```

Return accounting records matching the given criteria.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1563-L1577)

### slurm_script_generator.SAcct.jobs_by_partition

*method*

```python
def jobs_by_partition() -> Dict[str, List[SAcctJob]]
```

Return a mapping of partition -> list of jobs in that partition.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1593-L1598)

### slurm_script_generator.SAcct.jobs_by_state

*method*

```python
def jobs_by_state() -> Dict[str, List[SAcctJob]]
```

Return a mapping of state -> list of jobs in that state.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1586-L1591)

### slurm_script_generator.SAcct.jobs_by_user

*method*

```python
def jobs_by_user() -> Dict[str, List[SAcctJob]]
```

Return a mapping of username -> list of their historical jobs.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1579-L1584)

### slurm_script_generator.SAcct.refresh

*method*

```python
def refresh() -> SAcct
```

Re-run ``sacct`` and update the cached job list.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1511-L1561)

### slurm_script_generator.SAcct.summary

*method*

```python
def summary() -> dict
```

Return a summary dict of job counts and CPU usage.

Returns
-------
dict
    Keys: ``total``, ``completed``, ``failed``, ``cancelled``,
    ``timeout``, ``cpu_hours``, ``by_state``, ``users``.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1600-L1620)

## slurm_script_generator.SAcctJob

*class* · *dataclass*

```python
class SAcctJob
```

Re-exported from: `slurm_script_generator.squeue`

A single job record from SLURM accounting (``sacct``).

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1434-L1473)

### slurm_script_generator.SAcctJob.cpu_time_raw

*attribute* · *instance attribute*

```python
cpu_time_raw: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1446-L1446)

### slurm_script_generator.SAcctJob.elapsed

*attribute* · *instance attribute*

```python
elapsed: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1445-L1445)

### slurm_script_generator.SAcctJob.exit_code

*attribute* · *instance attribute*

```python
exit_code: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1447-L1447)

### slurm_script_generator.SAcctJob.job_id

*attribute* · *instance attribute*

```python
job_id: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1438-L1438)

### slurm_script_generator.SAcctJob.name

*attribute* · *instance attribute*

```python
name: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1440-L1440)

### slurm_script_generator.SAcctJob.num_cpus

*attribute* · *instance attribute*

```python
num_cpus: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1444-L1444)

### slurm_script_generator.SAcctJob.num_nodes

*attribute* · *instance attribute*

```python
num_nodes: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1443-L1443)

### slurm_script_generator.SAcctJob.partition

*attribute* · *instance attribute*

```python
partition: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1442-L1442)

### slurm_script_generator.SAcctJob.state

*attribute* · *instance attribute*

```python
state: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1441-L1441)

### slurm_script_generator.SAcctJob.user

*attribute* · *instance attribute*

```python
user: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1439-L1439)

### slurm_script_generator.SAcctJob.cpu_hours

*property*

```python
cpu_hours: float
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1450-L1451)

### slurm_script_generator.SAcctJob.is_cancelled

*property*

```python
is_cancelled: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1462-L1463)

### slurm_script_generator.SAcctJob.is_completed

*property*

```python
is_completed: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1454-L1455)

### slurm_script_generator.SAcctJob.is_failed

*property*

```python
is_failed: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1458-L1459)

### slurm_script_generator.SAcctJob.is_timeout

*property*

```python
is_timeout: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1466-L1467)

## slurm_script_generator.SQueue

*class*

```python
class SQueue
```

Re-exported from: `slurm_script_generator.squeue`

Interface to the SLURM job queue via ``squeue``.

Parameters
----------
user : str, optional
    If given, only fetch jobs belonging to this user by default.
me : bool
    If True, fetch only jobs belonging to the current OS user by default.
    Mutually exclusive with *user*. Defaults to False.

Examples
--------
>>> q = SQueue()
>>> q.summary()
{'total_jobs': 42, 'running': 30, 'pending': 12, 'users': {...}, 'by_state': {...}}

>>> q.wait_until_done(job_name='training_*')
>>> q.wait_until_done(job_id=12345)
>>> q.wait_until_done(job_id=[12345, 12346])
>>> q.wait_until_done(user='alice')

>>> q.cancel(job_id=12345)
>>> q.cancel(job_name='training_*')

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L541-L1078)

### slurm_script_generator.SQueue.cancel

*method*

```python
def cancel(job_name: Optional[str] = None, job_id: Optional[Union[int, str, List[Union[int, str]]]] = None, user: Optional[str] = None, state: Optional[str] = None, partition: Optional[str] = None, verbose: bool = True, me: bool = False) -> List[int]
```

Cancel all matching jobs with ``scancel``.

Supports glob patterns in *job_name* (``*`` and ``?`` wildcards).
At least one filter argument must be provided, so that an accidental
call cannot cancel the whole queue.

Parameters
----------
job_name : str, optional
    Job name or glob pattern, e.g. ``'train_*'``.
job_id : int, str, or list of int/str, optional
    A specific job ID, or a list of job IDs, to cancel.
user : str, optional
    Cancel all jobs belonging to this user.
me : bool
    Cancel all jobs belonging to the current OS user. Mutually
    exclusive with *user*. Defaults to False.
state : str, optional
    SLURM state code, e.g. ``'PD'`` to cancel only pending jobs.
partition : str, optional
    Partition name to filter by.
verbose : bool
    Print progress messages. Defaults to True.

Returns
-------
list of int
    The job IDs that were passed to ``scancel``.

Raises
------
ValueError
    If no filter is specified.
RuntimeError
    If ``scancel`` exits with a non-zero status.

Examples
--------
>>> q = SQueue()
>>> q.cancel(job_id=12345)
>>> q.cancel(job_name='train_*')
>>> q.cancel(user='alice', state='PD')

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L819-L909)

### slurm_script_generator.SQueue.jobs

*method*

```python
def jobs(job_name: Optional[str] = None, job_id: Optional[Union[int, str, List[Union[int, str]]]] = None, user: Optional[str] = None, state: Optional[str] = None, partition: Optional[str] = None, me: bool = False) -> List[SQueueJob]
```

Return jobs matching the given criteria.

Parameters
----------
job_name : str, optional
    Job name or glob pattern (e.g. ``'train_*'``).
job_id : int, str, or list of int/str, optional
    Exact job ID, or a list of job IDs.
user : str, optional
    Username to filter by.
state : str, optional
    SLURM state code, e.g. ``'R'`` or ``'PD'``.
partition : str, optional
    Partition name to filter by.
me : bool
    Filter to jobs belonging to the current OS user. Mutually
    exclusive with *user*. Defaults to False.

Returns
-------
list of SQueueJob

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L632-L678)

### slurm_script_generator.SQueue.jobs_by_partition

*method*

```python
def jobs_by_partition() -> Dict[str, List[SQueueJob]]
```

Return a mapping of partition name -> list of jobs in that partition.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L933-L938)

### slurm_script_generator.SQueue.jobs_by_state

*method*

```python
def jobs_by_state() -> Dict[str, List[SQueueJob]]
```

Return a mapping of state code -> list of jobs in that state.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L926-L931)

### slurm_script_generator.SQueue.jobs_by_user

*method*

```python
def jobs_by_user() -> Dict[str, List[SQueueJob]]
```

Return a mapping of username -> list of their jobs.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L919-L924)

### slurm_script_generator.SQueue.pending_jobs

*method*

```python
def pending_jobs() -> List[SQueueJob]
```

Return all jobs currently in the PD (Pending) state.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L684-L686)

### slurm_script_generator.SQueue.refresh

*method*

```python
def refresh() -> SQueue
```

Re-run ``squeue`` and update the cached job list.

Returns
-------
SQueue
    self, for chaining.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L582-L626)

### slurm_script_generator.SQueue.running_jobs

*method*

```python
def running_jobs() -> List[SQueueJob]
```

Return all jobs currently in the R (Running) state.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L680-L682)

### slurm_script_generator.SQueue.summary

*method*

```python
def summary() -> dict
```

Return a summary dict with total counts, per-user counts, and per-state counts.

Returns
-------
dict
    Keys: ``total_jobs``, ``running``, ``pending``,
    ``users`` (dict of user -> job count),
    ``by_state`` (dict of state code -> job count).

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L940-L958)

### slurm_script_generator.SQueue.users

*method*

```python
def users() -> List[str]
```

Return a sorted list of unique users with jobs in the queue.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L915-L917)

### slurm_script_generator.SQueue.wait_until_done

*method*

```python
def wait_until_done(job_name: Optional[str] = None, job_id: Optional[Union[int, str, List[Union[int, str]]]] = None, user: Optional[str] = None, poll_interval: float = 30.0, timeout: Optional[float] = None, verbose: bool = True, check: bool = False, me: bool = False) -> Dict[int, Optional[str]]
```

Block until all matching jobs leave the active queue.

Supports glob patterns in *job_name* (``*`` and ``?`` wildcards).
At least one filter argument must be provided.

Once the jobs are gone the final states are looked up with a single
``sacct`` call (see :func:`job_states`), so the caller learns whether
the jobs it waited for actually succeeded.

Parameters
----------
job_name : str, optional
    Job name or glob pattern, e.g. ``'train_*'``.
job_id : int, str, or list of int/str, optional
    A specific job ID, or a list of job IDs, to wait for.
user : str, optional
    Wait for all jobs belonging to this user to finish.
me : bool
    Wait for all jobs belonging to the current OS user. Mutually
    exclusive with *user*. Defaults to False.
poll_interval : float
    Seconds between queue polls. Defaults to 30.
timeout : float, optional
    Maximum seconds to wait before raising ``TimeoutError``.
verbose : bool
    Print progress messages. Defaults to True.
check : bool
    Raise ``RuntimeError`` if any job ended in a state from
    :data:`FAILED_JOB_STATES`. Jobs whose state is undetermined
    (None) never trigger this. Defaults to False.

Returns
-------
dict of int -> (str or None)
    Final accounting state per job ID that was waited on. A None value
    means the state could not be determined, not that the job failed.

Raises
------
ValueError
    If no filter is specified.
TimeoutError
    If *timeout* is exceeded before all jobs finish.
RuntimeError
    If *check* is True and a job ended in a failure state.

Examples
--------
>>> q.wait_until_done(job_id=12345)
{12345: 'COMPLETED'}
>>> q.wait_until_done(job_name='train_*', check=True)
{12345: 'COMPLETED', 12346: 'COMPLETED'}

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L712-L813)

## slurm_script_generator.SQueueJob

*class* · *dataclass*

```python
class SQueueJob
```

Re-exported from: `slurm_script_generator.squeue`

A single job entry from the SLURM queue.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L379-L486)

### slurm_script_generator.SQueueJob.job_id

*attribute* · *instance attribute*

```python
job_id: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L383-L383)

### slurm_script_generator.SQueueJob.name

*attribute* · *instance attribute*

```python
name: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L385-L385)

### slurm_script_generator.SQueueJob.num_cpus

*attribute* · *instance attribute*

```python
num_cpus: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L389-L389)

### slurm_script_generator.SQueueJob.num_nodes

*attribute* · *instance attribute*

```python
num_nodes: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L388-L388)

### slurm_script_generator.SQueueJob.partition

*attribute* · *instance attribute*

```python
partition: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L387-L387)

### slurm_script_generator.SQueueJob.priority

*attribute* · *instance attribute*

```python
priority: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L393-L393)

### slurm_script_generator.SQueueJob.reason

*attribute* · *instance attribute*

```python
reason: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L392-L392)

### slurm_script_generator.SQueueJob.state

*attribute* · *instance attribute*

```python
state: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L386-L386)

### slurm_script_generator.SQueueJob.submit_time

*attribute* · *class attribute* · *instance attribute*

```python
submit_time: str = ''
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L394-L394)

### slurm_script_generator.SQueueJob.time_limit

*attribute* · *instance attribute*

```python
time_limit: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L391-L391)

### slurm_script_generator.SQueueJob.time_used

*attribute* · *instance attribute*

```python
time_used: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L390-L390)

### slurm_script_generator.SQueueJob.user

*attribute* · *instance attribute*

```python
user: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L384-L384)

### slurm_script_generator.SQueueJob.is_active

*property*

```python
is_active: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L405-L406)

### slurm_script_generator.SQueueJob.is_pending

*property*

```python
is_pending: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L401-L402)

### slurm_script_generator.SQueueJob.is_running

*property*

```python
is_running: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L397-L398)

### slurm_script_generator.SQueueJob.state_name

*property*

```python
state_name: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L409-L410)

### slurm_script_generator.SQueueJob.submit_datetime

*property*

```python
submit_datetime: Optional[datetime]
```

The job's submission time, or None if squeue didn't report one.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L413-L415)

### slurm_script_generator.SQueueJob.waiting_seconds

*property*

```python
waiting_seconds: Optional[float]
```

Seconds elapsed since submission — how long a pending job has waited.

None when the submission time could not be determined.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L418-L426)

### slurm_script_generator.SQueueJob.cancel

*method*

```python
def cancel(verbose: bool = True) -> None
```

Cancel this specific job with ``scancel``.

Parameters
----------
verbose : bool
    Print a confirmation message. Defaults to True.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L471-L479)

### slurm_script_generator.SQueueJob.final_state

*method*

```python
def final_state() -> Optional[str]
```

Return this job's accounting state via ``sacct``.

See :func:`job_state`. Returns None when the state cannot be
determined; that is not evidence of failure.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L463-L469)

### slurm_script_generator.SQueueJob.wait_until_done

*method*

```python
def wait_until_done(poll_interval: float = 30.0, timeout: Optional[float] = None, verbose: bool = True, check: bool = False) -> Optional[str]
```

Block until this specific job leaves the active queue.

Parameters
----------
poll_interval : float
    Seconds between queue polls. Defaults to 30.
timeout : float, optional
    Maximum seconds to wait before raising ``TimeoutError``.
verbose : bool
    Print progress messages. Defaults to True.
check : bool
    Raise ``RuntimeError`` if the job ends in a failure state.
    Defaults to False.

Returns
-------
str or None
    The job's final accounting state, or None if undetermined.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L428-L461)

## slurm_script_generator.SlurmScript

*class*

```python
class SlurmScript
```

Re-exported from: `slurm_script_generator.slurm_script`

Class representing a Slurm batch script with pragmas, modules, and custom commands.

Parameters
----------
account : str, optional
    The account to charge for the job.
array : str, optional
    The job array specification.
begin : str, optional
    The time to begin the job.
bell : str, optional
    Ring terminal bell when job is allocated.
burst_buffer : str, optional
    Burst buffer specifications.
bb_file : str, optional
    Burst buffer specification file.
cpus_per_task : int, optional
    Number of CPUs required per task.
comment : str, optional
    Arbitrary comment for the job.
container : str, optional
    Path to OCI container bundle.
container_id : str, optional
    OCI container ID.
cpu_freq : str, optional
    Requested CPU frequency and governor.
delay_boot : str, optional
    Delay boot for desired node features.
dependency : str, optional
    Job dependency specification.
deadline : str, optional
    Remove job if no ending possible before deadline.
chdir : str, optional
    Change working directory for the job.
get_user_env : str, optional
    Used by Moab for environment setup.
gres : str, optional
    Required generic resources.
gres_flags : str, optional
    Flags related to GRES management.
hold : str, optional
    Submit job in held state.
immediate : str, optional
    Exit if resources not available within seconds.
job_name : str, optional
    Name of the job.
no_kill : str, optional
    Do not kill job on node failure.
kill_command : str, optional
    Signal to send terminating job.
licenses : str, optional
    Required licenses, comma separated.
clusters : str, optional
    Comma separated list of clusters.
distribution : str, optional
    Distribution method for processes.
mail_type : str, optional
    Notify on state change.
mail_user : str, optional
    Email for job state changes.
mcs_label : str, optional
    MCS label if mcs plugin is used.
ntasks : str, optional
    Number of processors required.
nice : str, optional
    Decrease scheduling priority by value.
nodes : int, optional
    Number of nodes to allocate.
ntasks_per_node : int, optional
    Number of tasks to invoke on each node.
oom_kill_step : str, optional
    Set OOMKillStep behaviour.
overcommit : str, optional
    Overcommit resources.
power : str, optional
    Power management options.
priority : str, optional
    Set job priority.
profile : str, optional
    Enable acct_gather_profile for detailed data.
partition : str, optional
    Partition requested.
qos : str, optional
    Quality of service.
quiet : str, optional
    Suppress informational messages.
reboot : str, optional
    Reboot compute nodes before starting job.
oversubscribe : str, optional
    Oversubscribe resources with other jobs.
signal : str, optional
    Send signal when time limit within seconds.
spread_job : str, optional
    Spread job across as many nodes as possible.
error : str, optional
    Redirect stderr to file.
output : str, optional
    Redirect stdout to file.
switches : str, optional
    Optimum switches and max wait time.
core_spec : str, optional
    Count of reserved cores.
thread_spec : str, optional
    Count of reserved threads.
time : str, optional
    Time limit for the job.
time_min : str, optional
    Minimum time limit.
tres_bind : str, optional
    Task to TRES binding options.
tres_per_task : str, optional
    TRES required per task.
use_min_nodes : str, optional
    Prefer smaller node count.
wckey : str, optional
    Wckey to run job under.
cluster_constraint : str, optional
    List of cluster constraints.
contiguous : str, optional
    Demand contiguous range of nodes.
constraint : str, optional
    List of constraints.
nodefile : str, optional
    Request specific list of hosts from file.
mem : str, optional
    Minimum real memory required.
mincpus : str, optional
    Minimum logical processors per node.
reservation : str, optional
    Allocate resources from named reservation.
tmp : str, optional
    Minimum temporary disk required.
nodelist : str, optional
    Request specific list of hosts.
exclude : str, optional
    Exclude specific list of hosts.
exclusive_user : str, optional
    Allocate nodes in exclusive mode.
exclusive_mcs : str, optional
    Exclusive mode when mcs plugin enabled.
mem_per_cpu : str, optional
    Real memory per allocated CPU.
resv_ports : str, optional
    Reserve communication ports.
sockets_per_node : int, optional
    Number of sockets per node to allocate.
cores_per_socket : int, optional
    Number of cores per socket to allocate.
threads_per_core : int, optional
    Number of threads per core to allocate.
extra_node_info : str, optional
    Combine sockets, cores, threads.
ntasks_per_core : int, optional
    Number of tasks per core.
ntasks_per_socket : int, optional
    Number of tasks per socket.
hint : str, optional
    Application binding hints.
mem_bind : str, optional
    Bind memory to locality domains.
cpus_per_gpu : int, optional
    Number of CPUs required per allocated GPU.
gpus : str, optional
    Count of GPUs required.
gpu_bind : str, optional
    Task to GPU binding options.
gpu_freq : str, optional
    Frequency and voltage of GPUs.
gpus_per_node : str, optional
    GPUs per allocated node.
gpus_per_socket : str, optional
    GPUs per allocated socket.
gpus_per_task : str, optional
    GPUs per spawned task.
mem_per_gpu : str, optional
    Real memory per allocated GPU.
disable_output_job_summary : str, optional
    Disable job summary in output file.
nvmps : str, optional
    Launch NVIDIA MPS for job.
pragmas : List[Pragma], optional
    List of pragmas to add to the script.
modules : List[str], optional
    List of modules to load in the script.
custom_command : str, optional
    Custom command to run in the script.
custom_commands : list, optional
    List of custom commands to run in the script.
inlined_script : str, optional
    Inline script to include in the batch script.
inlined_scripts : list, optional
    List of inline scripts to include in the batch script.
line_length : int, optional
    Line length for formatting output.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L18-L1178)

### slurm_script_generator.SlurmScript.custom_commands

*property*

```python
custom_commands: List[str]
```

Get the list of custom commands to run in the script.

Parameters
----------

Returns
-------
List[str]
    List of custom command strings.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L1124-L1136)

### slurm_script_generator.SlurmScript.line_length

*property*

```python
line_length: int
```

Get the maximum line length for the script, used for formatting the output.
This value is used to determine how many characters fit on a line
when generating the script string, and is also used for formatting
the header and section separators.

Parameters
----------

Returns
-------
int
    The line length value.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L1073-L1088)

### slurm_script_generator.SlurmScript.modules

*property*

```python
modules: List[str]
```

Get the list of modules to load in the script.

Parameters
----------

Returns
-------
List[str]
    List of module names.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L1109-L1121)

### slurm_script_generator.SlurmScript.pragmas

*property*

```python
pragmas: List[Pragma]
```

Get the list of Pragma objects in the script.

Parameters
----------

Returns
-------
List[Pragma]
    List of all Pragma instances.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L1091-L1106)

### slurm_script_generator.SlurmScript.add_custom_command

*method*

```python
def add_custom_command(command: str) -> None
```

Add a single custom command to the script.

Parameters
----------
command : str
    The custom command to add.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L451-L467)

### slurm_script_generator.SlurmScript.add_custom_commands

*method*

```python
def add_custom_commands(commands: List[str] | None) -> None
```

Add multiple custom commands to the script.

Parameters
----------
commands : list of str, optional
    List of custom commands to add.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L469-L485)

### slurm_script_generator.SlurmScript.add_inlined_script

*method*

```python
def add_inlined_script(path: str) -> None
```

Add lines from an inlined script file to the custom commands.

Parameters
----------
path : str
    Path to the script file to inline.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L526-L547)

### slurm_script_generator.SlurmScript.add_inlined_scripts

*method*

```python
def add_inlined_scripts(paths: List[str] | None) -> None
```

Add lines from multiple inlined script files to the custom commands.

Parameters
----------
paths : list of str, optional
    List of script file paths to inline.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L549-L565)

### slurm_script_generator.SlurmScript.add_module

*method*

```python
def add_module(module: str) -> None
```

Add a single module to the script.

Parameters
----------
module : str
    The module to add.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L488-L504)

### slurm_script_generator.SlurmScript.add_modules

*method*

```python
def add_modules(modules: List[str] | None) -> None
```

Add multiple modules to the script.

Parameters
----------
modules : list of str, optional
    List of modules to add.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L506-L523)

### slurm_script_generator.SlurmScript.add_param

*method*

```python
def add_param(key: str, value: Any) -> None
```

Add a non-pragma parameter to the script.

Parameters
----------
key : str
    The parameter key.
value : Any
    The parameter value.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L608-L639)

### slurm_script_generator.SlurmScript.add_pragma

*method*

```python
def add_pragma(pragma: Pragma) -> None
```

Add a Pragma object to the script, replacing any existing pragma with the same destination.

Parameters
----------
pragma : Pragma
    The Pragma object to add.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L568-L587)

### slurm_script_generator.SlurmScript.add_pragmas

*method*

```python
def add_pragmas(pragmas: List[Pragma] | None) -> None
```

Add multiple Pragma objects to the script.

Parameters
----------
pragmas : list of Pragma, optional
    List of Pragma objects to add.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L589-L606)

### slurm_script_generator.SlurmScript.check

*method*

```python
def check() -> None
```

Raise ``ValueError`` if :meth:`validate` finds any problems.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L758-L765)

### slurm_script_generator.SlurmScript.from_dict

*method* · *staticmethod*

```python
def from_dict(data: dict[str, Any]) -> SlurmScript
```

Create a SlurmScript instance from a dictionary.

Parameters
----------
data : dict[str, Any]
    Dictionary containing the SlurmScript data.

Returns
-------
SlurmScript
    The constructed SlurmScript object.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L894-L921)

### slurm_script_generator.SlurmScript.from_json

*method* · *staticmethod*

```python
def from_json(path: str) -> SlurmScript
```

Load a SlurmScript instance from a JSON file.

Parameters
----------
path : str
    Path to the JSON file to load.

Returns
-------
SlurmScript
    The constructed SlurmScript object.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L1037-L1054)

### slurm_script_generator.SlurmScript.from_script

*method* · *staticmethod*

```python
def from_script(script: str, verbose: bool = False) -> SlurmScript
```

Parse a SLURM script string and create a SlurmScript instance.

Parameters
----------
script : str
    SLURM script content.
verbose: bool :
     (Default value = False)

Returns
-------
SlurmScript
    The constructed SlurmScript object.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L944-L1019)

### slurm_script_generator.SlurmScript.generate_script

*method*

```python
def generate_script(line_length: int = 54, include_header: bool = False) -> str
```

Parameters
----------
line_length :
    int:  (Default value = 54)
include_header :
    bool:  (Default value = False)

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L641-L721)

### slurm_script_generator.SlurmScript.read_script

*method* · *staticmethod*

```python
def read_script(path: str, verbose: bool = False) -> SlurmScript
```

Read a SLURM script from a file and parse it into a SlurmScript instance.

Parameters
----------
path : str
    Path to the script file.
verbose : bool
    Whether to enable verbose output. (Default value = False)

Returns
-------
SlurmScript
    The parsed SlurmScript object.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L923-L942)

### slurm_script_generator.SlurmScript.save

*method*

```python
def save(path: str | Path, include_header: bool = True, verbose: bool = False) -> None
```

Save the generated SLURM script to a file.

Parameters
----------
path : str
    Path to save the script file.
include_header : bool
    Whether to include the script header.
verbose : bool
    Whether to enable verbose output. (Default value = False)

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L785-L811)

### slurm_script_generator.SlurmScript.submit_job

*method*

```python
def submit_job(path: str, verbose: bool = False, tail: bool = False) -> int
```

Submit the SLURM script as a job using sbatch.

Parameters
----------
path : str
    Path to the script file to submit.
verbose : bool, optional
    Print submission details.
tail : bool, optional
    Follow the file configured by ``--output`` until the submitted job
    leaves the queue. The output filename may contain Slurm's ``%j``
    (job ID) and ``%x`` (job name) substitutions. Defaults to False.

Returns
-------

Raises
------
ValueError
    If :meth:`validate` finds a combination of pragmas sbatch will
    reject (e.g. both ``--mem`` and ``--mem-per-cpu`` set).
RuntimeError
    If sbatch fails to submit the job.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L813-L852)

### slurm_script_generator.SlurmScript.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Convert the SlurmScript instance to a dictionary representation.

Parameters
----------

Returns
-------
dict[str, Any]
    Dictionary with keys 'pragmas', 'modules', and 'custom_commands'.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L767-L783)

### slurm_script_generator.SlurmScript.to_json

*method*

```python
def to_json(path: str) -> None
```

Save the SlurmScript instance as a JSON file.

Parameters
----------
path : str
    Path to save the JSON file.

Returns
-------

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L1021-L1035)

### slurm_script_generator.SlurmScript.to_string

*method*

```python
def to_string(include_header: bool = True) -> str
```

Generate the SLURM script as a string.

Parameters
----------
include_header : bool
    Whether to include the header in the generated script. (Default value = True)

Returns
-------
str
    The generated script string.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L1056-L1070)

### slurm_script_generator.SlurmScript.validate

*method*

```python
def validate() -> List[str]
```

Check for combinations of pragmas that ``sbatch`` will reject.

These are mistakes that only surface once a job is actually
submitted (or silently misbehave), so it is worth catching them in
Python first. This is not an exhaustive validator of sbatch's rules,
just the handful of cross-pragma mistakes that are easy to make.

Returns
-------
List[str]
    Human-readable problem descriptions. Empty if nothing was found.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/slurm_script.py#L723-L756)

## slurm_script_generator.job_state

*function*

```python
def job_state(job_id: Union[int, str], timeout: float = 30.0) -> Optional[str]
```

Re-exported from: `slurm_script_generator.squeue`

Return the state of a job from SLURM accounting (``sacct``).

``squeue`` only says whether a job is still in the queue, not how it ended,
so this is what distinguishes a crashed run from one that simply wrote no
output. States are normalized, e.g. ``'CANCELLED by 1234'`` -> ``'CANCELLED'``.

Parameters
----------
job_id : int or str
    The job ID to look up.
timeout : float
    Seconds to wait for ``sacct`` before giving up. Defaults to 30.

Returns
-------
str or None
    The job state (``'COMPLETED'``, ``'FAILED'``, ``'RUNNING'``, ...), or
    None when it cannot be determined — no accounting configured, ``sacct``
    missing or unresponsive, or the job not yet in the accounting database.
    A None result is *not* evidence of failure and callers should not
    report one.

See Also
--------
job_states : Batch version, one ``sacct`` call for many jobs.

Examples
--------
>>> job_state(12345)
'COMPLETED'

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L218-L253)

## slurm_script_generator.job_states

*function*

```python
def job_states(job_ids: Union[int, str, List[Union[int, str]]], timeout: float = 30.0) -> Dict[int, Optional[str]]
```

Re-exported from: `slurm_script_generator.squeue`

Return the states of several jobs from SLURM accounting (``sacct``).

Uses a single ``sacct`` call for the whole batch, so waiting on many jobs
costs one subprocess rather than one per job. States are normalized,
e.g. ``'CANCELLED by 1234'`` -> ``'CANCELLED'``.

Parameters
----------
job_ids : int, str, or list of int/str
    The job IDs to look up.
timeout : float
    Seconds to wait for ``sacct`` before giving up. Defaults to 30.

Returns
-------
dict of int -> (str or None)
    One entry per requested job ID, in the order given. The value is None
    when the state cannot be determined — no accounting configured,
    ``sacct`` missing or unresponsive, or the job not yet in the accounting
    database. A None value is *not* evidence of failure and callers should
    not report one.

Examples
--------
>>> job_states([12345, 12346])
{12345: 'COMPLETED', 12346: 'FAILED'}

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L145-L215)

## slurm_script_generator.task_states

*function*

```python
def task_states(job_ids: Union[int, str, List[Union[int, str]]], timeout: float = 30.0) -> Dict[int, Dict[int, str]]
```

Re-exported from: `slurm_script_generator.squeue`

Return the states of the tasks of job arrays.

:func:`job_states` folds the tasks of an array into one state per job;
this keeps them apart, which is what tells the one failed task of an array
from the ninety-nine that finished. The states come from SLURM accounting
(one ``sacct`` call) and, for the tasks still in the queue, from one
``squeue`` call, which is authoritative for those: accounting can lag
behind the queue, and on a system without accounting the queue is all
there is.

Parameters
----------
job_ids : int, str, or list of int/str
    The IDs of the array jobs to look up.
timeout : float
    Seconds to wait for ``sacct`` and for ``squeue``. Defaults to 30.

Returns
-------
dict of int -> dict of int -> str
    For each requested job, the state of each task that is known, by task
    ID: ``'PENDING'``, ``'RUNNING'``, ``'COMPLETED'``, ``'FAILED'``,
    ``'TIMEOUT'``, ... A task that is missing is one whose state cannot be
    determined (it has left the queue and there is no accounting, or
    neither command is available); this is *not* evidence of failure.

See Also
--------
job_states : One state per job, for jobs that are not arrays.

Examples
--------
>>> task_states(12345)
{12345: {1: 'COMPLETED', 2: 'FAILED', 3: 'RUNNING', 4: 'PENDING'}}

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L304-L376)

**Modules**

- `slurm_script_generator.clusters`
- `slurm_script_generator.main`
- `slurm_script_generator.pragmas`
- `slurm_script_generator.remote`
- `slurm_script_generator.runs`
- `slurm_script_generator.salloc`
- `slurm_script_generator.slurm_script`
- `slurm_script_generator.slurm_template`
- `slurm_script_generator.squeue`
- `slurm_script_generator.templates`
- `slurm_script_generator.utils`
