Skip to main content

Locusts

Locusts is a Python package for distributing many small jobs on a system (which can be your machine or a remote HPC running SLURM).

Installation

Locusts package is currently part of the PyPI Test archive. In order to install it, type

python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps locusts

Note: PyPI Test is not a permanent archive. Expect this installation procedure to change over time.

How it works

Locusts is thought for whom has to run a huge amount of small, independent jobs and has problems with the most used schedulers which will scatter the jobs over over too many nodes, or queue them indefinitely. Moreover, this package provides a safe, clean environment for each job instance, and keeps and collects notable inputs and outputs. In short, locusts creates a minimal filesystem where it prepares one environment for each job it has to execute. The runs are directed by a manager bash script, which schedules them and reports its stauts and the one of the jobs to the main locusts routine, which will always be run locally. Finally, it checks for a set of compulsory output files and compiles a list of success and failures.

Modes

Locusts can help you distributing your jobs when you are facing one of these three situations:

  • You want to run everything on your local machine (local mode)
  • You want to submit jobs to a HPC (remote mode)
  • You want to submit jobs to a HPC which shares a directory with your local machine (remote-shared mode)

Environments

Once you give locusts the set of input to consider and the command to execute, it creates the Generic Environment, a minimal filesystem composed of three folders:

  • An execution folder, where the main manager scripts will be placed and executed and where execution cache files will keep them updated on the progress of the single jobs
  • A work folder, where the specific inputs of each job are considered and where outputs are addressed
  • A shared folder, where common inputs have to be placed in case a group of different jobs wants to use them

Basing on this architecture, Locusts provides two types of environments the user can choose from depending on her needs:

Default Locusts Environment

Locusts Default

If the user only needs to process a (possibly huge) amount of files and get another (still huge) amount of output files in return, this environment is the optimal choice: it allows for minimal data transfer and disk space usage while each of the parallel runs will run in a protected sub-environment. The desired output files and the corresponding logs will then be collected and put in a folder designated by the user

Custom Environment

Locusts Custom The user could nonetheless want to parallelize a program or a code having more complex effects than taking in a bunch of input files and returning some outputs: for example, a program displacing files around a filesystem will not be able to run in the Default Locusts Environment. In these situations, the program needs to have access to a whole environment rather than to a set of input files.

Starting from this common base, there are two different environments that can be used:

  • The default Locusts Environment consists in having one folder corresponding to each set of files for running one instance of the command
  • The Custom Environment lets the user employ any other filesystem

Tutorial

Example 1: Running a script requiring input/output management (Default Environment)

You can find this example in the directory tests/test_manager/ In tests/test_manager/my_input_dir/ you will find 101 pairs of input files: inputfile\_\#.txt and secondinputfile\_\#.txt, where 0 <= # <= 100. Additionally, you will also find a single file named sharedfile.txt. The aim here is executing this small script over the 101 sets of inputs: sleep 1; ls -lrth <inputfile> <secondinputfile> <sharedfile> > <outputfile>; cat <inputfile> <secondinputfile> <sharedfile> > <secondoutputfile> For each pair, the script takes in inputfile\_\#.txt, secondinputfile\_\#.txt (both vary from instance to instance) and sharedfile.txt (which instead remains always the same), and returns ls\_output\_\#.txt and cat\_output\_\#.txt. In order to mimick a longer process, the script is artificially made to last at least one second.

The file tests/test_manager/test_manager.py gives you an example (and also a template) of how ou can submit a job on Locusts. The function you want to call is locusts.swarm.launch, which takes several arguments. Before describing them, let's look at the strategy used by Locusts: in essence, you give Locusts a template of the command you want to execute, and the you tell Locusts where to look for files to execute that template with. In our case, the template is: sleep 1; ls -lrth inputfile_<id>.txt secondinputfile_<id>.txt <shared>sf1 > ls_output_<id>.txt; cat inputfile_<id>.txt secondinputfile_<id>.txt <shared>sf1 > cat_output_<id>.txt Notice there are two handles that Locusts will know how to replace: <id> and <shared>. The <id> handle is there to specify the variable part of a filename (in our case, an integer in the [0,100] interval). The <shared> tag tells locust

  • indir takes the location (absolute path or relative from where you are calling the script) of the directory containing all your input files
  • outdir takes the location (absolute path or relative from where you are calling the script) of the directory where you want to collect your results
  • code takes a unique codename for the job you want to launch
  • spcins takes a list containing the template names for the shdins=shared_inputs, outs=outputs, cmd=command_template, parf=parameter_file

Example 2: Running a script requiring input/output management (Default Environment)

You will find the material

Release files for locusts 0.0.98

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

Source distribution (sdist)

Source distribution for locusts 0.0.98
File Size Uploaded
locusts-0.0.98.tar.gz 29.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for locusts 0.0.98
File Interpreter ABI Platform
locusts-0.0.98-py3-none-any.whl Python 3 none any Details

Total release size: 58.0 kB

Release files / locusts-0.0.98.tar.gz

Download URL locusts-0.0.98.tar.gz
Size 29.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9bec29e355c8e8e046a0003ddf5e4ab7883018caec7db5d20781ef568cc9adca
BLAKE2b-256 checksum
How to use checksums
7899dc1f165833948c0303c75ceaa93bb1174c2d89330d9e74bd2f7e2adb1d58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / locusts-0.0.98-py3-none-any.whl

Download URL locusts-0.0.98-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba1fc451408f71f908e4c199b1d8c3bd574a6fc9fe3149bb3f4f2a025f81c00f
BLAKE2b-256 checksum
How to use checksums
d58f60f87fdc8e96c4cccd70a65d37d49ee71a19500d70e1f4444ff4338c0492
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.0.98 This release

2 release files

0.0.97

2 release files

0.0.96

2 release files

0.0.95

2 release files

0.0.94

2 release files

0.0.93

2 release files

0.0.92

2 release files

0.0.91

2 release files

0.0.90

2 release files

0.0.89

2 release files

0.0.88

2 release files

0.0.87

2 release files

0.0.86

2 release files

0.0.85

2 release files

0.0.84

2 release files

0.0.82

2 release files

0.0.81

2 release files

0.0.80

2 release files

0.0.79

2 release files

0.0.78

1 release file

0.0.77

2 release files

0.0.76

2 release files

0.0.75

2 release files

0.0.74

2 release files

0.0.73

2 release files

0.0.72

2 release files

0.0.71

2 release files

0.0.70

2 release files

0.0.69

2 release files

0.0.68

2 release files

0.0.67

2 release files

0.0.66

2 release files

0.0.64

2 release files

0.0.63

2 release files

0.0.62

2 release files

0.0.61

2 release files

0.0.60

2 release files

0.0.59

2 release files

0.0.58

2 release files

0.0.57

2 release files

0.0.56

2 release files

0.0.54

2 release files

0.0.53

2 release files

0.0.52

2 release files

0.0.51

2 release files

0.0.50

2 release files

0.0.49

2 release files

0.0.48

2 release files

0.0.47

2 release files

0.0.45

2 release files

0.0.43

2 release files

0.0.42

2 release files

0.0.41

2 release files

0.0.40

2 release files

0.0.30

2 release files

0.0.29

2 release files

0.0.28

2 release files

0.0.27

2 release files

0.0.26

2 release files

0.0.25

2 release files

0.0.24

2 release files

0.0.23

2 release files

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