Skip to main content

python module for running experiments

Project description

run

A module for running experiments that involve the execution of commands with different combinations of command line arguments.

Goals

This module was written with the follow main goals in mind.

  • Simplicity: Specifying which commands to run with which sets of command line parameters should not be harder than just writing down the command and the sets of parameters. Similarly, reformatting the raw output of a command should not be harder than just writing a function that parses the raw output and returns the reformatted output.
  • Flexibility: There should be enough flexibility to cover many scenarios. This includes reformatting the output in various ways, custom error handling, or restricting the generated parameter combinations. However, flexibility should never be at the expense of simplicity, i.e., if you don't need the flexibility, then its existence should not make your life harder.
  • Parallelization: Tasks should be parallelized automatically.
  • Expandability: It should be easy to expand the experiment setup without having to rerun the existing experiments.
  • Usability: Running the resulting experiment script should be somewhat pleasant. For this, there are some QOL features such as a progress bar, an overview of the existing experiments, or the possibility to run only some of the experiments.

Basic Examples

The following example specifies an experiment with name experiment1 that runs the command mycommand passing it a file name and two parameters. When running the resulting script by calling python example.py experiment1, the command will be executed for all combinations of file ∈ ["file1", "file2", "file3"], param1 ∈ [1, 2, 3, 4], and param2 ∈ [8, 16, 32]. The resulting outputs will be written to the specified files, e.g., the output of the command mycommand file1 -x 1 -y 8 will be written to the file output/file1_x=1_y=8.txt.

# example.py
import run

run.add(
    "experiment1",
    "mycommand [[file]] -x [[param1]] -y [[param2]]",
    {'file': ["file1", "file2", "file3"],
     'param1': [1, 2, 3, 4],
     'param2': [8, 16, 32]},
    stdout_file="output/[[file]]_x=[[param1]]_y=[[param2]].txt"
)

run.run()

The experiment is then run using python example.py experiment1.

If you want to reformat the output before writing it to a file using a function reformat(), which takes a string and returns a string, you can do so by simply adding stdout_mod=reformat to the above example. For more ways to reformat the output and for other features, see the documentation.

Installation

The run module is available on under the name run-experiments. To install it, run:

pip install run-experiments

Alternatively, you can copy the run.py or the whole repository (e.g., as a git submodule) to wherever you use it.

Documentation

The documentation explains everything with a bunch of examples. This is probably the place to start if you want to learn how things work. For quick lookup, also see the reference documentation.

Windows

In principle, things should just work. However, there are some pitfalls.

  • For some reason (related to the fact that Windows does not have fork()), you have to use the if __name__ == "__main__" guard for multiprocessing. Thus, if you want your script to work under Windows, your call to run() should look as follows.

    if __name__ == "__main__":
        run.run()
    
  • You might need to surround the name of the executable with "". So if the command you want to call is, e.g., code/release/algo -x 1 -y 2, you need to write run.add(..., '"code/release/algo" -x 1 -y 2', ...). Without the surrounding "", Windows will call code, which opens VS Code instead of running your algorithm.

Building and Publishing on PyPi

Building uses setuptools as backend (which makes the option py-modules = ["run"] available). Checklist for publishing new version:

  • bump the version in project.toml
  • update CHANGELOG.md
  • run hatch build to build
  • (optional: run hatch publish --repo test dist/*<version>* to publish on test server)
  • run hatch publish dist/*<version>* to publish

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

run_experiments-1.0.8.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

run_experiments-1.0.8-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file run_experiments-1.0.8.tar.gz.

File metadata

  • Download URL: run_experiments-1.0.8.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for run_experiments-1.0.8.tar.gz
Algorithm Hash digest
SHA256 09d499e8a58c5557efac68b6be968ad7a74ed0f668e43fd2417473e2983f3dcb
MD5 f4b67cf3a6c863f57665436d5f5c8e3f
BLAKE2b-256 8a373a1b2aeb616c541b7040e75fee3d7d234d70b1d273a0a68115188b1e33fb

See more details on using hashes here.

File details

Details for the file run_experiments-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for run_experiments-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 bb7f20b04febb14196d873fbf69f8c4e74e1f8150679c736e70f82961eb603f3
MD5 e24d08e2e8e51eace131990fbec05a2b
BLAKE2b-256 6333cb0f7370e74271aac20764f2422d55fbf8b49f95a9913e3b195842339801

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