![](https://private-user-images.githubusercontent.com/1189580/331527890-280c02b9-46a4-4a61-bb42-3befd1c59879.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYzNTY5NjcsIm5iZiI6MTcxNjM1NjY2NywicGF0aCI6Ii8xMTg5NTgwLzMzMTUyNzg5MC0yODBjMDJiOS00NmE0LTRhNjEtYmI0Mi0zYmVmZDFjNTk4NzkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDUyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA1MjJUMDU0NDI3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MmUzOTFmNWYyMGFmZjM0MTRjNmI2YjY1NjFhOGUzNjIxNGFmMzkwNjAxYmQ2MjNjMGQ5ZWIxZTFkZGJlMzI1OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.UzwfqC3RISLuK9b-rc3sYJrOlc4ZbszeaRe7fau2hxE)
Valmix ("value mixer") gives a systematic way to tune Python program parameters from your terminal (similar to alsamixer
for Linux users familiar with it). Wrap your parameters in multiprocessing
values, pass them to both your program and valmix.run()
, and a terminal user interface will appear 🪔 allowing you to modify parameters in real time while your program is running.
Code is shorter than words in Usage below 😉
conda install -c conda-forge valmix
pip install valmix
Suppose you have a Python program with parameters you want to tune:
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:
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:
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:
# 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:
Useful for instance to tune robot behaviors in real-time 😉
Related software:
- Textual: terminal user interface (TUI) framework for Python, used to build this tool.