jansel / opentuner

An extensible framework for program autotuning
http://opentuner.org/
MIT License
381 stars 112 forks source link

OptionalInteger support #147

Open yaroslavsadin opened 3 years ago

yaroslavsadin commented 3 years ago

Hi @jansel

We're working on flags optimization for clang and complex real projects with custom build systems (CMake, GN etc.). We came across a use case where NumericParameter (primitive in terms of opentuner) is not enough to model real parameter behavior and we want to support something like OptionalIntegerParameter. This way we want to support compiler or build system behavior when parameter is not specified at all. We see this as a combination of Boolean and Integer but struggling to implement this with current search techniques interface in a way to utilize search techniques for both primitive and complex parameter. Do you have any suggestion on this?

jansel commented 3 years ago

You have a few options, and could run some experiments to find out what works best. You may want to add a bias to the bool if you don't want half the search space to omit the parameter.

Possible options: 1) Map it to two params (an integer and a bool) as you suggested. You can define a ComplexParameter with a sub_parameters() method that returns a [BooleanParameter, IntegerParameter]. The parent parameter could do nothing, or it could do some normalization (for example, read the sub params values and construct a combined output). It is also a place for you to put custom mutation logic that touches multiple params.

2) Map it to a PrimitiveParameter. The key methods here are get_unit_value() and set_unit_value(), which define a search space between 0.0 and 1.0. One option would be something like 0.0 to 0.1 omits the value, then 0.1 to 1.0 contains all the integers in the valid range (with scaling/rounding).

3) Map it to a ComplexParameter. This option gives the most flexibility, but also leaves the most up to you. The minimum here is to define op1_randomize(), but you could also define many 2 or 3 parent crossover/mutation methods that are search technique specific. Some search techniques (for example BinaryGA) will only use op1_randomize(), others (see PSO techniques) use the more complex options.

Best of luck! I'd be curious to know what you find works the best.