Skip to main content

Library to run experiment from argparse or config file with slurm

Project description

runexp

Library to run experiment from argparse or config file with slurm

Examples

argparse

To work with the builtin argparse library, have a look at the file examples/argparse/main.py. The only change required is the line to parse the arguments :

import argparse
from runexp import parse

parser = argparse.ArgumentParser(...)

parser.add_argument(...)

- args = parser.parse_args()
+ args = parse(parser)

# rest of the program, using `args`
time.sleep(5.0)
pprint.pprint(vars(args))

If you don't specify any special options, it's like runexp was never there in the first place.

python examples/argparse/main.py target --string 'a bc' --float 0.1 --no-option --sc

To perform a parameter sweep, you can prefix key-value arguments with sweep- and write all values as a coma separated list. Because dry-run is the default, it will print the command to execute the script and show a description equivalent to what the run would be :

$ python examples/argparse/main.py target --string 'a bc' --sweep-float 0.1,0.2,0.3 --no-option --sc
=== DRY RUN ===
run the command below for an actual execution
python examples/argparse/main.py target --string 'a bc' --sweep-float 0.1,0.2,0.3 --no-option --sc --runexp-no-dry-run
===============
/home/maxime/repos/runexp/.venv/bin/python examples/argparse/main.py target --float 0.1 --no-option --sc --string 'a bc'
/home/maxime/repos/runexp/.venv/bin/python examples/argparse/main.py target --float 0.2 --no-option --sc --string 'a bc'
/home/maxime/repos/runexp/.venv/bin/python examples/argparse/main.py target --float 0.3 --no-option --sc --string 'a bc'

If you want to run this code on a SLURM cluster, you can do it as follows :

$ python examples/argparse/main.py target --string 'a bc' --float 0.1 --no-option --sc --runexp-slurm
=== DRY RUN ===
run the command below for an actual execution
python examples/argparse/main.py target --string 'a bc' --float 0.1 --no-option --sc --runexp-slurm --runexp-no-dry-run
===============

Behavior inconsistance

What should happen if no runexp option is given ?

For the ArgParse case, it makes sense that if no RunExp option is found, nothing happens : RunExp should be minimally intrusive and avoid breaking everything, so args are returned as if RunExp did nothing.

For the ConfigFile case, it is not possible to run the program without RunExp as this is the way to parse the config. If it makes sense to re-use the function, it should be defined elsewhere and the decorator should be used as a function.

Moreover, because the ArgParse function needs to return the namespace, it should exit the process on a dry run, while the ConfigFile currently doesn't.

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

runexp-0.1.4.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

runexp-0.1.4-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file runexp-0.1.4.tar.gz.

File metadata

  • Download URL: runexp-0.1.4.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for runexp-0.1.4.tar.gz
Algorithm Hash digest
SHA256 dedb46e5a0a20dbce8f807e3f68b395c31320d4df18809457f16826db6abcacd
MD5 85b2098b04ee9a3a26be612a4127526f
BLAKE2b-256 cb93fb848233b50828f511da8321028c1c1dafdb045e3b0ae0ecaa0499396074

See more details on using hashes here.

File details

Details for the file runexp-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: runexp-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for runexp-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5258bfc2f20187629810f68c6bfc453bdb7ecfcf59c40736beca97027d085796
MD5 5ab90bf38a01ae8453ac89d19d5a0862
BLAKE2b-256 dad91bfd506bee5cb9462d2f23c4cb669ee7c8c98e7a6a0e1d29b6b9e602f281

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