code: def main():
      t0 = time.time()
      # Cleanup log folder.
      # This folder may grow rapidly especially if you have large checkpoints,
      # or submit lot of jobs. You should think about an automated way of cleaning it.
      folder = Path(__file__).parent / "mnist_logs"
      if folder.exists():
          for file in folder.iterdir():
              file.unlink()
  
      ex = submitit.AutoExecutor(folder)
      if ex.cluster == "slurm":
          print("Executor will schedule jobs on Slurm.")
      else:
          print(
              f"!!! Slurm executable `srun` not found. Will execute jobs on '{ex.cluster}'"
          )
  
      model_path = folder / "model.pkl"
      trainer = MnistTrainer(
          LogisticRegression(
              penalty="l1", solver="saga", tol=0.1, multi_class="auto"
          )
      )
  
      # Specify the job requirements.
      # Reserving only as much resource as you need ensure the cluster resource are
      # efficiently allocated.
      ex.update_parameters(mem_gb=1, cpus_per_task=4, timeout_min=5)
      job = ex.submit(trainer, 5000, model_path=model_path)
  
      print(f"Scheduled {job}.")
  
      # Wait for the job to be running.
      while job.state != "RUNNING":
          time.sleep(1)
  
      print("Run the following command to see what's happening")
      print(f"  less +F {job.paths.stdout}")
  
      # Simulate preemption.
      # Tries to stop the job after the first stage.
      # If the job is preempted before the end of the first stage, try to increase it.
      # If the job is not preempted, try to decrease it.
      time.sleep(25)
      print(f"preempting {job} after {time.time() - t0:.0f}s")
      job._interrupt()
  
      score = job.result()
      print(f"Finished training. Final score: {score}.")
      print(f"---------------- Job output ---------------------")
      print(job.stdout())
      print(f"-------------------------------------------------")
  
      assert model_path.exists()
      with open(model_path, "rb") as f:
          (scaler, clf) = pickle.load(f)
      sparsity = np.mean(clf.coef_ == 0) * 100
      print(f"Sparsity with L1 penalty: {sparsity / 100:.2%}")
  
file_path: submitit/docs/mnist.py
imports: import functools
  import pickle
  import time
  from pathlib import Path
  import numpy
  from sklearn.datasets import fetch_openml
  from sklearn.linear_model import LogisticRegression
  from sklearn.model_selection import train_test_split
  from sklearn.preprocessing import StandardScaler
  from sklearn.utils import check_random_state
  import submitit
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types