Submitit Job Submission Library

1.5.4 · active · verified Sat Apr 11

Submitit is a Python 3.8+ toolbox developed by Facebook Incubator for submitting jobs to Slurm clusters, as well as providing a local executor for testing. It simplifies the process of dispatching Python functions to compute nodes, managing job states, and retrieving results. The current version is 1.5.4, and it sees active maintenance with occasional releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `submitit.AutoExecutor` to submit Python functions as jobs. It showcases configuring an executor, defining a simple function, submitting multiple jobs in a batch, and retrieving their results. The `AutoExecutor` intelligently switches between Slurm and local execution based on the environment.

import submitit
import time
import os

def my_function(x):
    time.sleep(0.1) # Simulate some work
    print(f"Hello from job! Input: {x}, PID: {os.getpid()}")
    return x * x

# Configure a log folder for submitit to store job information
# The %j placeholder will be replaced by the Slurm job ID
log_folder = os.path.join(os.getcwd(), "submitit_logs", "%j")

# Use AutoExecutor, which selects SlurmExecutor if a Slurm environment
# is detected, otherwise falls back to LocalExecutor.
executor = submitit.AutoExecutor(folder=log_folder)

# Set Slurm parameters (these are ignored by LocalExecutor)
executor.update_parameters(timeout_min=5, slurm_array_parallelism=2)

# Submit jobs within a batch context
with executor.batch():
    jobs = []
    for i in range(5):
        job = executor.submit(my_function, i)
        jobs.append(job)
    
    print(f"Submitted {len(jobs)} jobs. Waiting for results...")
    
    # Retrieve results (blocks until all jobs are complete)
    outputs = [job.result() for job in jobs]
    print(f"All jobs completed. Results: {outputs}")

view raw JSON →