experimental-design / bofire

Experimental design and (multi-objective) bayesian optimization.
https://experimental-design.github.io/bofire/
BSD 3-Clause "New" or "Revised" License
155 stars 20 forks source link

Implement generic typing in Features #383

Closed TobyBoyne closed 3 months ago

TobyBoyne commented 3 months ago

Implements generic typing for Features.

Currently, the dynamic typing for Features, Inputs, and Outputs doesn't work well with pyright. There are many # type: ignores in the codebase, such as shown below, to address this. However, a solution that does work with pyright is generic typing. With this PR, you can remove these comments and the type checker is still happy. The API for interacting with Features, Inputs, and Outputs remains unchanged,

https://github.com/experimental-design/bofire/blob/0efb4685ce72c163a44e0f1fdc325ce191dda31d/bofire/data_models/strategies/predictives/botorch.py#L198

TobyBoyne commented 3 months ago

This should fail the typechecking pipeline, due to an error spotted by pyright below. I believe this is because this PR has highlighted an issue with the Output class, which does not define an Output.objective attribute by default. However, all classes that subclass it do define an objective.

https://github.com/experimental-design/bofire/blob/0efb4685ce72c163a44e0f1fdc325ce191dda31d/bofire/data_models/strategies/predictives/predictive.py#L29