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

Uploaded Python 3

File details

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

File metadata

  • Download URL: shephex-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a4e923ff8af0d860ce28948dbe05c20b423242688a97a806ca09447a396f3faf
MD5 b1429c5933ebd35f6772db485de921de
BLAKE2b-256 27f2c3067d90f9d8b71481793c65f93b7b01955c93e57769947ce7262e96e3fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shephex-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f11bb0b7898c9d06134bef6bb5d58ceeeaf4a0452cb0369a9f18070f88f30960
MD5 e462875b296f7e586a5fa5595f006bde
BLAKE2b-256 46cffb30e0210c0e52e0fde5f5ed311b58930d5970e57a9a6356b5ed86fd0000

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