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.1.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.1.0-py3-none-any.whl (51.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shephex-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 d7d1b4e264a30656d6ca572a668cd174b802692c9d0db934c39b656af0179f01
MD5 16faf95e4b8eb0dd238b5d9bbcc90e5e
BLAKE2b-256 e2765588935dae259531d1a94a173337ad34cfb390fd368e7f5a767c338df205

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for shephex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fb9cb528eac5c09256cb7adab8f8191bc3a5b451ec6e5cbec7de4ceffac98a9
MD5 f630258d763ea62c41d33879dddc4340
BLAKE2b-256 4b7175b403c4b29de29a405f73244224b6d2883065369ec1e5281bfc9c02ff1c

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