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

removed deprecation from strategies serialization #375

Closed bertiqwerty closed 4 months ago

bertiqwerty commented 4 months ago

PR to remove depracted pydantic from the tutorials.

bertiqwerty commented 4 months ago

Hey @jduerholt, I noticed a strange output when deserializing. It still creates the datamodel, though. It seems to misinterpret the Hyperparameter-config of the surrogate? Not sure. This also happened with the deprecated code.

https://github.com/experimental-design/bofire/blob/374-deprecated-pydantic-in-tutorials/tutorials/strategies_serial.ipynb

image

jduerholt commented 4 months ago

Hi @bertiqwerty ,

@jkeupp mentioned this also to me, and I know what is happenign and how to get rid of the error messages.

A minimal working example to reproduce it is this:

from pydantic import TypeAdapter
from bofire.data_models.features.api import CategoricalInput, AnyFeature

feat = CategoricalInput(key="a", categories=["a","b"])
TypeAdapter(AnyFeature).validate_python(feat.model_dump())

When deserializing, pydantic is trying all data models given to the respective TypeAdapter here AnyFeature which is a union of a set of data models and tries if the serialized dictionary keys matches the fields in the data model. If it matches it tries to instantiate. CategoricalMolecularInput and CategoricalInput have exactly the same field names, so it tries to instantiate CategoricalMolecularInput with the deserialized version of the CategoricalInput and it fails for two reasons:

My proposal to solve the issue would be to create a file logging.py in which we check if rdkit is installed and if yes we set the rdkit logger to a default global value, which would be CRITICAL. The same, I would do for botorch, than we have one place in which we control the loglevel of the libs on which we depend.

In addition, I would create also a bofire logger in logging.py, which is something that I wanted to have already for a longer time as it could be helpful in some scenarios.

If fine for you, I can file a PR for this ;)

Best,

Johannes

jduerholt commented 4 months ago

Your PR is fine for me and ready to merge ;)