JuliaSmoothOptimizers / JuliaSmoothOptimizers/ExpressionTreeForge.jl

ADNLSModel from ADNLPModels (OptimizationProblems)

Open
#14 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
10
Forks
3
PR merge metrics
No merged PRs in 30d

Description

The following code can test if an ADNLPModel is least square problem or not.

```julia
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:
```julia
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.