From b9b735d1e740edd9906d867ffdfe05cf229e531b Mon Sep 17 00:00:00 2001 From: fpacaud Date: Sun, 14 Jul 2024 15:51:47 +0200 Subject: [PATCH] Pass option to ExaModel when instantiating from JuMP --- ext/ExaModelsJuMP.jl | 4 ++-- ext/ExaModelsKernelAbstractions.jl | 15 +++------------ ext/ExaModelsMOI.jl | 4 ++-- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/ext/ExaModelsJuMP.jl b/ext/ExaModelsJuMP.jl index 94adad2e..b24de963 100644 --- a/ext/ExaModelsJuMP.jl +++ b/ext/ExaModelsJuMP.jl @@ -3,8 +3,8 @@ module ExaModelsJuMP import ExaModels import JuMP -function ExaModels.ExaModel(jm::JuMP.GenericModel{T}; backend = nothing) where {T} - return ExaModels.ExaModel(jm.moi_backend.model_cache; backend = backend) +function ExaModels.ExaModel(jm::JuMP.GenericModel{T}; options...) where {T} + return ExaModels.ExaModel(jm.moi_backend.model_cache; options...) end end # module ExaModelsJuMP diff --git a/ext/ExaModelsKernelAbstractions.jl b/ext/ExaModelsKernelAbstractions.jl index 2a3885a7..9929c388 100644 --- a/ext/ExaModelsKernelAbstractions.jl +++ b/ext/ExaModelsKernelAbstractions.jl @@ -335,17 +335,6 @@ function ExaModels.jtprod_nln!( ) where {T,VT,E<:KAExtension{T,VT,Nothing}} error("Prodhelper is not defined. Use ExaModels(c; prod=true) to use jtprod_nln!") end -function ExaModels.hprod!( - m::ExaModels.ExaModel{T,VT,E}, - x::AbstractVector, - y::AbstractVector, - v::AbstractVector, - Hv::AbstractVector; - obj_weight = one(eltype(x)), -) where {T,VT,E<:KAExtension{T,VT,Nothing}} - error("Prodhelper is not defined. Use ExaModels(c; prod=true) to use hprod!") -end - function ExaModels.jprod_nln!( m::ExaModels.ExaModel{T,VT,E}, x::AbstractVector, @@ -396,7 +385,9 @@ function ExaModels.hprod!( Hv::AbstractVector; obj_weight = one(eltype(x)), ) where {T,VT,E<:KAExtension} - + if isnothing(m.ext.prodhelper) + error("Prodhelper is not defined. Use ExaModels(c; prod=true) to use hprod!") + end fill!(Hv, zero(eltype(Hv))) fill!(m.ext.prodhelper.hessbuffer, zero(eltype(Hv))) diff --git a/ext/ExaModelsMOI.jl b/ext/ExaModelsMOI.jl index be7efc72..39aef87c 100644 --- a/ext/ExaModelsMOI.jl +++ b/ext/ExaModelsMOI.jl @@ -55,7 +55,7 @@ end float_type(::MOIU.Model{T}) where {T} = T -function ExaModels.ExaModel(jm_cache::MOI.ModelLike; backend = nothing) +function ExaModels.ExaModel(jm_cache::MOI.ModelLike; backend = nothing, prod=false) T = float_type(jm_cache.model) minimize = jm_cache.model.objective.sense == MOI.MIN_SENSE @@ -116,7 +116,7 @@ function ExaModels.ExaModel(jm_cache::MOI.ModelLike; backend = nothing) cons = ExaModels.constraint(c, offset; start = y0, lcon = lcon, ucon = ucon) build_constraint!(c, cons, bin) - return ExaModels.ExaModel(c) + return ExaModels.ExaModel(c; prod=prod) end function exafy_con(cons::Nothing, bin, offset, lcon, ucon)