From 3b0af92546912f4f7f52494d908be92ec96b81ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 6 Jun 2026 11:45:51 +0100 Subject: [PATCH] Add canonical --- src/Utilities/functions.jl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Utilities/functions.jl b/src/Utilities/functions.jl index e88ae35416..b824cdbcbe 100644 --- a/src/Utilities/functions.jl +++ b/src/Utilities/functions.jl @@ -1056,6 +1056,32 @@ function canonical(f::MOI.AbstractFunction) return g end +# Workaround: both `is_canonical` and `canonicalize!` would be slow otherwise +canonical(f::MOI.ScalarNonlinearFunction) = f + +# This is maybe the right fix, but commented out to be sure to isolate +# JuMP-side of profiling in https://github.com/jump-dev/JuMP.jl/pull/4032 +# We still need to figure out what's the right fix here anyway +#function canonical(f::MOI.ScalarNonlinearFunction) +# cache = Dict{MOI.AbstractScalarFunction,MOI.AbstractScalarFunction}() +# # Don't use recursion here. This gets called for all scalar nonlinear +# # constraints. +# stack = Any[arg for arg in f.args] +# while !isempty(stack) +# arg = pop!(stack) +# if arg isa MOI.ScalarNonlinearFunction +# for a in arg.args +# push!(stack, a) +# end +# else +# if !is_canonical(arg) +# return false +# end +# end +# end +# return true +#end + canonicalize!(f::Union{MOI.VectorOfVariables,MOI.VariableIndex}) = f """