Skip to main content

Computational experiment manager. Execute parameterized Python function on Slurm directly from a python script

Project description

shephex

coverage Website

A Python package for managing and executing computational experiments.

Features

  • Easy management of parameter sweeps
  • Execution of python function or scripts with input sets.
  • Simple SLURM Scheduling from Python.
  • Extendable execution class to adapt to other job management systems.

The example show how easy it is to submit an arbitrary Python function for execution on Slurm. The function in this case is a biased-random walk in 2D for which 50 different parameterizations are submitted and executed.

import numpy as np
import shephex

@shephex.hexperiment()
def biased_random_walk_2d(steps: int, bias_x: float, bias_y: float) -> tuple:
    """
    Simulate a 2D biased random walk and return the final position.
    """    
    # Movement choices: (-1, 1) for left/right (x) and down/up (y)
    moves_x = np.random.choice([-1, 1], size=steps, p=[1 - bias_x, bias_x])
    moves_y = np.random.choice([-1, 1], size=steps, p=[1 - bias_y, bias_y])
    
    final_x = np.sum(moves_x)
    final_y = np.sum(moves_y)
    
    return final_x, final_y  # Return final (x, y) position

if __name__ == '__main__':

    experiments = []
    for steps in [10, 100, 250, 500, 1000]:
        for bias_x in [0.5, 0.6]:
            for repeat in range(5):
                experiments += [biased_random_walk_2d(steps=steps, 
                                                    bias_x=bias_x, 
                                                    bias_y=0.5)]

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

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

shephex-0.2.1.tar.gz (2.9 MB view details)

Uploaded Source

Built Distribution

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

shephex-0.2.1-py3-none-any.whl (53.2 kB view details)

Uploaded Python 3

File details

Details for the file shephex-0.2.1.tar.gz.

File metadata

  • Download URL: shephex-0.2.1.tar.gz
  • Upload date:
  • Size: 2.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for shephex-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c310f7cb5c964b270eec81e1aab83d9b34c68d21ec970e6e665cd19e74cb0800
MD5 9fbed136c9d546b34e46df9bc996343d
BLAKE2b-256 0308284bac43ad5ea75559e6041180018d9210309e1725c9c362c88dbb028472

See more details on using hashes here.

File details

Details for the file shephex-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: shephex-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 53.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for shephex-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61c88bdce29f2865ba6d42d859c438a138449d9432fa7589910ff19c7f28d558
MD5 df332f6ae3a8c4f59f22100ff1fccd24
BLAKE2b-256 1eba6278a5ed4e45df1c5e092e3c9c3bb53c997faa5d2bedf7b13c44d24dfb42

See more details on using hashes here.

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