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.0.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.0-py3-none-any.whl (53.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shephex-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 d1fc10255cd0cc235f428ad07d125f7752c43dc62db4bee886c22e4bb72d0822
MD5 97b59ff03c76faa1f0853b517f60f6a0
BLAKE2b-256 888db11c687b4bdb093ccf74464ac085e30d1dc5f21f3b51b6f0751bbab2b7c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shephex-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74ae15ad7e20cfdab0be1b4ef006ab17dd2f1b6aac3af95e49879276a92bd29b
MD5 370508c6c9ef837bdc4d0afa2b200741
BLAKE2b-256 696bddfd1eec990c2ca3482374c9c6307bf396e3e297c82030fa68dc059e9226

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