Skip to main content

oh-my-batch

PyPI version PyPI - Downloads PyPI - Python Version

A command line toolkit to simplify batch tasks generation and execution.

Features

  • omb combo: generate folders/files from different combinations of parameters
  • omb batch: generate batch scripts from multiple working directories
  • omb job: track the state of job in job scheduler
  • omb misc: miscellaneous commands

Install

pip install oh-my-batch

Usage

oh-my-batch provides a command line interface omb with multiple sub-commands. You can read the help message of each sub-command to learn how to use it.

For example,

omb  # see the help message of `omb` command
omb combo # see the help message of `combo` sub-command
omb combo set_broadcast --help # see the help message of `set_broadcast` command in combo
omb batch # see the help message of `batch` sub-command
omb batch add_work_dirs --help # see the help message of `add_work_dirs` command in batch
omb job # see the help message of `job` sub-command
omb job slurm submit --help # see the help message of slurm `submit` command

Chaining function calls

oh-my-batch makes use of fire's chaining function call to provide a flexible command line interface. You can see it as builder pattern for command line tools.

For command that supports chaining function calls, you can chain multiple commands with - to build your desired command. You will find many examples in Examples section below.

Thinking in oh-my-batch

English | 中文

Note that the document is not yet complete.

Examples

  • TESLA workflow: A customizable active learning workflow for training machine learning potentials.
  • TESLA PIMD workflow: A customizable active learning workflow for training machine learning potentials with path integral molecular dynamics.
  • LAMMPS benchmark: Find out the best MPI and OpenMP setup for LAMMPS through benchmarking.

Use cases

Generate files from different combinations of parameters

It's common to generate files with different combinations of parameters in scientific computing. For example, you have 3 LAMMPS data files in tmp directory: tmp/1.data, tmp/2.data, tmp/3.data. And you want to generate a series of input files with different parameters, for example, different temperatures 300K, 400K, 500K, against each data file.

In this case, you can use omb combo command to generate a series of input files for you.

# prepare fake data files
mkdir -p tmp/
touch tmp/1.data tmp/2.data tmp/3.data

# prepare a lammps input file template
cat > tmp/in.lmp.tmp <<EOF
read_data @DATA_FILE
velocity all create @TEMP @RANDOM
run 1000
EOF

# prepare a run script template
cat > tmp/run.sh.tmp <<EOF
cat in.lmp  # simulate running lammps
EOF

# generate input files
omb combo \
    add_files DATA_FILE tmp/*.data - \
    add_var TEMP 300 400 500 - \
    add_randint RANDOM -n 3 -a 1 -b 1000 - \
    set_broadcast RANDOM - \
    make_files tmp/tasks/{i}-T-{TEMP}/in.lmp --template tmp/in.lmp.tmp - \
    make_files tmp/tasks/{i}-T-{TEMP}/run.sh --template tmp/run.sh.tmp --mode 755 - \
    done

The above script will generate 9 folders in tmp/tasks directory with names from 0-T-300, 1-T-400, 2-T-500, 3-T-300 to 8-T-500. Each folder will contain a in.lmp file and a run.sh file.

The 9 folders are the combinations of 3 data files and 3 temperatures, and each input file will have a independent random number between 1 and 1000 as RANDOM.

You can run the about script by ./examples/omb-combo.sh, and you can also run omb combo --help to see the detailed usage of combo command.

Generate batch scripts from multiple working directories

It's common to submit a lot of jobs to a job scheduler. omb batch is designed to help you generate batch scripts from multiple working directories and package them into several batch scripts.

Let's continue the above example, now you have 9 folders in tmp/tasks directory. You want to package them into 2 batch scripts to submit to a job scheduler.

You can use omb batch to generate batch scripts for you like this:

cat > tmp/lammps_header.sh <<EOF
#!/bin/bash
#SBATCH -J lmp
#SBATCH -n 1
#SBATCH -t 1:00:00
EOF

omb batch \
    add_work_dirs tmp/tasks/* - \
    add_header_files tmp/lammps_header.sh - \
    add_cmds "./run.sh" - \
    make tmp/lmp-{i}.slurm --concurrency 2

You will find batch scripts tmp/lmp-0.slurm and tmp/lmp-1.slurm in tmp directory.

You can run the above script by ./examples/omb-batch.sh,

Track the state of job in job schedular

Let's continue the above example, now you have submitted the batch scripts to the job scheduler. In this case, you can use omb job to track the state of the jobs.

omb job slurm submit tmp/*.slurm --max_tries 3 --wait --recovery lammps-jobs.json

The above command will submit the batch scripts to the job scheduler, and wait for the jobs to finish. If the job fails, it will retry for at most 3 times.

The --recovery option will save the job information to lammps-jobs.json file. If omb job is interrupted, you can rerun the exact same command to recover the job status, so that you don't need to resubmit the jobs that are still running or completed.

Shell tips

oh-my-batch is intended to help you implement computational workflows with shell scripts. To make the best use of oh-my-batch, you need to know some shell tips.

Metadata

Release files for oh-my-batch 0.7.7

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

Source distribution (sdist)

Source distribution for oh-my-batch 0.7.7
File Size Uploaded Provenance Actions
oh_my_batch-0.7.7.tar.gz 27.6 kB Without provenance Details for oh_my_batch-0.7.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for oh-my-batch 0.7.7
File Interpreter ABI Platform Actions
oh_my_batch-0.7.7-py3-none-any.whl Python 3 none any Details for oh_my_batch-0.7.7-py3-none-any.whl

Total release size: 56.7 kB

Release files / oh_my_batch-0.7.7.tar.gz

Download URL oh_my_batch-0.7.7.tar.gz
Size 27.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fc7c6658ebcdd650a4b0f3992196ce636011ce549782a3661be1f0a0836ffcff
BLAKE2b-256 checksum
How to use checksums
3611cbed7b771abc9a34951b4e1efbe49845d6934defcadc324db44373f2f814
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.13 Linux/6.18.54.1-microsoft-standard-WSL2

Release files / oh_my_batch-0.7.7-py3-none-any.whl

Download URL oh_my_batch-0.7.7-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
defd07640cdaf2d215a218b4f7c97083677b421eaa9b21320b14f4527b6652f1
BLAKE2b-256 checksum
How to use checksums
dfc52b03dc1b3adb8e92eed2ebd7e6ad8010d54aa0b4511cb998095441c32d34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.13 Linux/6.18.54.1-microsoft-standard-WSL2

Security for oh-my-batch 0.7.7

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.7.7 This release

2 release files No provenance

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