facebook / Ax

Adaptive Experimentation Platform
https://ax.dev
MIT License
2.38k stars 312 forks source link

Parameter constraint with square roots #816

Closed EvanClaes closed 2 years ago

EvanClaes commented 2 years ago

Hi all,

I'm trying to solve a multi-objective optimization problem that has a relatively complex parameter constraint involving squares and square roots. So far I have failed to do this as the API does not seem to accept np.square for example.

Here is the code I'm using:

ax_client.create_experiment(
    name="moo_experiment",
    parameters=[
        {
            "name": f"x{i+1}",
            "type": "range",
            "bounds": [400, 500],
        }
        for i in range(2)
    ],
    objectives={
        # `threshold` arguments are optional
        "a": ObjectiveProperties(minimize=False), 
        "b": ObjectiveProperties(minimize=False)
    },
    overwrite_existing_experiment=True,
    is_test=True,
    parameter_constraints=["-np.sqrt(2*np.square( 0.5*x1 )) + x1 <= -100"],
)

Which produces the following error:

AssertionError: Parameter not in dict_keys(['x1', 'x2'])

Is there any way in which I can implement this constraint? I've also tried reformulating the constraint to get rid of the square root which (I think) yields 0.5x12 - x22 - 200x2 >= 10000, but this gives the same error (perhaps because of the squared terms?).

Is there any solution for this?

Balandat commented 2 years ago

Hi, unfortunately we currently do not support non-linear parameter constraints. #769 has a pretty lengthy discussion of this, incl. pointers to other issues as well a draft PR (#794) that can allow this - but this is very much preliminary work and can potentially cause unwanted behavior when interacting with the transforms we do of the parameters - if you want to try this out USE AT YOUR OWN RISK.

lena-kashtelyan commented 2 years ago

Closing as duplicate of #153 that is already on our wishlist. As @Balandat states, full support for this is not likely in the short-term, and https://github.com/facebook/Ax/issues/769 discusses some very experimental workarounds.