Skip to main content

A CLI tool to run the complex experiments

Project description

Hypo is a CLI tool to run OS commands concurrently.

You are tired of running commands one by one manually when the previous command is finished. A lot of commands (maybe experiments) need to run in your project (maybe paper). You want to run them concurrently, without leaving the Free time.

Hypo is a tool to help you run commands concurrently. You can use Hypo to run them concurrently without wasting time. It run your complex commands in System-level. You can easily manipulate the commands in the way you like.

You can install it by pip install hypo-run.

# In the file folder_a/index.py
from hypo import run, Run

@run()
def trial():
    return [Run(command="echo this_is_a_very_complex_prompt_to_start_your_experiment_in_bash", name="indicate your task")]

@run(max_workers=10) # run 10 tasks concurrently
def trial():
    return [Run(command=f"echo {i}", name="echo 0 to 9") for i in range(10)]

Then you can start your task parallel.

# hypo <dir_name> <function_name>

hypo folder_a index.trial # to start method trial. Create tasks, then run.

# if the file named `index.py`, then you can ignore the file name.
hypo folder_a trial # to start method trial. Create tasks, then run.

# if you are already in the folder_a
hypo trial # to start method trial. Create tasks, then run.

Or, directly call the function you need.

trial()
# Then, `python folder_a/index.py`

After running all experiments, you can check the task summary in the output folder named summary.json.

[
  {
    "name": "A very complex task",
    "command": "echo this_is_a_very_complex_prompt_to_start_your_experiment_in_bash",
    "cwd": "/data/Hypothesis/hypo",
    "output": "/data/Hypothesis/hypo/a",
    "datetime": "2024-06-27__18-35-21"
  },
  {
    "name": "Git Version",
    "command": "git rev-parse HEAD",
    "cwd": "/data/Hypothesis/hypo",
    "output": "/data/Hypothesis/hypo",
    "datetime": "2024-06-27__18-35-21"
  }
]

CUDA CMD Friendly

You may have a lot of cuda tasks to do. Run them concurrently! Assume your GPU could have 2 task to run at the same time. cuda_visible_devices will be the environment variable CUDA_VISIBLE_DEVICES pass to processing.

from hypo import run, Run, run_git_checkout
from itertools import product

@run(cuda_visible_devices={0, 1, 6, 7}, max_workers=8) 
def compare():
    cmd_templete = "python main.py --category {clz}"

    clzs = [
        "table",
        "sofa",
        "bench",
        "watercraft",
        # ... a really long list
    ]
    tasks = []
    for clz, method in product(clzs, ["my_method", "baseline", "sota"]): # the method you want to compare
        task = [
            run_git_checkout(method),  # branch name. git checkout to the branch you want to run. 
            Run(
                command=cmd_templete.format(clz=clz),
                name=f"{method}-{clz}",
                cwd="/path/to/your/project",
                out="/summary.json/will/be/generated/here",
            ),
        ]
        tasks.append(task)
    return tasks

You do not need to worry about the run_git_checkout. Python will load all file in memory at the start. Your code will not go wrong.

Extensions

You can use some pre-defined Run. for example, the git version using run_git_status.

from hypo import runs, Run, run_git_status

@runs()
def method():
    return [
        Run(name="a", cwd=".", output="./a", command="echo $cwd"),
        run_git_status(),
    ]

If you want to run the command in a specific git version, you can use run_git_checkout.

from hypo import run, run_git_checkout, Run


@run()
def test_run_git_checkout():
    return [
        [
            run_git_checkout("a6bb0c3"), # commit name
            Run(command="python main.py", output=".", cwd=".", name="run1"),
        ],
        [
            run_git_checkout("main"), # branch name
            Run(command="python main.py", output=".", cwd=".", name="run2"),
        ],
    ]

Progress bar

A progress bar will be shown in the terminal. You can easily check the progress of your tasks. This progress bar will not block the log you printed in the processing.

Under the hood

  • Just use the subprocess.run() to run the command.
  • Use the ThreadPoolExecutor to run the command concurrently.
  • Get the Run object from the queue and assign the command to the ThreadPoolExecutor by max_workers.
  • To avoid the git conflict at the same time, the GlobalResources as the threading lock will be created.

Enjoy it to make the life easier.

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

hypo_run-1.0.1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

hypo_run-1.0.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file hypo_run-1.0.1.tar.gz.

File metadata

  • Download URL: hypo_run-1.0.1.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for hypo_run-1.0.1.tar.gz
Algorithm Hash digest
SHA256 370263157d7b6b4c9d2322ba9f55b8d9394db6a47a287f535cf9ed9459eeb8c4
MD5 d6ab3b6f2e4993ad1b10e51f13dda9f5
BLAKE2b-256 513ba573c2dc3bd58f228d43dc4f176858d5c42044463cf2d90fc04d4cf0d2e4

See more details on using hashes here.

File details

Details for the file hypo_run-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: hypo_run-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for hypo_run-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 933f59fdf9c288dbe92ff9fed98f274b527a4488e8609ee2be4b92af645ca4b5
MD5 2705fbd8acc97d624d68eb6fdf6c28fb
BLAKE2b-256 860a9e887ea6f958f486d323ac699990c03d7c66b1c77574578d0b8198c85093

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