NLopt stopval and termination criteria

Hi,
I am solving optimization problems like find max x1 in [a1,b1] : f(x1,x2,x3...)<=0 plus I know that at initial point f(a1,a2,a3...)<=0.
Sometimes my model f (based on experimental data) isn’t sensitive to x1 (like in the example below), so I want to stop the optimizer when it reaches b1 but it seems stopval doesn’t work this way:

f_ineq_constr(x::Vector, g::Vector) = 0.0*x[1] + (x[2]-1.0)^2 -2.0

global count = 0

function f_optim(x::Vector, g::Vector)
    global count
    count::Int += 1
    println("f_$count($x)")
    x[1]
end

using NLopt
opt = Opt(:LN_AUGLAG, 2)
max_objective!(opt, f_optim)
local_opt = Opt(:LN_SBPLX, 2)
lower_bounds!(opt, [0.0, -Inf])
upper_bounds!(opt, [9.0, +Inf])
xtol_abs!(opt, 1e-3)
stopval!(opt, 9.0)
inequality_constraint!(opt, f_ineq_constr, 1e-5)

(minf, minx, ret) = optimize(opt, zeros(2))

f_23035([8.9965, 0.0])
f_23036([9.0, 0.0])
f_23037([9.0, 0.0])
...

Finally it reaches MAXEVAL_REACHED.
Could you please help me understand how stopval should work and what is a good choice of a termination criteria here?

IIRC will ignore stopval if the point is infeasible (violates the constraint). The AUGLAG algorithm is a bit funny in that intermediate steps are almost always infeasible, so stopval won’t have much effect. (The CCSA algorithm, in contrast, is designed to produce feasible iterates, but it requires you to supply gradients.)

Thanks for clarification!
Currently I use a “workaround” to stop the optimization when boundary is reached with AUGLAG. Instead of searching max of f_optim = (x,g)->x[1] I use f_optim = (x,g)->-(x[1]-9)^2 and remove the boundary constraints.

@stevengj Do you think there is a way to efficiently stop AUGLAG optimization for this problem when x[1] reaches the boundary x[1]=9.0? I have read about ForcedStop but not sure how to use it in Julia