Gradient-Free-Optimizers icon indicating copy to clipboard operation
Gradient-Free-Optimizers copied to clipboard

[MNT] isolate `scikit-learn`

Open fkiraly opened this issue 7 months ago • 3 comments

I think we should make scikit-learn an optional dependency of gfo.

Otherwise, currently, hyperactive depends on gfo, and gfo on scikit-learn, making it a required dependency - even though it is used only in a small number of places.

This PR "isolates" scikit-learn in the sense that:

  • imports do not happen on module level where possible
  • scikit-learn is installed as a test dependency instead of as a core dependency

Also does some other minor things:

  • remove unused imports

fkiraly avatar Jun 14 '25 16:06 fkiraly

This would lead to a worse "out of the box" experience for the user, since using these optimizers will raise an error if sklearn is not already installed, right? Sklearn is not an optional dependency, but is (at the moment) required for the use of the supported optimization algorithms of this package. But to minimize dependencies I started to natively implement the required estimators in this module: https://github.com/SimonBlanke/Gradient-Free-Optimizers/tree/master/src/gradient_free_optimizers/_estimators

This way sklearn can be a true optional dependency.

SimonBlanke avatar Jul 31 '25 01:07 SimonBlanke

This would lead to a worse "out of the box" experience for the user, since using these optimizers will raise an error if sklearn is not already installed, right?

Hm, yes, if we move scikit-learn to the optional dependency set, you are right.

However, if we do not change pyproject.toml, I believe nothing would change from the user perspective? Only the imports are more restricted, and no scikit-learn imports happen on module level anymore.

fkiraly avatar Jul 31 '25 05:07 fkiraly

However, if we do not change pyproject.toml, I believe nothing would change from the user perspective? Only the imports are more restricted, and no scikit-learn imports happen on module level anymore.

yes, this will work fine.

SimonBlanke avatar Aug 02 '25 13:08 SimonBlanke