I am trying to use mystic for some constrained optimization problems, but it will not respect my constraint, even after using mystic's simplify function. I reckon I must be missing something, but I can't figure out what it is.
Here is a simple example of code that should illustrate my issue:
# %pip install mystic
import mystic as my
import numpy as np
def objective(X):
x0, x1, x2 = X
return x0*x1*x2
bounds = [(0., 1e5)]*3
eqn = "x0 + x1 + x2 - 100 == 0.0"
constraint = my.symbolic.generate_constraint(
my.symbolic.generate_solvers(my.symbolic.simplify(eqn))
)
mon = my.monitors.VerboseMonitor(10)
result = my.solvers.diffev2(
objective,
x0=bounds,
bounds=bounds,
constraints=constraint,
disp=True,
full_output=True,
itermon=mon)#, map=p.map)
print (result)
This is a very simple objective function (my actual work involves something more complicated), which should leave us with a result of x0 = x1 = x2 = 100/3; f(x) = (100/3)^3, but mystic is ignoring the constraint and saying that the function value is infinite. I have also tried making the objective function negative, making the constraint negative, and both at the same time, each time mystic ignored the constraint.
What is missing from this code to make mystic follow the simple summation constraint?
Edit: I found that by removing the "s" from "constraints" in the diffev2 call caused mystic to stop reporting infinite function values. I also changed the objective to -x0*x1*x2 because mystic is attempting to minimize, so this should actually give the x0=x1=x2 result I was expecting. Unfortunately mystic now always converges to [100000, 100000, 100000], even when changing the constant in the constraint, changing the objective by squaring one of the terms, or increasing npop and gtol.