Metadata-Version: 2.5
Name: shephex
Version: 0.5.0
Summary: Create, run and manage computational experiments in Python, locally or as Slurm array jobs
Project-URL: Documentation, https://mads-peter.gitlab.io/shephex/
Project-URL: Source, https://gitlab.com/Mads-Peter/shephex
Project-URL: Issues, https://gitlab.com/Mads-Peter/shephex/-/issues
Project-URL: Changelog, https://gitlab.com/Mads-Peter/shephex/-/blob/master/CHANGELOG
Author-email: Mads-Peter Verner Christiansen <mpvc@bio.aau.dk>
License-Expression: GPL-3.0-or-later
License-File: LICENSE
Keywords: computational science,experiments,hpc,parameter sweep,slurm
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: System :: Distributed Computing
Requires-Python: >=3.11
Requires-Dist: click>=8.2.0
Requires-Dist: dill>=0.3.8
Requires-Dist: littletable>=3.0.0
Requires-Dist: rich-click>=1.8.9
Requires-Dist: rich>=13.7.1
Requires-Dist: shortuuid>=1.0.13
Description-Content-Type: text/markdown

# Shephex

[![PyPI](https://img.shields.io/pypi/v/shephex)](https://pypi.org/project/shephex/)
[![Python versions](https://img.shields.io/pypi/pyversions/shephex)](https://pypi.org/project/shephex/)
[![License: GPL-3.0-or-later](https://img.shields.io/badge/license-GPL--3.0--or--later-blue)](https://gitlab.com/Mads-Peter/shephex/-/blob/master/LICENSE)
[![Docs](https://img.shields.io/website?url=https%3A%2F%2Fmads-peter.gitlab.io%2Fshephex%2F&up_message=online&down_message=offline&label=docs)](https://mads-peter.gitlab.io/shephex/)
[![Coverage](https://gitlab.com/Mads-Peter/shephex/badges/master/coverage.svg)](https://gitlab.com/Mads-Peter/shephex/-/pipelines)

Shephex creates, runs and manages computational experiments in Python. Decorate a
function, create experiments with the parameters you want, and Shephex gives every
experiment a directory of its own and runs them locally or as Slurm array jobs, on
the cluster you are logged in to or a remote one over ssh.

**[Documentation](https://mads-peter.gitlab.io/shephex/)** · [Getting started](https://mads-peter.gitlab.io/shephex/getting_started/) · [Examples](https://mads-peter.gitlab.io/shephex/examples/) · [Changelog](https://gitlab.com/Mads-Peter/shephex/-/blob/master/CHANGELOG)

## Features

- Every experiment gets its own directory with its parameters, status and result.
- Runs experiments locally, or as Slurm array jobs on the cluster you are logged in to or
  a remote one over ssh.
- Executes experiments in Singularity/Apptainer containers or virtual environments on the
  cluster.
- `hex report` follows experiments from the terminal, with filters and the progress
  experiments report themselves.
- Safeguards for submissions, also by AI agents: dry runs, limits and confirmation of
  large submissions.

## Installation

```
pip install shephex
```

On a cluster, Shephex can also be installed as a standalone tool with
`uv tool install shephex`, and experiments run in a container or environment of their own,
see [Installation](https://mads-peter.gitlab.io/shephex/installation/).

## Example

The example submits 30 experiments of a random walk, every combination of `steps`, `bias`
and `seed`, to a Slurm cluster as a single array job.

```python
import shephex


@shephex.hexperiment()
def random_walk(steps: int, bias: float, seed: int) -> float:
    import numpy as np  # Only needed where the experiments run.

    rng = np.random.default_rng(seed)
    moves = rng.choice([-1, 1], size=steps, p=[1 - bias, bias])
    return float(moves.sum())


if __name__ == '__main__':
    experiments = [
        random_walk(steps=steps, bias=bias, seed=seed)
        for steps in [100, 1_000, 10_000]
        for bias in [0.5, 0.6]
        for seed in range(5)
    ]

    executor = shephex.SlurmExecutor(partition='q48', ntasks=1, time='00:10:00')
    executor.execute(experiments)
```

`hex report` shows the status and parameters of the experiments while they run, here
filtered to some of them:

```
$ hex report experiments -f bias 0.6 float -f steps 10000 int
                        experiments
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━┓
┃       Identifier       ┃  Status   ┃ steps ┃ bias ┃ seed ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━┩
│ DMRnu7L7G3HTsFfWKXxyPT │ Completed │ 10000 │ 0.6  │  0   │
│ V2JQcRFgS22A3R9UroFMHf │ Completed │ 10000 │ 0.6  │  1   │
│ DYEGgrCFMkwaTgQYDuS4Yz │ Completed │ 10000 │ 0.6  │  2   │
│ Cf5z7hR3pA3jyrmapDmqCa │ Completed │ 10000 │ 0.6  │  3   │
│ KKJ7o35KtrrrZ95ywL29kn │ Completed │ 10000 │ 0.6  │  4   │
└────────────────────────┴───────────┴───────┴──────┴──────┘
5 completed / 5 shown of 30
```

## Learn more

- [Getting started](https://mads-peter.gitlab.io/shephex/getting_started/): experiments, results, Slurm, containers,
  environments and remote clusters, one step at a time.
- [Examples](https://mads-peter.gitlab.io/shephex/examples/): complete, tested scripts, e.g. parameter sweeps, external
  programs and remote clusters.
- [Using Shephex with AI agents](https://mads-peter.gitlab.io/shephex/getting_started/agents/): how Shephex keeps agents'
  submissions in check.
- [API reference](https://mads-peter.gitlab.io/shephex/reference/shephex/).

## License

Shephex is licensed under the GNU General Public License v3.0 or later, see
[LICENSE](https://gitlab.com/Mads-Peter/shephex/-/blob/master/LICENSE).
