valmix


Namevalmix JSON
Version 0.0.1 PyPI version JSON
download
home_pageNone
SummaryAdjust numerical values from a terminal user interface.
upload_time2024-05-16 16:12:32
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords multiprocessing value tui user interface
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Valmix

[![Build](https://img.shields.io/github/actions/workflow/status/stephane-caron/valmix/ci.yml?branch=main)](https://github.com/stephane-caron/valmix/actions)
[![Documentation](https://img.shields.io/github/actions/workflow/status/stephane-caron/valmix/docs.yml?branch=main&label=docs)](https://stephane-caron.github.io/valmix/)
[![Coverage](https://coveralls.io/repos/github/stephane-caron/valmix/badge.svg?branch=main)](https://coveralls.io/github/stephane-caron/valmix?branch=main)
[![PyPI version](https://img.shields.io/pypi/v/valmix)](https://pypi.org/project/valmix/)

Adjust numerical values from a terminal user interface.

## Usage

Suppose you have a Python program with parameters you want to tune:

```py
def main(kp: float, kd: float):
    pass  # your code here
```

Valmix gives a systematic way to tune these parameters from the command line. First, wrap your parameters in ``multiprocessing.Value``s:

```py
import multiprocessing as mp

kp = mp.Value("f", 10.0)
kd = mp.Value("f", 1.0)
```

Next, update your program to read from the multiprocessing values. For example:

```py
import numpy as np
import time

def main(kp: mp.Value, kd: mp.Value):
    with open("/tmp/output", "w") as output:
        for _ in range(100):
            u = np.clip(kp.value * 1.0 + kd.value * 0.1, 5.0, 20.0)
            output.write(f"{u}\n")
            output.flush()
            time.sleep(1.0)

```

Finally, run your program and Valmix together, specifying the tuning range for each value:

```py
    # Call the main function in a separate process
    main_process = mp.Process(target=main, args=(kp, kd))
    main_process.start()

    # Display the terminal user interface in this process (blocking call)
    valmix.run(
        {
            "kp": (kp, np.arange(0.0, 20.0, 0.5)),
            "kd": (kd, np.arange(0.0, 10.0, 0.5)),
        }
    )
```

This will fire up a terminal user interface (TUI) where you can tune ``kp`` and ``kd`` while the program runs in the background:

![image](https://github.com/stephane-caron/valmix/assets/1189580/1d50ccf5-9bb2-4a73-95e3-9f3345a91311)

Useful for instance to [tune robot behaviors](https://github.com/upkie/upkie/blob/main/examples/wheeled_balancing.py) in real-time 😉

## Installation

### From PyPI

```console
pip install valmix
```

## See also

Related software:

- [Textual](https://textual.textualize.io/): terminal user interface (TUI) framework for Python, used to build this tool.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "valmix",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "St\u00e9phane Caron <stephane.caron@inria.fr>",
    "keywords": "multiprocessing, value, tui, user, interface",
    "author": null,
    "author_email": "St\u00e9phane Caron <stephane.caron@inria.fr>",
    "download_url": "https://files.pythonhosted.org/packages/d5/a6/34951f1cee414908b352d9ea25b5fca0bcde235d8cb212c341b03b280c08/valmix-0.0.1.tar.gz",
    "platform": null,
    "description": "# Valmix\n\n[![Build](https://img.shields.io/github/actions/workflow/status/stephane-caron/valmix/ci.yml?branch=main)](https://github.com/stephane-caron/valmix/actions)\n[![Documentation](https://img.shields.io/github/actions/workflow/status/stephane-caron/valmix/docs.yml?branch=main&label=docs)](https://stephane-caron.github.io/valmix/)\n[![Coverage](https://coveralls.io/repos/github/stephane-caron/valmix/badge.svg?branch=main)](https://coveralls.io/github/stephane-caron/valmix?branch=main)\n[![PyPI version](https://img.shields.io/pypi/v/valmix)](https://pypi.org/project/valmix/)\n\nAdjust numerical values from a terminal user interface.\n\n## Usage\n\nSuppose you have a Python program with parameters you want to tune:\n\n```py\ndef main(kp: float, kd: float):\n    pass  # your code here\n```\n\nValmix gives a systematic way to tune these parameters from the command line. First, wrap your parameters in ``multiprocessing.Value``s:\n\n```py\nimport multiprocessing as mp\n\nkp = mp.Value(\"f\", 10.0)\nkd = mp.Value(\"f\", 1.0)\n```\n\nNext, update your program to read from the multiprocessing values. For example:\n\n```py\nimport numpy as np\nimport time\n\ndef main(kp: mp.Value, kd: mp.Value):\n    with open(\"/tmp/output\", \"w\") as output:\n        for _ in range(100):\n            u = np.clip(kp.value * 1.0 + kd.value * 0.1, 5.0, 20.0)\n            output.write(f\"{u}\\n\")\n            output.flush()\n            time.sleep(1.0)\n\n```\n\nFinally, run your program and Valmix together, specifying the tuning range for each value:\n\n```py\n    # Call the main function in a separate process\n    main_process = mp.Process(target=main, args=(kp, kd))\n    main_process.start()\n\n    # Display the terminal user interface in this process (blocking call)\n    valmix.run(\n        {\n            \"kp\": (kp, np.arange(0.0, 20.0, 0.5)),\n            \"kd\": (kd, np.arange(0.0, 10.0, 0.5)),\n        }\n    )\n```\n\nThis will fire up a terminal user interface (TUI) where you can tune ``kp`` and ``kd`` while the program runs in the background:\n\n![image](https://github.com/stephane-caron/valmix/assets/1189580/1d50ccf5-9bb2-4a73-95e3-9f3345a91311)\n\nUseful for instance to [tune robot behaviors](https://github.com/upkie/upkie/blob/main/examples/wheeled_balancing.py) in real-time \ud83d\ude09\n\n## Installation\n\n### From PyPI\n\n```console\npip install valmix\n```\n\n## See also\n\nRelated software:\n\n- [Textual](https://textual.textualize.io/): terminal user interface (TUI) framework for Python, used to build this tool.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Adjust numerical values from a terminal user interface.",
    "version": "0.0.1",
    "project_urls": {
        "Changelog": "https://github.com/stephane-caron/valmix/blob/main/CHANGELOG.md",
        "Source": "https://github.com/stephane-caron/valmix",
        "Tracker": "https://github.com/stephane-caron/valmix/issues"
    },
    "split_keywords": [
        "multiprocessing",
        " value",
        " tui",
        " user",
        " interface"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "53cb64668a5a411e5582a3adb708a1a2ef471bdd1cdedbf42355163c2b1b9ddb",
                "md5": "3e52ac5880b017f0792ec385f5b8d6af",
                "sha256": "75e03aa4555a638742e52fc95e18d081df1e2c2cb769b20946e1729bc3d18841"
            },
            "downloads": -1,
            "filename": "valmix-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e52ac5880b017f0792ec385f5b8d6af",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10616,
            "upload_time": "2024-05-16T16:12:30",
            "upload_time_iso_8601": "2024-05-16T16:12:30.546989Z",
            "url": "https://files.pythonhosted.org/packages/53/cb/64668a5a411e5582a3adb708a1a2ef471bdd1cdedbf42355163c2b1b9ddb/valmix-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d5a634951f1cee414908b352d9ea25b5fca0bcde235d8cb212c341b03b280c08",
                "md5": "9cab7e8007822c3017db8406787070e5",
                "sha256": "2b7dc93e70ab7287526e9b8853571e92cc7a7315106a4caef34a28bd39e74e1c"
            },
            "downloads": -1,
            "filename": "valmix-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9cab7e8007822c3017db8406787070e5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 14378,
            "upload_time": "2024-05-16T16:12:32",
            "upload_time_iso_8601": "2024-05-16T16:12:32.754757Z",
            "url": "https://files.pythonhosted.org/packages/d5/a6/34951f1cee414908b352d9ea25b5fca0bcde235d8cb212c341b03b280c08/valmix-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-16 16:12:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stephane-caron",
    "github_project": "valmix",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "valmix"
}
        
Elapsed time: 0.23723s