-
Notifications
You must be signed in to change notification settings - Fork 47
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
Rework validation for measurements
and pending_experiments
#456
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Scienfitz, thanks the refactor 🏗️ Below my comments
0a42492
to
a412305
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
7056db6
to
969dea4
Compare
After a pause I reanalzyed the outstanding issues here:
Solution Proposal:
|
baybe/campaign.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Scienfitz, turning this into a threaded discussion for easier communication:
Regarding the two points you mentioned:
-
I'm afraid the suggested solution with
numerical_measurements_must_be_within_tolerance
fixes the problem from the wrong angle, tbh. IMO, a clean solution requires fixing Refactoring out-of-range and tolerance mechanism #428 first. If you think about it: it really doesn't make much sense to impose any user restrictions onmeasurements
andpending_measurements
in terms of tolerances (yes: for our internal tracking of metadata, we can do whatever we think is reasonable) because the measurements are really already there / currently in progress. So what's even the point of validating them? That would be likeUser says: I've already collected some data
butBaybe says: Nope!
😄 Validation that the data is compatible with the parameters in the first place is a different story, of course, but that's part 2 then. What do you think? -
Agree, we need a mechanism that the campaign can "inform" the recommender that data has already been validated. There are really a lot of different ways how we could do this, here just some of them, which can potentially also be combined:
- Adding a (private) flag to
Recommender.recommend
- Wrapping the call inside campaign into a context manager
- Use a separate validation manager (i.e. an object that keeps track of which objects have been already validated) to decouple it entirely from campaign/recommender
- Use some clever form of dataframe wrapper
- Adding a (private) flag to
The advantage of the latter three would be that no API change is required. I don't have a clear opinion yet but right now I'd go with the wrapper or the context manager. And perhaps one comment because I can anticipate objections against the wrapper: Note that could be as slim as just subclassing pd.DataFrame
into ValidatedDataframe
, nothing else. So no API change involved – the recommender would only require do to a simple isinstance
check. What do you think? Whatever we do, it'd be good if this stays completely behind the scenes in case we notice problems later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
we certainly dont need to tangle issues more than they are already. Essentially you are opening an entirely new question
does requiring measurements being inside allowed toelrances even make sense?
. This PR does not aim at answering this, instead, for consistency I was assuming that recommenders must also allow this choice because the campaign already allows it. If the answer isno
then the whole problem is greatly simplified and the calls inside recommenders just happens withnumerical_measurements_must_be_within_tolerance=False
always. If theres an update to that it can be changed again, again tis PR aims at fixing Pending experiments with CustomDiscreteParameter value not in search space gives cryptic error #453 (coming from disallowed values not related to tolerances) and not Refactoring out-of-range and tolerance mechanism #428 (dealing with disallowed values due to tolerances) -
Don't get the
private flag
? Do you mean an private attribute to the class or the proposed argument? Prefer the context manager out of the other variants but havent implemented yet (any hint or link how to do it?). Reject last two points as overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Don't know your opinion yet, but I think the answer should be
no
. And therefore I think we don't even need to handle it in this PR + it should be fixed/removed in the Campaign in another PR to solve Refactoring out-of-range and tolerance mechanism #428. -
The "private flag" would be something like adding
_validate_measurements
toRecommender.recommend
, which I don't like so much. Of course, one could also add it as a "regular" flag but this is really something the user should not need to bother and adding the flag in any form definitely adds some noise to the API. Below a rough sketch of how I could envision the other alternatives.
Wrapper
Even if you don't like the wrapper, it could be a quick temporary (internal) fix until we have the perhaps cleaner approach with the context manager set up. I would probably be as simple as:
class ValidatedDataframe(pd.DataFrame):
pass
Then, at the point in the campaign where the validation happens, either the campaign or the validating function would need to set df.__class__ = ValidatedDataframe
and then the recommender would only trigger validation in an if not isinstance(df, ValidatedDataframe)
condition.
Context Manager
Potentially cleaner but requires some external settings
mechanism to keep track of the state. This is definitely something that we should set up anyway for all sorts of other flags as well, like polars
, single_precision
etc. I have some ideas how to do this nicely in the long run, but for now a quick'n'dirty internal(!) solution would also do the job. Would look like
with settings.validate_user_data(False):
recommender.recommend(...)
And then inside recommender you have the corresponding check reading the global flag maintained by the settings object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: In the long run, the settings approach of course has additional benefits, e.g. when can easily integrate this with environment variables so that you can flexibly control the settings from within and outside python, regardless of the specific context you're in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I see the wrapper is probably much better given we have no settings at the moment. Will try, ty.
Besides, I think we are talking about a situation where I want to know whether a df has already been validated. This does not really conform to the meaning of a setting
or at least we then have to distinguish whether inputs are checked for validity from them being checked for numerical tolerance match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AdrianSosic ok Ive added the wrapper suggestion in the last two commits + rebased the branch. It seems to work out of the box
Co-authored-by: AdrianSosic <adrian.sosic@merckgroup.com>
f2b383f
to
7c2b551
Compare
Fixes #453
Notes re
measurements
validationadd_measurements
andfuzzy_row_match
fuzzy_row_match
does not perform any validation anymoreadd_measurements
now simply calls the utilitiesNotes re
pending_experiments
validationpending_experiments
has been addedRemaining problem:
The places of validation for
measurements
andpending_experiments
are inconsistent. The former is done in the campaign and not in any recommender, the latter is not done in the campaign but done in the recommender. One of the issues is thatnumerical_measurements_must_be_within_tolerance
is not available for recommenders, but its required for the parameter input validation.Suggestion:
Imo we dont want to add more keywords to
.recommend
or so, hence thepending_experiments
validation currently assumesnumerical_measurements_must_be_within_tolerance=False
and cannot be configured otherwise. To me it seems the simplest solution would be to completely get rid of anynumerical_measurements_must_be_within_tolerance
keywords and make it an environment variable, we wouldn't have to worry about its availability anymore and it would require adding it to more and more signatures.