Skip to content
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

Constraints on FixedParameters are not allowed #2455

Closed
Fa20 opened this issue May 14, 2024 · 8 comments
Closed

Constraints on FixedParameters are not allowed #2455

Fa20 opened this issue May 14, 2024 · 8 comments
Assignees
Labels
question Further information is requested

Comments

@Fa20
Copy link

Fa20 commented May 14, 2024

ax_client.create_experiment(
name="multi_objective_optimization",
parameters=[{"name": "x11", "type": "fixed", "value": 500, "value_type": "int"},
{"name": "x1", "type": "range", "bounds": [-1, 3], "value_type": "int"},
{"name": "x2", "type": "range", "bounds": [-2, 2], "value_type": "int"},
{"name": "x3", "type": "range", "bounds": [-2.0, 2.0], "value_type": "float"},
{"name": "x4", "type": "range", "bounds": [-20, 20], "value_type": "int"}
],
objectives={
"objective_1": ObjectiveProperties(minimize=True),
"objective_2": ObjectiveProperties(minimize=False),
},
parameter_constraints=[
"x4 - 1.5x3 >= 0", # Constraint involving x4 and x3
"x2 - 5
x1 <= 0", # Constraint involving x2 and x1
"x11 - x3 >= 0",
]. How can I fix this problem in case that I want to keep this constarined "x11 - x3 >= 0" and x11 has a fixed value

another question: does AX support complex constarined like :
dist = 100 / x4
length = ((x2 / np.tan(np.radians(x3))) / (x11 * math.pi) * 100)

constarined= (length / dist) >= 3

@bernardbeckerman
Copy link
Contributor

Hi @Fa20,
Can you manually input the fixed bavlue of x11 into your constraint? So your example becomes:

ax_client.create_experiment(
    name="multi_objective_optimization",
    parameters=[
        {"name": "x11", "type": "fixed", "value": 500, "value_type": "int"},
        {"name": "x1", "type": "range", "bounds": [-1, 3], "value_type": "int"},
        {"name": "x2", "type": "range", "bounds": [-2, 2], "value_type": "int"},
        {"name": "x3", "type": "range", "bounds": [-2.0, 2.0], "value_type": "float"},
        {"name": "x4", "type": "range", "bounds": [-20, 20], "value_type": "int"}
    ],
    objectives={
        "objective_1": ObjectiveProperties(minimize=True),
        "objective_2": ObjectiveProperties(minimize=False),
    },
    parameter_constraints=[
        "x4 - 1.5*x3 >= 0", # Constraint involving x4 and x3
        "x2 - 5*x1 <= 0", # Constraint involving x2 and x1
        "x3 <= 500", # This line is updated to use the fixed value of x11
    ],
)

another question: does AX support complex constarined like :

Ax only supports linear constraints, since those are easily passed down to the modeling layer and incorporated into the optimization. One imperfect-but-potentially-useful way to incorporate these constraints is as OutcomeConstraints, i.e., supply the scalar you'd like to constrain as an outcome of your experiment, and then set constraints on that scalar's value via outcome constraints (pointer). Hope that helps!

@Fa20
Copy link
Author

Fa20 commented May 15, 2024

@bernardbeckerman

Hi @Fa20, Can you manually input the fixed bavlue of x11 into your constraint? So your example becomes:

ax_client.create_experiment(
    name="multi_objective_optimization",
    parameters=[
        {"name": "x11", "type": "fixed", "value": 500, "value_type": "int"},
        {"name": "x1", "type": "range", "bounds": [-1, 3], "value_type": "int"},
        {"name": "x2", "type": "range", "bounds": [-2, 2], "value_type": "int"},
        {"name": "x3", "type": "range", "bounds": [-2.0, 2.0], "value_type": "float"},
        {"name": "x4", "type": "range", "bounds": [-20, 20], "value_type": "int"}
    ],
    objectives={
        "objective_1": ObjectiveProperties(minimize=True),
        "objective_2": ObjectiveProperties(minimize=False),
    },
    parameter_constraints=[
        "x4 - 1.5*x3 >= 0", # Constraint involving x4 and x3
        "x2 - 5*x1 <= 0", # Constraint involving x2 and x1
        "x3 <= 500", # This line is updated to use the fixed value of x11
    ],
)

another question: does AX support complex constarined like :

Ax only supports linear constraints, since those are easily passed down to the modeling layer and incorporated into the optimization. One imperfect-but-potentially-useful way to incorporate these constraints is as OutcomeConstraints, i.e., supply the scalar you'd like to constrain as an outcome of your experiment, and then set constraints on that scalar's value via outcome constraints (pointer). Hope that helps!

@bernardbeckerman thanks for your answer . how can I convert the constarined to scaler and it is depend on the value of x1,x2 etc. which has range between two values? as wellas I have 3 constatins not just the above one?

@bernardbeckerman
Copy link
Contributor

Following the example in this tutorial, you can do this by adding an outcome_constraint to the ax_client.create_experiment call, e.g.,

ax_client.create_experiment(
    ...
    outcome_constraints=["length_over_dist >= 3"]
)

and then adding the calculation of the desired quantity to the evaluate function and including it in the output dictionary, e.g.,

def evaluate(parameterization):
    x = np.array([parameterization.get(f"x{i+1}") for i in range(6)])
    dist = 100 / x4
    length = ((x2 / np.tan(np.radians(x3))) / (x11 * math.pi) * 100
    # In our case, standard error is 0, since we are computing a synthetic function.
    return {
        "hartmann6": (hartmann6(x), 0.0), 
        "l2norm": (np.sqrt((x**2).sum()), 0.0), 
        "length_over_dist": (length/dist, 0.0)
    }

Hope that helps!

@bernardbeckerman bernardbeckerman self-assigned this May 15, 2024
@bernardbeckerman bernardbeckerman added the question Further information is requested label May 15, 2024
@Fa20
Copy link
Author

Fa20 commented May 16, 2024

Does this the same like if we set the constrained on parameters?does this mean that the suggested values of parameters will satisfy this condition. Because I need the values of the parameters to simulate the objective functions after each trial in order to get the value of the objective functions

@Fa20
Copy link
Author

Fa20 commented May 16, 2024

and I have MOO problem

@bernardbeckerman
Copy link
Contributor

If you follow my recommendation here (link) to avoid computation of the objective(s) if the (nonlinear) constraint is violated, then any trial with status COMPLETED should satisfy the constraint. This should work with constrained or non-constrained optimization. Does that make sense?

@bernardbeckerman
Copy link
Contributor

@Fa20 have you had luck with the above suggestion? Closing this out for now but please feel free to comment/reopen with any further questions.

@Fa20
Copy link
Author

Fa20 commented May 21, 2024

ok thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants