Coverage for valmix/run.py: 71%

7 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2026-10-25 09:28 +0000

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3# 

4# SPDX-License-Identifier: Apache-2.0 

5# Copyright 2024 Inria 

6 

7"""Convenience function to run the app directly.""" 

8 

9from multiprocessing.sharedctypes import Synchronized as Value 

10from typing import Dict, Sequence, Tuple 

11 

12from .app import App 

13from .knob import Knob, T 

14 

15 

16def run(tui: Dict[str, Tuple[Value, Sequence[T]]]) -> None: 

17 """Convenience function to run the app directly from the valmix module. 

18 

19 Args: 

20 tui: Dictionary defining the terminal user interface. 

21 

22 A TUI dictionary looks like this: 

23 

24 { 

25 "foo": (mp.Value("f", 10.0), np.arange(0.0, 10.0, 0.5)), 

26 "bar": (mp.Value("i", 2), range(-7, 7)), 

27 } 

28 

29 Each key defines a parameter whose value to tune. Each value (of the 

30 key-value dictionary) is a pair consisting of (1) a multiprocessing Value 

31 instance, holding the actual parameter to tune, and (2) the values the 

32 parameter may take, typically a range for integers or a NumPy linspace for 

33 floating-point numbers. 

34 """ 

35 knobs = [Knob(key, value, values) for key, (value, values) in tui.items()] 

36 App(knobs).run()