Skip to content

Add ExpressionTreeForge.extract_element_functions in parse-function.jl #181

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

Merged
merged 2 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parse-functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ then try to detect the least squares pattern. There is no guarantee that this fu
"""
function isnls(nlp)
expr_tree = ExpressionTreeForge.get_expression_tree(nlp)
F_expr = extract_element_functions(expr_tree)
F_expr = ExpressionTreeForge.extract_element_functions(expr_tree)
test_square(expr) = expr.field == ExpressionTreeForge.M_power_operator.Power_operator{Int}(2)
is_nls = mapreduce(test_square, &, F_expr) :: Bool
return is_nls
Expand Down
32 changes: 18 additions & 14 deletions test/parse-function-test.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
problems_names = meta[!,:name][1:50] # we test only the 50 first problems
problems_symbols = map(name -> OptimizationProblems.ADNLPProblems.eval(Meta.parse(name)), problems_names)

result_list_isnls = Bool[]
@testset "Test NLS parser" for (index, problem) in enumerate(problems_symbols)
@debug "$index : $problem"
try
detect_nls = JSOSuite.isnls(problem())
is_nls = meta[meta.name .== problems_names[index], :objtype][1] == :least_squares
push!(result_list_isnls, detect_nls)
if detect_nls
@test detect_nls == is_nls
@debug "Least squares objective"
end
catch
@debug "the $index-th $(problems_names[index]) problem is unsupported."
end
@testset "NLS from NLP" begin
result_list_isnls = Bool[]
for (index, problem) in enumerate(problems_symbols)
try
detect_nls = JSOSuite.isnls(problem())
is_nls = meta[meta.name .== problems_names[index], :objtype][1] == :least_squares
push!(result_list_isnls, detect_nls)
if detect_nls
@test detect_nls == is_nls
@debug "Least squares objective, $index : $problem"
# detect_nls != is_nls && (@debug "$index : $problem")
else
@debug "Not least squares objective, $index : $problem"
end
catch
@debug "the $index-th $(problems_names[index]) problem is unsupported."
end
end
end
Loading