Unable to construct `ADNLPModel` with a matrix of linear constraints

The documentation of ADNLPModels.ADNLPModel suggests that there are methods that accept a matrix A to signify linear constraints:

ADNLPModel(f, x0, A, lcon, ucon)
ADNLPModel(f, x0, lvar, uvar, A, lcon, ucon)

These constructors are also successfully tested on GitHub.
However, I get an error when I try to use this:

params0 = [1.0, 0.1, 0.9]
A = sparse([
	0 -1 1
])
problem = ADNLPModels.ADNLPModel(
	nll, params0, # f, x0
	[0, 0, 0], [Inf, Inf, 1], # lvar, uvar
	A, [0], [Inf] # A, lcon, ucon
)

Error:

MethodError: no method matching ADNLPModels.ADNLPModel(::Main.var"workspace#51".var"#nll#5"{Main.var"workspace#51".GARCHLearner{Float64}, Vector{Float64}}, ::Vector{Float64}, ::Vector{Int64}, ::Vector{Float64}, ::SparseArrays.SparseMatrixCSC{Int64, Int64}, ::Vector{Int64}, ::Vector{Float64})

The type `ADNLPModels.ADNLPModel` exists, but no method is defined for this combination of argument types when trying to construct it.


Closest candidates are:

  ADNLPModels.ADNLPModel(::Any, ::Any, ::Any, ::Any, ::SparseArrays.AbstractSparseMatrix{Tv, Ti}, ::Any, ::Any, ::Any; kwargs...) where {Tv, Ti}
   @ ADNLPModels ~/.julia/packages/ADNLPModels/bOFzz/src/nlp.jl:507

  ADNLPModels.ADNLPModel(::Any, ::S, ::Any, ::Any, ::S, ::Any, ::S, ::S; kwargs...) where S
   @ ADNLPModels ~/.julia/packages/ADNLPModels/bOFzz/src/nlp.jl:240

  ADNLPModels.ADNLPModel(::Any, ::S, ::S, ::S, ::Any, ::Any, ::S, ::S, ::S; kwargs...) where S
   @ ADNLPModels ~/.julia/packages/ADNLPModels/bOFzz/src/nlp.jl:330
  ...

What am I doing wrong?

Hey @ForceBru
I cannot test it in right now but from the error message I am suspecting the problem is that your matrix A and lcon are vectors of Int while their should be vectors of Float64

1 Like

Yes, that is exactly right - I’ve literally discovered this just now!

This throws the error:

params0 = [1.0, 0.1, 0.9]
A = sparse([
	0 -1 1 # integers here
])
problem = ADNLPModels.ADNLPModel(
	nll, params0,
	[0, 0, 0], # these are integers
        [Inf, Inf, 1],
	A, [0], [Inf] # 0 is an integer!
)

Change ints to float - and now it works:

A = sparse([
	0. -1 1 # note floating-point literal here
])
problem = ADNLPModels.ADNLPModel(
	nll, params0,
	[0, 0, 0.], [Inf, Inf, 1], # floats everywhere
	A, [0.], [Inf] # 0. is a float
)

IMO this is extremely confusing. The error message doesn’t say anything about element types at all.

Yes, agreed it’s not 100% clear. Can you open an issue to improve the error message on ADNLPModels.jl? We could make a tailored one.

1 Like