-
Notifications
You must be signed in to change notification settings - Fork 404
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
Feature/non linear q #1793
Feature/non linear q #1793
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1793 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 170 170
Lines 14773 14920 +147
==========================================
+ Hits 14773 14920 +147
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Nice.
An example would be great. I wonder if a short-but-sweet mini-tutorial for parameter constraints (incl. a simple linear constraint and e.g. more complicated NChooseK constraints) would make sense?
I think it may just have been something we didn't test / weren't sure about when we first added the experimental support for nonlinear constraints. |
So you recommend a small jupyter notebook within |
Yes, I think that would be great. Maybe a simple synthetic function and then show a few different ways to optimize an acquisition function subject to parameter constraints (both linear and nonlinear). No need to make a full Bayesian Optimization loop out of it. |
Ok, sounds good. Do you want to have it as part of this PR, or specific one? |
Small update on this PR, we should not yet merge it. It looks that it was somehow by coincidence that the non-linear constraint was fulfilled for q>1. In more elaborate experiments, I found that this is not always the case. I have to dig there a bit deeper ;) |
If you can do it as part of this PR that would be great (also as a test plan). But if you’d like to get this in soon and need some more time to put together the tutorial that’s fine, too. Thanks! |
Could be that it takes a bit longer, let's see. I overlooked something, but now found out what it was, which is already an advance ;) |
The point is the following: Just commenting out applies the constraint over the flattened q-batch, which means the constraint is applied inter-point wise, but we want to have it always as intra-point, or do we want to have options for both? I would say, always go for intra-point is sufficient. |
Hmm and the additional complexity compared to the linear constraints is that there is no standardized interface for passing in intra- or inter-point constraints, right? And we'd like to make it easier for folks to apply a nonlinear constraint that's defined for a single element of the domain to all elements of a q-batch, right? I think then restricting to intra-point should be ok, so long as we make clear in the docstring that that's the restriction. |
Other option would be to change the signature of the nonlinear constraints from |
Hmm that's an interesting idea as well. I guess this is a rather advanced feature so I wouldn't be too worried about the interface being a bit clunkier, so that sounds good to me if we think that there will be use cases for non-linear inter-point constraints. |
One can come up with use cases, the question is how realistically they are. But, in general I think it is good to keep it as flexible as possible, I will try to implement it as described above. |
I found some time to implement the prototype of what I had in mind. This script tests it on the 6dim Hartmann, with NChooseK. Most of the times it seems to work but sometimes it returns candidates where the constraint eval leads to values that are substantially smaller than zero. Not sure what is going on there:
|
Interesting; I'll take a look. |
I looked into this a bit, and every time the constraints are infeasible it's b/c
or
There also seem to be some failures that don't result in infeasible candidates, but those are rare. haven't figured out what's going on exactly, but this simply seems to be due to the optimization not terminating properly. Out of 100: |
Hi Max, thanks for investigating this. So how to proceed? Is the proposed solution fine for you? Should we remove the old solution which was somehow able for interpoint constraints or keep it and give the user the possibility to toggle between them? Best, Johannes |
Hi Max, any opinion to the question from above? Best, Johannes |
Sorry, I missed this. Yeah, let's give the user the possibility to toggle between inter-point and intra-point constraints. |
@jduerholt checking in on the status of this - are you still planning on merging this in? Anything needed from our end at this point? |
Hi Max, it is still on my menu. I hope to get it finalized in November. There were a lot of other things to do, so I had to reprioritize ... |
No worries, looking forward to it :) |
Hi @Balandat, I think I am done with all your suggestions. You can have a look again. Best, Johannes |
@Balandat has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
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.
Thanks. Mostly cosmetic changes, once those are in I'm happy to merge this
test/generation/test_utils.py
Outdated
_flip_sub_unique, | ||
_remove_fixed_features_from_optimization, | ||
) | ||
from botorch.utils.testing import BotorchTestCase, MockAcquisitionFunction | ||
|
||
|
||
class TestGenerationUtils(BotorchTestCase): | ||
def test_convert_nonlinear_inequality_constraints(self): | ||
for dtype in (torch.float, torch.double): |
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 think you need to test for different dtype
s here? Not used right now...
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.
I think it is not needed, as I am not doing anything with tensors here, so I removed it.
Co-authored-by: Max Balandat <Balandat@users.noreply.github.com>
@Balandat has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
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.
Many thanks!
Summary: <!-- Thank you for sending the PR! We appreciate you spending the time to make BoTorch better. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to BoTorch here: https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md --> ## Motivation When implementing the possibility to use `q>1` for nonlinear constraints in PR #1793, I forgot to update the `batch_limit` check when commenting the check back in. Thus, the feature is still not usable. Here, it is fixed and it is actually tested that it is working with `q>1`. Before, only the lower level methods were tested with `q>1`, but not `optimize_acqf`. This demonstrates again, that one cannot write to less tests :D cc: Balandat ### Have you read the [Contributing Guidelines on pull requests](https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md#pull-requests)? Yes. Pull Request resolved: #2168 Test Plan: Unit tests. Reviewed By: saitcakmak Differential Revision: D52786447 Pulled By: Balandat fbshipit-source-id: 58d5eb2da4298849bdd97aec92eb96c363ef87e0
Summary: <!-- Thank you for sending the PR! We appreciate you spending the time to make BoTorch better. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to BoTorch here: https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md --> ## Motivation When implementing the possibility to use `q>1` for nonlinear constraints in PR pytorch#1793, I forgot to update the `batch_limit` check when commenting the check back in. Thus, the feature is still not usable. Here, it is fixed and it is actually tested that it is working with `q>1`. Before, only the lower level methods were tested with `q>1`, but not `optimize_acqf`. This demonstrates again, that one cannot write to less tests :D cc: Balandat ### Have you read the [Contributing Guidelines on pull requests](https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md#pull-requests)? Yes. Pull Request resolved: pytorch#2168 Test Plan: Unit tests. Reviewed By: saitcakmak Differential Revision: D52786447 Pulled By: Balandat fbshipit-source-id: 58d5eb2da4298849bdd97aec92eb96c363ef87e0
Summary: Legacy non-linear inequality constraint format has been deprecated since pytorch#1793. Differential Revision: D66003879
Summary: Legacy non-linear inequality constraint format has been deprecated since pytorch#1793. Reviewed By: esantorella Differential Revision: D66003879
Summary: Legacy non-linear inequality constraint format has been deprecated since pytorch#1793. Reviewed By: esantorella Differential Revision: D66003879
Summary: Legacy non-linear inequality constraint format has been deprecated since pytorch#1793. Reviewed By: esantorella Differential Revision: D66003879
Summary: Legacy non-linear inequality constraint format has been deprecated since pytorch#1793. Reviewed By: esantorella Differential Revision: D66003879
Motivation
This PR adds the possibilities of q>1 for optimizing acqfs with nonlinear constraints. I just removed the blocking of q>1 in
gen_candidates_scipy
and tested it with NChooseK constraints. It worked. So I am wondering, why it was blocked originally. Any idea?I can also provide an example showing that it works.
Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
Unit tests.