.. _confgurable-utilities: Configurable utilities ----------------------------------------------- We offer a set of utilities that can be used to define more complex configurable functions. .. _choice-parameter: The *Choice* parameter ~~~~~~~~~~~~~~~~~~~~~~ The *Choice* parameter can be used to specify that a parameter can take different types. For example: .. code:: python :number-lines: from optilog.tuning import ac, Int, Real, Choice @ac def func( data, seed, n: Choice(Int(-7, 8, default=3), Real(0.1, 4.8, default=1.0)) = Int(-7, 8, default=3), ): if isinstance(n, int): # Some computation considering 'n' as an int ... if isinstance(n, float): # Some computation considering 'n' as an int ... Another possible usage is the definition of more complex ranges for parameters. For example, in the following function parameter *n* can take values of the range [-10, 10] U [20, 25]. .. code:: python :number-lines: from optilog.tuning import ac, Int @ac def func( data, seed, n: Choice(Int(-10, 10, default=0), Int(20, 25, default=20)) = Int(-10, 10, default=0), ): ... A *Choice* parameter can be also be used to choose from different configurable functions. This will properly handle the parameters that correspond to each function. .. code:: python :number-lines: from optilog.tuning import ac, CfgCall, Choice @ac def func( data, seed, fn: Choice(CfgCall(func1), CfgCall(func2)) = CfgCall(func1), ): val = fn(data, seed) ... *Choice* also supports more than two domains and inline default. .. code:: python :number-lines: R1 = Int(3, 10, default=5) R2 = Int(5, 30, default=20) R3 = Int(80, 100, default=90) @ac def func( data, seed, x: Choice(R1, R2, R3, default=R1) ): ... More generally, *Choice* accepts any number of arguments of *any domain*. The *Choice* type will automatically handle the specified options. In particular, it will provide to the AC tool all needed constraints to correctly configure a *Choice* parameter. .. note:: *Choice* allows for efficient optimization of parameters on composite domains. These optimizations generate constraints that the AC tool can use to optimize more efficiently.