Closed StanleyYoo closed 1 month ago
As you said, the standard parameter constraints do not support complex nonlinear constraints. This is for a few reasons, not least that this makes the acquisition function optimization a lot more challenging. It also makes it a lot harder to deal with the parameter transformations that Ax applies under the hood. See https://github.com/facebook/Ax/discussions/1797#discussioncomment-6827496 for a more detailed discussion.
What is the mathematical problem you're trying to solve? Is there a way to express the constraints in other coordinates?
Hi Balandat,
Thanks for your response and the discussion at #1797 is well understood. Then do you have any suggestion to address my issue? the mathematical problem I need to solve is that I only want to confine the SearchSpace
which only satisfy discriminant = b**2 - (4 * a * c) >= 0
requirement. Since otherwise, the sample from the SearchSpace
passed to a next step and they won't work, meaning the entire BO process stopped since the next step yields empty result. The next step only work once real solution exists, i.e. discriminant = b**2 - (4 * a * c) >= 0
. I have thinking about including 'discriminant' together with other parameters, x00, x01, x02, x03, x04 and x05
at SearchSpace
but it hasn't worked since there is no correlation between 'discriminant' and others. If you have any idea to resolve this or even discarding/abandon a sample which are not satisfy the criteria discriminant = b**2 - (4 * a * c) >= 0
, please let me know!
We've recently deprecated discussions, which unfortunately killed @Balandat's link above. For posterity I'm copying the question and answer this refers to here.
Question from Stefan2016 on Aug 25, 2023
Dear all,
I have read in the Botorch repo that nonlinear constraints are now possible. From my understanding this should now also be possible with Ax, is this correct?
E.g.,
x^2 + y^2 ≤ 25
as aparameter_constraints
the following code?ax_client.create_experiment( name="hartmann_test_experiment", parameters=[ { "name": "x1", "type": "range", "bounds": [0.0, 1.0], "value_type": "float", # Optional, defaults to inference from type of "bounds". "log_scale": False, # Optional, defaults to False. }, { "name": "x2", "type": "range", "bounds": [0.0, 1.0], }, { "name": "x3", "type": "range", "bounds": [0.0, 1.0], }, { "name": "x4", "type": "range", "bounds": [0.0, 1.0], }, { "name": "x5", "type": "range", "bounds": [0.0, 1.0], }, { "name": "x6", "type": "range", "bounds": [0.0, 1.0], }, ], objectives={"hartmann6": ObjectiveProperties(minimize=True)}, parameter_constraints=["x1 + x2 <= 2.0"], # Optional. outcome_constraints=["l2norm <= 1.25"], # Optional. )
Answer from Balandat on Aug 25, 2023
HI @Stefan2016, unfortunately this is currently not easily possible. The string representations passed to the
parameter_constraints
arg are parsed internally into affine constraint objects, for which the coefficients and rhs are being passed down to the botorch models. This currently does not support nonlinear expressions. The main difficulties here are
- To use this in the optimization, we need to construct a callable that we can pass to the optimizer (with the default settings this would be the optimizers in
scipy.optimize
that are expected to map numpy arrays to numpy floats). It's hard to do that without allowing something like python'seval()
(which we want to avoid) or do some reasonably bespoke string parsing. Another option would be to direcly pass that callable, but that has issues as well (see below).- Serialization: Ax allows serializing the experiement to json / a database. While this does work with a string representation, it wouldn't with an arbitrary python callable defining the nonlinear constraints
- Transforms. Ax does some reasonably complicated transformation of the parameters and outcomes in its modeling layer (in order to be able to use consistent priors on model hyperparameters and avoid numerical issues). While applying these transformations to a linear constraint mapping is reasonably straightforward (and we can use the transformed constraint in the transformed space), it is not for arbitrary nonlinear constraints.
In short, there are a bunch of challenges here. We'd like to enable this feature but it's not straightforward and we don't have any concrete plans to work on it in the near future.
@StanleyYoo since these are highly nonlinear constraints, it's not straightforward to support them easily via the AxClient
API. You essentially have two options:
@StanleyYoo closing due to lack of activity. If you need additional support please feel free to re-open or start a new issue :)
Hi, I am trying to apply complex constrains to the
SearchSpace
. TheSearchSpace
comprises with 6RangeParameter
s as:x00, x01, x02, x03, x04 and x05
. The constrains I need to apply is thediscriminant
calculated follwoing procedure shall be larger than 0, i.e.discriminant >=0
:However, the
ParameterConstraint
only support very simple contraints. How this could be resolved?Thank you in advance. Stanley