Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor surrogates and decorators #209

Merged
merged 28 commits into from
May 2, 2024
Merged

Refactor surrogates and decorators #209

merged 28 commits into from
May 2, 2024

Conversation

AdrianSosic
Copy link
Collaborator

@AdrianSosic AdrianSosic commented Apr 18, 2024

This PR refactors our surrogate package, which significantly removes boilerplate/workaround code and solves several longstanding issues:

  • The catch_constant_targets and scale_model decorators have been drastically reduced/improved. Most importantly, they no longer cause problems in the subclass hierarchy, which allows us to remove many ugly workarounds with serialization hooks, the docs, typing, ...
    Note: Potentially the scale_model decorator might vanish entirely when refactoring scaling, but this already serves as a preparation as the decorator can now be cleanly removed without other side-effects.
  • The corresponding code and doc workarounds have been fixed
  • The _model attribute has been pulled up the base class and is now correctly handled in serialization and equality checks.

@AdrianSosic
Copy link
Collaborator Author

Hi @AVHopp, @Scienfitz, this PR sits on top of another, so let's wait with the review until the other is merged.

baybe/surrogates/base.py Outdated Show resolved Hide resolved
@AdrianSosic AdrianSosic force-pushed the refactor/decorators branch from 339b15c to 3784326 Compare April 23, 2024 14:50
@AdrianSosic
Copy link
Collaborator Author

@AVHopp @Scienfitz: now that #206 is merged, have rebased and is ready for review 🚀

Copy link
Collaborator

@AVHopp AVHopp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for that PR :) I have some comments, but nothing too serious.

baybe/surrogates/base.py Outdated Show resolved Hide resolved
baybe/surrogates/base.py Outdated Show resolved Hide resolved
baybe/surrogates/base.py Outdated Show resolved Hide resolved
baybe/surrogates/base.py Show resolved Hide resolved
baybe/surrogates/naive.py Outdated Show resolved Hide resolved
baybe/surrogates/utils.py Show resolved Hide resolved
baybe/surrogates/utils.py Outdated Show resolved Hide resolved
baybe/surrogates/random_forest.py Show resolved Hide resolved
examples/Basics/recommenders.py Show resolved Hide resolved
baybe/surrogates/naive.py Show resolved Hide resolved
baybe/surrogates/utils.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@AVHopp AVHopp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might need some in-person discussion about some stuff since I am not sure if I understand your arguments and disagree with them.

baybe/surrogates/base.py Show resolved Hide resolved
baybe/surrogates/base.py Outdated Show resolved Hide resolved
baybe/surrogates/utils.py Outdated Show resolved Hide resolved
baybe/surrogates/utils.py Outdated Show resolved Hide resolved
baybe/surrogates/random_forest.py Show resolved Hide resolved
Scienfitz added a commit that referenced this pull request Apr 29, 2024
Some progress towards refactoring the acqf interface and enabling more
advanced acqfs

Done
- removed `debotorchize`
- incldued some new acqfs, see CHANGELOG
- enable iteration tests with all acqfs
- extended hypothesis tests

Not Done Yet:
- removing `AdapterModel` (does not make sense while #209 is open)

Issues:
- ~~some tests with custom surrogates fail, see separate thread~~
resolved since not using botorch factory anymore
- some of the analytical new acqfs dont seem to work wiht out GP model.
Eg when I implement the `NEI` I get
`botorch.exceptions.errors.UnsupportedError: Only SingleTaskGP models
with known observation noise are currently supported for fantasy-based
NEI & LogNE`. Also the `LogPI` is available in botorch, but it is not
imported to the top level acqf package in botorch, I ignored it here.
~~I included a reverted commit pair so it can be checked out quickly to
reproduce~~
@AdrianSosic AdrianSosic force-pushed the refactor/decorators branch from 530f17c to b3a4572 Compare May 2, 2024 07:35
baybe/surrogates/utils.py Outdated Show resolved Hide resolved
baybe/surrogates/base.py Outdated Show resolved Hide resolved
The old approach was unnecessarily complex and resulted in various
problems (i.e. typing issues, duplication of subclasses, etc).

The new approach simply exchanges the class' methods (and thus modifies
the original class) instead of creating a new one. This requires
significantly less and easier code an avoids the aforementioned
problems.
The reason is the same as for the refactor of catch_constant_targets in
the previous commit.
@AdrianSosic AdrianSosic force-pushed the refactor/decorators branch from b3a4572 to bfad013 Compare May 2, 2024 16:21
@AdrianSosic AdrianSosic merged commit 6a6603d into main May 2, 2024
9 of 10 checks passed
@AdrianSosic AdrianSosic deleted the refactor/decorators branch May 2, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants