Hi all,
I have been estimating a nonlinear model using the Ipopt solver through MathProgBase. The objective function takes sum(log.(x)) for a vector x at the end.

From what I understand, if x is ever negative, Ipopt shows the following message: Warning: Cutting back alpha due to evaluation error
However today I ran into the following error after 200+ iterations for the first time:

ERROR: DomainError with -1.(bunch of digits)e-30:
log will only return a complex result if called with a complex argument. Try log(Complex(x)).

The objective function is quite complicated and I have not been able to come up with a MWE that would lead to the same error during Ipopt optimization. I have been running similar scripts daily for the past few months and this is the first time I see the Core DomainError, instead of Ipoptâ€™s evaluation error message.

The cause for this error might be just some embarrassing bug that I have yet to locate, but my question is: in general, what might lead to the Domain Error during optimization (instead of having Ipopt indicate that thereâ€™s an evaluation error and just continue as usual)? I am hoping this would lead me to where my bug might be.

The error is because log(x) is being called with a negative value of x. You should add constraints to prevent this, and/or choose a starting value of x such that x is feasible and non-negative.

Hi, thank you for the response. The starting values result in positive x, so the problem doesnâ€™t come up until after 200+ iterations. If I didnâ€™t write a bug (which I probably did), x should be positive for all values of the variables being optimized, given the constraints and bounds I set. I am just puzzled over the difference between negative x that leads to Ipoptâ€™s warning about evaluation error, and the negative x that would trigger the core Domain Error. I was hoping maybe knowing the difference would point me to where my bug was.

Even though the initial x is > 0 and the solution is > 0, thereâ€™s not guarantee IPOPT wonâ€™t try values of x with negative components unless you add the constraint x â‰Ą 0 to your problem. Perhaps you can turn up the log level and gist IPOPTâ€™s (long) output somewhere. It might reveal what the solver was doing when the error occured. Seeing your model might help too.

Thatâ€™s what Iâ€™m puzzled with. I though Ipoptâ€™s evaluation error warning indicates this kind of situation, as Andreas Waechter had stated on the Ipopt mailing list.
The reason I thought this would be a Julia question is that I am getting a Julia core error, not an Ipopt warning. The latter happens frequently when we optimize with log() in the objective function without setting x > 0, whereas this is the first time I see the core Domain Error when estimating this model.
As you and @odow have suggested, itâ€™d be easy to bypass negative x by adding an if x > 0 kind of condition or constraints. I just thought maybe the fact that I am getting the domain error points to potential concerns with my model, and was wondering how the domain error gets triggered when Ipopt already has the evaluation error for negative input to log().
Still, thank you for the response.

The error comes from Ipopt calling log with a negative value.

julia> log(-1.0)
ERROR: DomainError with -1.0:
log will only return a complex result if called with a complex argument. Try log(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
[2] log(::Float64) at ./special/log.jl:285
[3] top-level scope at none:0

In this case, itâ€™s being called with x=-1e-30, which is approximately zero. So even if you have a constraint x >= 0, Ipopt might call it with -1e-30. You need a constraint like x >= 0.001.