Skip to content
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

Generic numeric type in JuMP #2025

Closed
matbesancon opened this issue Aug 14, 2019 · 9 comments · Fixed by #3385
Closed

Generic numeric type in JuMP #2025

matbesancon opened this issue Aug 14, 2019 · 9 comments · Fixed by #3385

Comments

@matbesancon
Copy link
Contributor

MOI parameterizes function and set types with the number type used to store the data, example:

julia> using JuMP
julia> MOI.LessThan(big"3.5")
MathOptInterface.LessThan{BigFloat}(3.5)

For the moment, JuMP uses and assumes Float64:

julia> @variable(m, x[1:3])
julia> @constraint(m, sum(x) <= 1//7)
x[1] + x[2] + x[3]  0.14285714285714285

Julia-native solvers should support more numeric types (see jump-dev/Convex.jl#262 (comment)), using them through JuMP would in the current state block this genericity.

From the user perspective, generic number types could allow chosen precision, Unitful.jl and others

@blegat
Copy link
Member

blegat commented Aug 14, 2019

One way to go for this is to parametrize the JuMP model with the coefficient type. Model() would give a JuMP.Model{Float64} and Model{T}() would give a JuMP.Model{T}(). JuMP.VariableRef will also be parametrized by T as one of its field is the JuMP.Model.
This means that in operators, we know which type to use for, e.g. +(::VariableRef, ::VariableRef).

@matbesancon
Copy link
Contributor Author

I think this will be fairly easier to implement and test once we have solvers working on multiple number types, from the conversations of last week Hypatia (Float64 / Complex) and SCIP (Float64, Rational)

@blegat
Copy link
Member

blegat commented Aug 15, 2019

CDDLib.Optimizer{Rational{BigInt}} and Polyhedra.VRepOptimizer{Rational{BigInt}} should work with Rational{BigInt}.

@ericphanson
Copy link
Contributor

ericphanson commented Aug 17, 2019

@JiazhengZhu and I are working on wrapping SDPA-GMP for high precision SDP solving, which would benefit from being able to use BigFloats. We’re currently using an branch of Convex with MOI support hacked on and parametrizing Convex’s Problem type with the numeric type, as was suggested above to do for JuMP. It would be great to be able to use JuMP to formulate problems as well.

edit: I would no longer call the MOI support in that Convex.jl branch as hacked-on, since we no longer re-use the MPB standard form and instead formulate the problem more directly for MOI

@chriscoey
Copy link
Contributor

Hypatia and Tulip allow generic reals.
I just tried to use the JuMP.Model{T}() syntax expecting it to work but I forgot that it doesn't. My vote is for that syntax as it is quite natural.

@rschwarz
Copy link
Contributor

rschwarz commented Apr 22, 2021

Would it be possible to introduce this feature as a non-breaking change, e.g. by defining a ModelGeneric{T} and then const Model = ModelGeneric{T}?

EDIT: Someting like this is already proposed above, but it's not clear to me whether it would be non-breaking.

Otherwise, I guess it would be post-poned to JuMP 2.x according to the roadmap, right?

@odow
Copy link
Member

odow commented Apr 22, 2021

Since the backend isn't concrete, we could do this non-breaking with Model(coefficient_type = T) or similar.

@odow odow added this to the 1.x milestone Sep 23, 2021
@chriscoey
Copy link
Contributor

chriscoey commented Nov 2, 2021

this has been requested at https://discourse.julialang.org/t/hypatia-jump/70717. given that MOI allows any T<:Real, it seems like a natural thing to be able to do in JuMP. is it too late to make this a 1.0 milestone?

@odow
Copy link
Member

odow commented Nov 2, 2021

Yes, this is far too late for JuMP 1.0. Depending on the details, it might even be a JuMP 2.0 type thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants