Hi all,
I have a question regarding using the MathOptInterface.AbstractOptimizer
for parametric type declaration when defining a composite type. For example, take the type definition below:
using JuMP # JuMP reexports MathOptInterface as MOI
using Ipopt
struct TestType{U <: MOI.AbstractOptimizer}
test::U
end
my_test = TestType(Ipopt.Optimizer)
The idea here is that the user can pass a number of possible solvers to instantiate the composite type; however, the snippet above gives me the following error:
ERROR: MethodError: no method matching TestType(::Type{Ipopt.Optimizer})
The type `TestType` exists, but no method is defined for this combination of argument types when trying to construct it.
Closest candidates are:
TestType(::U) where U<:MathOptInterface.AbstractOptimizer
@ Main c:\Users\...\minexample.jl:5
Stacktrace:
[1] top-level scope
@ c:\Users\...\minexample.jl:8
I thought that U <: MOI.AbstractOptimizer
would be a valid type declaration because Ipopt.Optimizer
is a subtype of MOI.AbstractOptimizer
, for example:
julia> Ipopt.Optimizer <: MOI.AbstractOptimizer
true
What is the correct way to declare the type parameter for U
in the struct TestType
? Thank you in advance for the help!