The following code can test if an ADNLPModel is least square problem or not.
using ExpressionTreeForge
using ADNLPModels, ModelingToolkit
using OptimizationProblems, OptimizationProblems.ADNLPProblems
function get_expr_tree(adnlp :: ADNLPModel; x0 :: Vector{T}=copy(adnlp.meta.x0), kwargs...) where T <: Number
n = adnlp.meta.nvar
ModelingToolkit.@variables x[1:n]
fun = adnlp.f(x)
ex = ExpressionTreeForge.transform_to_expr_tree(fun)
return ex, n, x0
end
using ..ExpressionTreeForge.M_power_operator
myand(a::Bool,b::Bool) = a && b
function isnls(nlp)
ex, n, x0 = get_expr_tree(nlp)
F_expr = delete_imbricated_plus(ex)
test_square(expr) = expr.field == Power_operator{Int}(2)
is_nls = mapreduce(test_square, myand, F_expr) :: Bool
return is_nls
end
problems_names = OptimizationProblems.meta[!,:name] #261 problems
problems_symbols = map(name -> Symbol(name), problems_names)
problems = map( symbol -> getfield(OptimizationProblems.ADNLPProblems, symbol)(), problems_symbols)
res_isnls = []
index_is_nls = []
for (index,problem) in enumerate(problems)
println(index)
try
bool = isnls(problem)
push!(res_isnls, bool)
push!(index_is_nls, index)
catch
println("the ", index, "-th problem is unsupported")
end
end
length(res_isnls) #243 supported problems
cpt_isnls = 0
for (index, is_nls) in enumerate(res_isnls)
cpt_isnls += is_nls
end
cpt_isnls # 45 NLS problems
To summarize, among the 261 ADNLPModels: 243 are analyzed (without an error) and 45 are least square problems.
The name of the name least square problems are:
list_isnls_supported = filter(i-> res_isnls[i], 1:length(index_is_nls))
list_isnls = index_is_nls[list_isnls_supported]
name_nls = problems_names[list_isnls]
There is a bunch of operators that are not implemented, at least:
- logarithm;
- absolute value;
producing unsupported problems.
The following code can test if an ADNLPModel is least square problem or not.
To summarize, among the 261 ADNLPModels: 243 are analyzed (without an error) and 45 are least square problems.
The name of the name least square problems are:
There is a bunch of operators that are not implemented, at least:
producing unsupported problems.