force-h2020 / force-bdss

Business Decision System general interface
BSD 2-Clause "Simplified" License
2 stars 2 forks source link

Explore making WeightedOptimizerEngine class a mixin #342

Closed flongford closed 4 years ago

flongford commented 4 years ago

We can explore ways to make the WeightedOptimizerEngine class not rely on inheriting from ScipyOptmizerEgine, and rather be a mixin-type object that can sit on top of any BaseOptimizerEngine implementation.

The mixin will need to:

flongford commented 4 years ago

Since #340, the only dependency that WeightedOptimizerEngine has on SciPyOptimizerEngine is via use of the _scipy_optimize method in _weighted_optimize.

We would need to invoke the super().optimize method here (or equivalent) for this to be independent of the parent class. However, the if there are any extra functionalities in _scipy_optimize that are missing from BaseOptimizerEngine, then we will also need to ensure these are present in the base class.

sparsonslab commented 4 years ago

We can explore ways to make the WeightedOptimizerEngine class not rely on inheriting from ScipyOptmizerEgine, and rather be a mixin-type object that can sit on top of any BaseOptimizerEngine implementation.

The mixin will need to:

  • [ ] Overwrite the objective function to include weights on each KPI value returned
  • [ ] Overload the optimize method to iterate through each combination of weights returned by the space sampler, calling the super().optimize method in turn.

Would the goal be something like,

class MyOptimizerEngine(ScipyOptimizerEngine, WeightedOptimizerEngine): pass

where you don't have to implement any methods in MyOptimizerEngine - it just inherits from its bases (ScipyOptimizerEngine and WeightedOptimizerEngine).

In that case those bases should be unrelated: only one inherits from BaseOptimizerEngine and provides the optimize(). The other provides some other interface that optimize calls on. And then you can mix-and-match OptimizerEngine (weighted/etc) and optimizer (scipy/nevergrad).

Does that make sense?

flongford commented 4 years ago

Would the goal be something like,

class MyOptimizerEngine(ScipyOptimizerEngine, WeightedOptimizerEngine): pass

where you don't have to implement any methods in MyOptimizerEngine - it just inherits from its bases (ScipyOptimizerEngine and WeightedOptimizerEngine).

Yes, that would be the idea - or a namespace equivalent:

class WeightedOptimizerEngine(ScipyOptimizerEngine, WeightedOptimizerMixin):
    pass

In that case those bases should be unrelated: only one inherits from BaseOptimizerEngine and provides the optimize(). The other provides some other interface that optimize calls on. And then you can mix-and-match OptimizerEngine (weighted/etc) and optimizer (scipy/nevergrad).

Does that make sense?

Perfect sense (hopefully it's also not too difficult to implement!).