Anders Brink
Anders Brink

Reputation: 11

Use of log function in pyomo from spyder with couenne solver

I have the following constraint in a simple MINLP model:

model.cm2=Constraint(expr = model.xB2 == log(1.0+model.xA2))

This works when I call bonmin (windows64 binary distribution from AMPL)

When swithing to the couenne solver I need to convert to log10 base

model.cm2=Constraint(expr = model.xB2 == 2.3*log10(1.0+model.xA2))

otherwise I get the error:

ApplicationError: Solver (asl) did not exit normally.

model.pprint() gives in the first case:
    cm2 : Size=1, Index=None, Active=True
        Key  : Lower : Body                   : Upper : Active
        None :   0.0 : xB2 - log( 1.0 + xA2 ) :   0.0 :   True

I use the anaconda python installation and work with spyder.

Do anyone have an idea of the reason for this behaviour?

I have read the comment from jsiirola, but I do not think that the problem is evaluating the log of a negative number. Here is a complete test problem, that behaves the same way. If I solve with bonmin i can use log() if I use cuonne I have to use ln(10)*log10().

from pyomo.environ import *

solverpathb="..\\solversAMPL\\bonmin\\bonmin"
solverpathc="..\\solversAMPL\\couenne\\couenne"

model=ConcreteModel()

model.x =  Var(within=NonNegativeReals,bounds=(1,2),doc='Nonnegative')
model.y =  Var(within=NonNegativeReals,doc='Nonnegative')
model.obj = Objective(expr= model.x+model.y, sense=maximize)

model.c1=Constraint(expr = model.y == log(1.0+model.x))
#model.c2=Constraint(expr = model.y == 2.3*log10(1.0+model.x))

#Works with version c1 and c2 of the constraint
#solver = pyomo.opt.SolverFactory("bonmin", executable=solverpathb)

#only constraint c2 works with this solver
solver = pyomo.opt.SolverFactory("couenne", executable=solverpathc)

results = solver.solve(model, tee = True)
model.display()

The log file that should include errors only includes the model. This is the last part of the errors. ... File "C:/../testproblem.py", line 24, in results = solver.solve(model, tee = True)

File "C:\Users..\Python\Python36\site-packages\pyomo\opt\base\solvers.py", line 623, in solve "Solver (%s) did not exit normally" % self.name)

ApplicationError: Solver (asl) did not exit normally.

Note: I can use the following code for the object function, also with couenne

model.obj = Objective(expr= model.x+log(1.0+model.x), sense=maximize)

Upvotes: 1

Views: 2478

Answers (2)

Anders Brink
Anders Brink

Reputation: 11

Using a binary distribution from COIN-OR solved the problem, it was not a pyomo problem. The binary distribution of couenne downloaded from ampl.com doesn't, for some odd reason, accept the log-function, only log10.

Upvotes: 0

jsiirola
jsiirola

Reputation: 2634

First, the entire model would be most useful when debugging problems like this. Second, what error is being thrown by Couenne when it exits abnormally?

As to answers:

Pyomo uses the same interface for BONMIN and Couenne (they are both through the ASL), so you should never have to change your expression just because you switched solvers. log and log10 are not the same function, of course, so you are not solving the same problem.

I suspect the problem is that model.xA2 is going less than or equal to -1 (i.e., the solver is asking the ASL to evaluate log(0). The way to verify this is by looking at the solver log. Additionally, you will want to make sure that Pyomo sends "symbolic" labels to the solver so that the error will reference actual variable / constraint names and not just "x1, x2, x3, ..." and "c1, c2, c3, ..." in the error message.

Couenne is a global solver, whereas BONMIN is a local solver. As this is a nonconvex problem, Couenne is probably exploring parts of the solution space that BONMIN never went to.

Upvotes: 1

Related Questions