Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newpt_wrapper access to undefined reference #151

Closed
ferrolho opened this issue Mar 24, 2020 · 3 comments
Closed

newpt_wrapper access to undefined reference #151

ferrolho opened this issue Mar 24, 2020 · 3 comments

Comments

@ferrolho
Copy link
Contributor

I have an issue related to #143 after upgrading to v0.9.0:

UndefRefError: access to undefined reference

Stacktrace:
 [1] getproperty at ./Base.jl:20 [inlined]
 [2] newpt_wrapper(::Ptr{Nothing}, ::Ptr{Float64}, ::Ptr{Float64}, ::Ptr{Nothing}) at /home/henrique/.julia/packages/KNITRO/HkbuF/src/kn_callbacks.jl:620
 [3] macro expansion at /home/henrique/.julia/packages/KNITRO/HkbuF/src/kn_common.jl:14 [inlined]
 [4] KN_solve at /home/henrique/.julia/packages/KNITRO/HkbuF/src/kn_solve.jl:10 [inlined]
 [5] #optimise#154(::Array{Tuple{Int32,Real},1}, ::typeof(TrajOpt.optimise), ::TrajOpt.Problem, ::Array{Float64,1}) at /home/henrique/git/uoe-trajopt-framework/src/transcription.jl:301
 [6] optimise(::TrajOpt.Problem, ::Array{Float64,1}) at /home/henrique/git/uoe-trajopt-framework/src/transcription.jl:54
 [7] top-level scope at In[27]:16

This only happens if I set a new point callback:

function callbackNewPoint(kc, x, duals, userParams)
    print("")
    return 0
end

KNITRO.KN_set_newpt_callback(kc, callbackNewPoint)
@ferrolho
Copy link
Contributor Author

I think that replacing this line
https://github.com/JuliaOpt/KNITRO.jl/blob/c0db89ef55fd3876139c176b73293299e035d7f9/src/kn_callbacks.jl#L620
with something like

if m.newpoint_user != nothing
    ret = m.newpt_callback(m, x, lambda, m.newpoint_user)
else
    ret = m.newpt_callback(m, x, lambda)
end

should solve the issue, but I don't know if this is the most idiomatic way of doing it.

@ferrolho
Copy link
Contributor Author

Here is a minimal working example.

Source

using KNITRO

function callbackNewPoint(kc, x, duals, userParams)
    println("[INFO] callbackNewPoint")
    return 0
end

lm = KNITRO.LMcontext()
kc = KNITRO.KN_new_lm(lm)

KNITRO.KN_add_vars(kc, 1)
KNITRO.KN_set_var_lobnds(kc, Cint(0), 2.0)
KNITRO.KN_set_var_primal_init_values(kc, [0.0])

KNITRO.KN_set_obj_goal(kc, KNITRO.KN_OBJGOAL_MINIMIZE)
KNITRO.KN_add_obj_quadratic_struct(kc, Cint[0], Cint[0], [1.0])

KNITRO.KN_set_newpt_callback(kc, callbackNewPoint)
# KNITRO.KN_set_newpt_callback(kc, callbackNewPoint, [])  # this one works

KNITRO.KN_solve(kc)

KNITRO.KN_free(kc)
KNITRO.KN_release_license(lm)

Output

=======================================
           Academic License
       (NOT FOR COMMERCIAL USE)
         Artelys Knitro 12.1.0
=======================================

Knitro presolve eliminated 0 variables and 0 constraints.

The problem is identified as a convex QP.
The problem is identified as bound constrained only.
Knitro changing algorithm from AUTO to 1.
Knitro changing bar_initpt from AUTO to 1.
Knitro changing bar_murule from AUTO to 4.
Knitro changing bar_penaltycons from AUTO to 0.
Knitro changing bar_penaltyrule from AUTO to 2.
Knitro changing bar_switchrule from AUTO to 0.
Knitro changing linesearch from AUTO to 2.
Knitro changing linsolver from AUTO to 2.
Knitro shifted start point to satisfy presolved bounds (1 variable).

Problem Characteristics                                 (   Presolved)
-----------------------
Objective goal:  Minimize
Objective type:  quadratic
Number of variables:                                  1 (           1)
    bounded below only:                               1 (           1)
    bounded above only:                               0 (           0)
    bounded below and above:                          0 (           0)
    fixed:                                            0 (           0)
    free:                                             0 (           0)
Number of constraints:                                0 (           0)
    linear equalities:                                0 (           0)
    quadratic equalities:                             0 (           0)
    gen. nonlinear equalities:                        0 (           0)
    linear one-sided inequalities:                    0 (           0)
    quadratic one-sided inequalities:                 0 (           0)
    gen. nonlinear one-sided inequalities:            0 (           0)
    linear two-sided inequalities:                    0 (           0)
    quadratic two-sided inequalities:                 0 (           0)
    gen. nonlinear two-sided inequalities:            0 (           0)
Number of nonzeros in Jacobian:                       0 (           0)
Number of nonzeros in Hessian:                        1 (           1)

  Iter      Objective      FeasError   OptError    ||Step||    CGits 
--------  --------------  ----------  ----------  ----------  -------
       0    8.940100e+00   0.000e+00
UndefRefError: access to undefined reference

Stacktrace:
 [1] getproperty at ./Base.jl:33 [inlined]
 [2] newpt_wrapper(::Ptr{Nothing}, ::Ptr{Float64}, ::Ptr{Float64}, ::Ptr{Nothing}) at /home/henrique/.julia/packages/KNITRO/HkbuF/src/kn_callbacks.jl:620
 [3] macro expansion at /home/henrique/.julia/packages/KNITRO/HkbuF/src/kn_common.jl:14 [inlined]
 [4] KN_solve(::KNITRO.Model) at /home/henrique/.julia/packages/KNITRO/HkbuF/src/kn_solve.jl:10
 [5] top-level scope at In[1]:19

@ferrolho
Copy link
Contributor Author

Closed with #152.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant