Skip to main content

Python experiment manager

Project description

runexpy - Experiment manager GitHub Workflow Status PyPI

Python library to perform multiple executions of a script with different parameters, manage the results and collect them.

How does it work?

Get you script

Write a script (it can be a Python program or any command line executable) which can take command line parameters in GNU standard, i.e. in the format --arg=value.

The script can print anything on standard output and standard error. Moreover, it can produce any file in the current working directory, e.g. output.txt can contain the result computed by the script.

Example of a Python script, e.g. script.py

import random
from argparse import ArgumentParser


def main():
    ap = ArgumentParser("Draw a random number")
    ap.add_argument("--seed", "-s", type=int, required=True)
    ap.add_argument("--lower", "-l", type=float, default=0)
    ap.add_argument("--upper", "-u", type=float, default=1)
    args = ap.parse_args()

    random.seed(args.seed)
    draw = args.lower + random.random() * (args.upper - args.lower)
    with open("output.txt", "w") as f:
        f.write(str(draw))


if __name__ == "__main__":
    main()

Define you experimental settings

Write a Python script that defines the experiments you want to run.

Example, e.g. experiment.py

from runexpy.campaign import Campaign
from runexpy.runner import SimpleRunner


def main():
    # for a python script
    script = ["python3", "script.py"]
    # for any command-line executable
    # script = "my-program"

    campaign_dir = "campaigns"

    # define the arguments with their default value if any, else None
    default_params = {
        "seed": None,
        "lower": 0,
        "upper": 1,
    }

    c = Campaign.new(script, campaign_dir, default_params)

    runs = {
        "seed": [0, 1, 2],
        "lower": [0, 0.5],
    }
    # equivalent to
    # runs = [
    #     {"seed": 0, "lower": 0,   "upper": 1},
    #     {"seed": 0, "lower": 0.5, "upper": 1},
    #     {"seed": 1, "lower": 0,   "upper": 1},
    #     {"seed": 1, "lower": 0.5, "upper": 1},
    #     {"seed": 2, "lower": 0,   "upper": 1},
    #     {"seed": 2, "lower": 0.5, "upper": 1},
    # ]

    # run the experiments
    runner = SimpleRunner()
    c.run_missing_experiments(runner, runs)

    # parse results
    for result, files in c.get_results_for(runs):
        with open(files["output.txt"]) as f:
            draw = f.read()
        print(
            f"Draw in interval [{result.params['lower']}, {result.params['upper']}]"
            f" with seed {result.params['seed']}: {draw}"
        )
        # print("stdout: ", open(files["stdout"]).read())
        # print("stderr: ", open(files["stderr"]).read())


if __name__ == "__main__":
    main()

Run your experiments

By running your experiment.py, runexpy will create a directory containing all your experiments with the corresponding results and files produced. A database is kept to store all the informations and allow for an easy retrieval of the outputs.

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

runexpy-0.1.0.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

runexpy-0.1.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: runexpy-0.1.0.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for runexpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 744af300fca23f478b9efe160ec03b46950532b54f795e369a0d113cd02eea5f
MD5 d50ff1b25ef376d6068c38cc82cb04ba
BLAKE2b-256 c1d5f3d40b0f31a4a715a0c3874aa80870acd5cfcd64da3396bda095ffe32f27

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: runexpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for runexpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d69843ab2d5d2a1c67be9bf9cf56d1fb90ff476a9b75f4a633926930c4e717e
MD5 851f749e8140235b28298d9049ae4bfc
BLAKE2b-256 d88bb88bd33b0bd1f7fee9a121651d11dd3b63a0c62c34e7ee31a3fa17536b08

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page