Closed bertiqwerty closed 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.
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:
type
attributes do not match (this is why we need them)validate_smiles
(https://github.com/experimental-design/bofire/blob/86f1220def6dd23e25e2b5b6b7b61cad12960597/bofire/data_models/features/molecular.py#L115) which checks that the categories are valid SMILES strings fails. And this validator uses rdkit to validate the strings, and per default the log level of rdkit is configured in a way that it gives then an error message. Setting the rdkit log level to CRITICAL
as described here: https://rdkit-discuss.narkive.com/6M3hS5nq/suppress-stdout-and-stderr-in-rdkit mutes the error messages.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
Your PR is fine for me and ready to merge ;)
PR to remove depracted pydantic from the tutorials.