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.3.2.tar.gz (84.3 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: shephex-0.3.2.tar.gz
  • Upload date:
  • Size: 84.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for shephex-0.3.2.tar.gz
Algorithm Hash digest
SHA256 6eb771aba7e56a1fa3b7fa079983f0a4bfb11782145c2808bfdf4df7137286af
MD5 f7720d6d74e51a21a0617ac841e3ef4d
BLAKE2b-256 b631313636a46987fb088d86b6e7e55b52f8add647eb8b46a89c1359047452b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shephex-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 53.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for shephex-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f41e3a571c4237151b3c2f7c8982b9cbd889d8651e2a74695798081977447ce0
MD5 9cf90172db8994d008c719716db99866
BLAKE2b-256 77bd116158283efb971bb6612cfede1b5b8f73584cd878a2f00b473416e74bae

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