Using sum_constraints with "later" dimensions breaks opt.ask()
Closed this issue · 1 comments
dk-teknologisk-mon commented
Sum_equals constraints break if you use a set of dimensions that do not start from the first one and continue upwards. E.g. constraining dimensions [0, 1, 2] works, but constraining dimensions [1, 2, 3] does not. The error is caused by the step that checks whether candidate points in the constrained dimensions actually lie within the space.
To reproduce
##% Import packages
from ProcessOptimizer import Optimizer
from ProcessOptimizer.space.constraints import SumEquals
# Step 1: This code works just fine
seed = 42
dimensions = [
(200.0, 450.0),
(50.0, 450.0),
(0.0, 450.0),
(10.0, 60.0),
]
# Build optimizer
opt = Optimizer(
dimensions=dimensions,
lhs=False,
acq_func="EI",
n_initial_points=5,
random_state=seed,
)
# Create a constraint among the three factors with the 450 upper limit
constraints = [SumEquals(dimensions=[0, 1, 2], value=450)]
opt.set_constraints(constraints)
x = opt.ask(
5,
strategy="cl_min",
)
# ==============================
# Step 2: This code breaks
seed = 42
dimensions = [
(10.0, 60.0), # <-- We have moved this dimension from last, to first
(200.0, 450.0),
(50.0, 450.0),
(0.0, 450.0),
]
# Build optimizer
opt = Optimizer(
dimensions=dimensions,
lhs=False,
acq_func="EI",
n_initial_points=5,
random_state=seed,
)
# Create the constraint, again just with the three factors with the 450 upper limit
constraints = [SumEquals(dimensions=[1, 2, 3], value=450)]
opt.set_constraints(constraints)
x = opt.ask(
5,
strategy="cl_min",
)
The code above throws an error in a later step, where the coordinates are transformed, with an error indicating that some points lie outside the defined space.
dk-teknologisk-mon commented
I have already identified and corrected the problem, working on a pull request now.