Skip to main content

Provides ability to run against Slurm

Project description

Staging: idmtools-platform-slurm

idmtools-platform-slurm

Introduction

SlurmPlatform is a platform designed to facilitate the execution of experiments and simulations in slurm cluster.

Setting Up Virtual Environment

To set up a virtual environment for SlurmPlatform, follow these steps:

  1. Install Python

    Ensure you have Python 3.8+ installed on your system.

  2. Create Virtual Environment

    There are multiple ways to create a virtual environment. Below is an example using venv:

    python -m venv slurm_env
    
  3. Activate Virtual Environment

    • On Windows:
      slurm_env\Scripts\activate
      
    • On Linux:
      source slurm_env/bin/activate
      
  4. Install SlurmPlatform

    pip install idmtools-platform-slurm
    
  5. Install Dependencies

    pip install -r requirements.txt
    
  6. Optional(No need step #4 and #5), Install all slurm platform related packages

    pip install idmtools[slurm]
    

Development Tips

There is a Makefile file available for most common development tasks. Here is a list of commands

clean       -   Clean up temproary files
lint        -   Lint package and tests
test        -   Run All tests
coverage    -   Run tests and generate coverage report that is shown in browser

On Windows, you can use pymake instead of make

Manually run a script as a Slurm job

Preparation

(1).Have target script ready, say my_script.py, suppose you have folder structure like::

script_folder
    my_script.py
    ......

(2). Created a virtual environment and activated it.

Steps

  1. within the target script folder, create a batch file 'sbatch.sh' (without quote) with content:
#!/bin/bash

#SBATCH --partition=b1139
#SBATCH --time=10:00:00
#SBATCH --account=b1139

#SBATCH --output=stdout.txt
#SBATCH --error=stderr.txt

# replace with your script file
python3 my_script.py
    
exit $RESULT

Note: the content here is based on Northwestern University QUEST Slurm system. For general case, above content (required #SBATCH parameters) may be a little bit different.

  1. run your target script as SLURM job execute the following commands from console (under virtual environment):

    cd path_to_script_folder

    sbatch sbatch.sh

Note: any output information from my_script.py is stored in file stdout.txt under the current folder. For example, if my_script.py kicks out another Slurm job, then its Slurm id information can be found in file stdout.txt.

Use SlurmJob to run a script as a Slurm job

The example can be simple as the following:

--script.py--

   from idmtools.core.platform_factory import Platform
   from idmtools_platform_slurm.utils.slurm_job.slurm_job import SlurmJob

   script = '<user script path>'
   # script = 'example_path/python_sim_slurm.py'   # example
   platform = Platform('SLURM_LOCAL', job_directory='<job_directory>')
   sj = SlurmJob(script_path=script, platform=platform)
   sj.run()

With SlurmPlatform to run a script as a Slurm job

We have SlurmJob integrated into SlurmPlatform and any Python script can run as a Slurm job simply doing:

--script.py--

   from idmtools.entities.command_task import CommandTask
   from idmtools.entities.experiment import Experiment
   from idmtools.core.platform_factory import Platform
   
   platform = Platform('SLURM_LOCAL', job_directory='<job_directory>')
   # Define task
   command = "echo 'Hello, World!'"
   task = CommandTask(command=command)
   # Run an experiment
   experiment = Experiment.from_task(task, name="example")
   experiment.run(platform=platform)

Folder structure:

See Folder Structure

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

idmtools_platform_slurm-3.0.9.tar.gz (47.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

idmtools_platform_slurm-3.0.9-py3-none-any.whl (39.9 kB view details)

Uploaded Python 3

File details

Details for the file idmtools_platform_slurm-3.0.9.tar.gz.

File metadata

  • Download URL: idmtools_platform_slurm-3.0.9.tar.gz
  • Upload date:
  • Size: 47.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for idmtools_platform_slurm-3.0.9.tar.gz
Algorithm Hash digest
SHA256 edcd29192ced6c2ad98c7a7c28d9b7af7ac4b60db812eaf82c0b8adedffd1291
MD5 c82b7e22ae3a64af96fbfc187030b21e
BLAKE2b-256 7a12211c6c837cb604a28a9c10f020e3918a9f1a2454818cfb4b894b01e41b00

See more details on using hashes here.

Provenance

The following attestation bundles were made for idmtools_platform_slurm-3.0.9.tar.gz:

Publisher: deploy.yml on InstituteforDiseaseModeling/idmtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file idmtools_platform_slurm-3.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for idmtools_platform_slurm-3.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 a37523f142be11df8eaf27e47bb225c2be6c67dec3405160c8e3c548a22b3d94
MD5 64adbd76e189545e530090be591e21cd
BLAKE2b-256 8b17993597a667cb6da921aafb258e6822ac75f8138e81b50e19faffac21e40d

See more details on using hashes here.

Provenance

The following attestation bundles were made for idmtools_platform_slurm-3.0.9-py3-none-any.whl:

Publisher: deploy.yml on InstituteforDiseaseModeling/idmtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page