# SbatchPy
![PyPI Version](https://img.shields.io/pypi/v/sbatchpy.svg) ![PyPI Downloads](https://static.pepy.tech/badge/sbatchpy)
A python package that allows easy ``sbatch`` job script creation and submissions on ``hpc clusters``, directly from ``python``.
# Installation
```bash
# to install latest PyPI release
pip install sbatchpy
# to install latest GitHub commit
pip install --upgrade git+https://github.com/killiansheriff/sbatchpy
```
# Usage
An example on how to run a python script called ``my_script.py`` taking 2 arguments ``var1`` and ``var2`` as inputs, and using the ``base`` environement is provided below. A complete example with outputs can be found [here](examples/).
```python
from sbatchpy import run
config = {
"mem": "1gb",
"time": "00:01:00",
"account": "myaccount",
"cpus-per-task": "5",
"partition": "shared",
"ntasks-per-node": "1",
"nodes": "1",
}
for var1, var2 in zip([1, 2, 3], ["A", "B", "C"]):
config["job-name"] = f"myjob_{var1}var1_{var2}var2.sh"
config["output"] = f"out/myjob_{var1}var1_{var2}var2.out"
run(
config,
code=f"source activate base \n python my_script.py {var1} {var2}",
)
```
By default, sbatchpy will check that ``config["output"]``'s directory folder exists. If it doesn't, you will be notified and the job will not run.
Additionally, each sbatch submission script is saved inside the ``f"{os.getcwd()}/.job"`` folder. Another saving folder can be chosen by passing ``job_directory=my_saving_directory_path`` to the ``run`` function which is responsible of creating the submission script and running it using ``sbatch job_directory/config["job-name"]``.
Raw data
{
"_id": null,
"home_page": "https://github.com/killiansheriff/sbatchpy",
"name": "sbatchpy",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "sbatch,slurm,python,hpc",
"author": "Killian Sheriff",
"author_email": "ksheriff@mit.edu",
"download_url": "https://files.pythonhosted.org/packages/17/91/b7f0e1e6d2364f6adf7a55373c8a6027cb114ff78666bcf81cd9c300f277/sbatchpy-1.0.0.tar.gz",
"platform": null,
"description": "# SbatchPy\n![PyPI Version](https://img.shields.io/pypi/v/sbatchpy.svg) ![PyPI Downloads](https://static.pepy.tech/badge/sbatchpy) \n\nA python package that allows easy ``sbatch`` job script creation and submissions on ``hpc clusters``, directly from ``python``. \n\n# Installation\n\n```bash\n# to install latest PyPI release\npip install sbatchpy\n\n# to install latest GitHub commit\npip install --upgrade git+https://github.com/killiansheriff/sbatchpy\n```\n\n# Usage\nAn example on how to run a python script called ``my_script.py`` taking 2 arguments ``var1`` and ``var2`` as inputs, and using the ``base`` environement is provided below. A complete example with outputs can be found [here](examples/).\n\n```python\nfrom sbatchpy import run\n\nconfig = {\n \"mem\": \"1gb\",\n \"time\": \"00:01:00\",\n \"account\": \"myaccount\",\n \"cpus-per-task\": \"5\",\n \"partition\": \"shared\",\n \"ntasks-per-node\": \"1\",\n \"nodes\": \"1\",\n}\n\nfor var1, var2 in zip([1, 2, 3], [\"A\", \"B\", \"C\"]):\n\n config[\"job-name\"] = f\"myjob_{var1}var1_{var2}var2.sh\"\n config[\"output\"] = f\"out/myjob_{var1}var1_{var2}var2.out\"\n run(\n config,\n code=f\"source activate base \\n python my_script.py {var1} {var2}\",\n )\n\n```\nBy default, sbatchpy will check that ``config[\"output\"]``'s directory folder exists. If it doesn't, you will be notified and the job will not run. \n\nAdditionally, each sbatch submission script is saved inside the ``f\"{os.getcwd()}/.job\"`` folder. Another saving folder can be chosen by passing ``job_directory=my_saving_directory_path`` to the ``run`` function which is responsible of creating the submission script and running it using ``sbatch job_directory/config[\"job-name\"]``.\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Sbatchpy is a python package allowing easy sbatch job script creation and submissions on hpc clusters, directly from python.",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/killiansheriff/sbatchpy"
},
"split_keywords": [
"sbatch",
"slurm",
"python",
"hpc"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3e0bc4ff3b250c98a6875c2ac3b7bf30af9e7ec102b2395588b9162a86237a0f",
"md5": "90c45b1327101a7c309175203c38f2e3",
"sha256": "da7424c0dd9f1d1086c57c7e89621f1792ede29c12ae61a41429b3f945afa321"
},
"downloads": -1,
"filename": "sbatchpy-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "90c45b1327101a7c309175203c38f2e3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 2959,
"upload_time": "2023-08-11T21:32:31",
"upload_time_iso_8601": "2023-08-11T21:32:31.874740Z",
"url": "https://files.pythonhosted.org/packages/3e/0b/c4ff3b250c98a6875c2ac3b7bf30af9e7ec102b2395588b9162a86237a0f/sbatchpy-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1791b7f0e1e6d2364f6adf7a55373c8a6027cb114ff78666bcf81cd9c300f277",
"md5": "e2775f3299a04eb1001766030536b038",
"sha256": "54a4ebaabd90ec7e7a93441c5124cbe9a5d8ebafb7b77ac488f9193facf3645a"
},
"downloads": -1,
"filename": "sbatchpy-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "e2775f3299a04eb1001766030536b038",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 2840,
"upload_time": "2023-08-11T21:32:33",
"upload_time_iso_8601": "2023-08-11T21:32:33.273056Z",
"url": "https://files.pythonhosted.org/packages/17/91/b7f0e1e6d2364f6adf7a55373c8a6027cb114ff78666bcf81cd9c300f277/sbatchpy-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-11 21:32:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "killiansheriff",
"github_project": "sbatchpy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sbatchpy"
}