Skip to main content

cluster_utils

cluster_utils is a Python package that simplifies interacting with compute clusters. It is geared towards tasks typical for machine learning research, for example running multiple seeds, grid searches, and hyperparameter optimization. The package was developed in the Autonomous Learning group at the University of Tübingen.

A note on support. cluster_utils was initially developed for inhouse use. In particular, this means that documentation is sparse (though we're working on extending it), and the user experience is suboptimal in some places. We are open sourcing the package now because we think it could also be useful for other people in the machine learning community. However, we can only provide limited support for user questions and requests.

A note on stability. This package is in stable beta mode. cluster_utils has been powering the experiments behind many machine learning projects, and has been battle tested a lot. However, there are many rough edges and bugs that remain; you have been warned! If you encounter any bugs or have suggestions for improvements, please submit an issue and we will try to work on it.

Features

  • Parametrized jobs and hyperparameter optimization: run grid searches or multi-stage hyperparameter optimization.
  • Supports several cluster backends: currently, Slurm and HTCondor, as well as local (single machine runs) are supported.
  • Automatic job management: jobs are submitted, monitored (with error reporting), and cleaned up in an automated way.
  • Timeouts & restarting of failed jobs: jobs can be stopped and resubmitted after some time; failed jobs can be (manually) restarted.
  • Integrated with git: jobs are run from a git clone with customizable branch and commit number to enhance reproducility.
  • Reporting: results are summarized in CSV files, and optionally PDF reports with basic summaries and plots.

Installation

pip install "cluster_utils[runner]"

See documentation for more details.

Documentation

The documentation is hosted at https://martius-lab.github.io/cluster_utils.

You can also build the documentation locally with the following commands:

git clone https://github.com/martius-lab/cluster_utils.git
cd cluster_utils
# install package with the additional dependencies needed to build the documentation
pip install ".[docs]"
cd docs/
make html  # build documentation

When the build is finished, open docs/_build/html/index.html with the browser of your choice.

Quick Start

First, the code that should be executed with cluster_utils needs to be instrumented to communicate with the cluster_utils server process.

The simplest way to do so is to wrap the main function with the cluster_main decorator:

from cluster_utils import cluster_main

@cluster_main
def main(
    working_dir,    # Path to a directory for storing results and checkpoints
    id,             # Id of the job
    **kwargs        # Other parameters passed by cluster_utils
):
    results = ...   # Code that computes something interesting

    return results  # Results are sent to the cluster_utils server

If you don't want to use a decorator, use the following:

import cluster_utils

def main(params):
    results = ...  # Code that computes something interesting
    return results

if __name__ == "__main__":
    # Dictionary that contains parameters passed by cluster_utils. This call also establishes 
    # communication with the cluster_utils server. Also contains "working_dir" and "id", as above.
    params = cluster_utils.initialize_job()

    results = main(params)

    # Report results back to cluster_utils.
    cluster_utils.finalize_job(results)

To start a cluster run, start the cluster_utils server on the login node of the cluster. There are two basic functionalities:

python3 -m cluster_utils.grid_search specification_of_grid_search.json

for grid search, and

python3 -m cluster_utils.hp_optimization specification_of_hp_opt.json

for hyperparameter optimization. Both receive a configuration file that specifies the compute environment, the script to be called, parameters to pass and more.

See examples/basic and examples/rosenbrock for simple demonstrations.

Usage

Environment Setup

The simplest way to specify your Python environment is to activate it (using virtualenv, pipenv, conda, etc.) before calling python -m cluster_utils.grid_search or python -m cluster_utils.hp_optimization. The jobs will automatically inherit this environment. A caveat of this approach is that if you installed your local package in the environment, this package might override the repository cluster_utils clones using git, i.e. you are not using a clean clone of your project.

There are multiple options to further customize the environment in the environment_setup configuration section, see the documentation.

Further Documentation Links

Metadata

Release files for cluster-utils 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cluster-utils 3.0.0
File Size Uploaded Provenance
cluster_utils-3.0.0.tar.gz 202.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cluster-utils 3.0.0
File Interpreter ABI Platform
cluster_utils-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 286.7 kB

Release files / cluster_utils-3.0.0.tar.gz

Download URL cluster_utils-3.0.0.tar.gz
Size 202.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f3c6a2f8870c9089e62b60292a746d8c59f378874a159fff2c2ad0335f791ffb
BLAKE2b-256 checksum
How to use checksums
6b6394ff72b313d99771018a18e3f4839ff09fa442706ab26badbf32ac31fbd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / cluster_utils-3.0.0-py3-none-any.whl

Download URL cluster_utils-3.0.0-py3-none-any.whl
Size 84.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04931ee616edacbf6c8c34fbaac7e4bb19abe226dff835332b07e6254f549310
BLAKE2b-256 checksum
How to use checksums
b858118d49eeff7699a869df652076fcfcc9eccaff21b5e3c9f4f0bf266c1dcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Security for cluster-utils 3.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page