# Configurable utilities

We offer a set of utilities that can be used to define more complex configurable functions.

## The Choice parameter

The Choice parameter can be used to specify that a parameter can take different types. For example:

``` 1from optilog.tuning import ac, Int, Real, Choice
2
3@ac
4def func(
5    data, seed,
6    n: Choice(Int(-7, 8, default=3), Real(0.1, 4.8, default=1.0)) = Int(-7, 8, default=3),
7):
8    if isinstance(n, int):
9        # Some computation considering 'n' as an int
10        ...
11    if isinstance(n, float):
12        # Some computation considering 'n' as an int
13        ...
```

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].

```1from optilog.tuning import ac, Int
2
3@ac
4def func(
5    data, seed,
6    n: Choice(Int(-10, 10, default=0), Int(20, 25, default=20)) = Int(-10, 10, default=0),
7):
8    ...
```

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.

```1from optilog.tuning import ac, CfgCall, Choice
2
3@ac
4def func(
5    data, seed,
6    fn: Choice(CfgCall(func1), CfgCall(func2)) = CfgCall(func1),
7):
8    val = fn(data, seed)
9    ...
```

Choice also supports more than two domains and inline default.

```1R1 = Int(3, 10, default=5)
2R2 = Int(5, 30, default=20)
3R3 = Int(80, 100, default=90)
4@ac
5def func(
6    data, seed,
7    x: Choice(R1, R2, R3, default=R1)
8):
9    ...
```

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.