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

To install the run module, call pip install . from the root directory of this repository. 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.

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.7.tar.gz (9.7 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.7-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: run_experiments-1.0.7.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for run_experiments-1.0.7.tar.gz
Algorithm Hash digest
SHA256 8797c462311b5ab3aeecf6a310ac9f213a9f794b8015eb83c58748d8f87f4620
MD5 d518e1ae3e86a55f564887dc04a3eb35
BLAKE2b-256 d2713b472e865f5f556b20c9fba02df2c2b77a3fa49907fe091ebcc954d30999

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for run_experiments-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bca72b4fe78090f91f530fa129af18495cd66ba01979f24b1ba9762e71b1b709
MD5 e776a854574182cb722b24eba3b0b34c
BLAKE2b-256 c783e79c9d15b40919fa8bf47578cf2e82795adeaea69d96679fd8666936acd3

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