# Use low precision float type in JuMP

**URL:** <https://discourse.julialang.org/t/use-low-precision-float-type-in-jump/80332>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [May 1, 2022, 3:42pm UTC](https://discourse.julialang.org/t/use-low-precision-float-type-in-jump/80332 "2022-05-01T15:42:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wujinq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wujinq/32/22221_2.png) [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Post date:** [May 1, 2022, 3:42pm UTC](https://discourse.julialang.org/t/use-low-precision-float-type-in-jump/80332/1 "2022-05-01T15:42:11Z")

</div>

I’m working with a large linear SDP problem with `JuMP` and `COSMO` and is trying to find whether low float precision contributes to the convergence problem. So I want to change the float type of a smaller problem that works well with `Float64` to see whether the convergence problem recurs. Here is what I did:

```julia
model = Model(COSMO.Optimizer{Float16})
# And pass to the model Float16 version of constraints and objective function

```

However, an error occurs:

```julia
ERROR: MathOptInterface.UnsupportedAttribute{MathOptInterface.ObjectiveFunction{MathOptInterface.ScalarAffineFunction{Float64}}}: Attribute MathOptInterface.ObjectiveFunction{MathOptInterface.ScalarAffineFunction{Float64}}() is not supported by the model.

```

So I check the type of the objective function, and it seems the sum of two `VariableRef`s is of type `GenericAffExpr{Float64,VariableRef}` by default, which explains the error.

So, is there any method to work around the problem? Can I build an objective function with type `GenericAffExpr{Float16,VariableRef}`?

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [May 1, 2022, 4:00pm UTC](https://discourse.julialang.org/t/use-low-precision-float-type-in-jump/80332/2 "2022-05-01T16:00:04Z")

</div>

JuMP currently only supports Float64: [Generic numeric type in JuMP · Issue #2025 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/issues/2025). JuMP can be seen as a front-end to MathOptInterface (MOI) which does support generic number types. So depending on the problem you could try to use MOI directly or another front end (like Convex). But it might not be easy or work as well.

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [May 1, 2022, 9:44pm UTC](https://discourse.julialang.org/t/use-low-precision-float-type-in-jump/80332/3 "2022-05-01T21:44:44Z")

</div>

Note that according to [Arbitrary Precision · COSMO.jl](https://oxfordcontrol.github.io/COSMO.jl/stable/literate/build/arbitrary_precision/) COSMO supports `Float64` and `Float32` for SDP but not `Float16`.

IMO solvers like COSMO should have an option to solve in a precision that’s different from the precision of the input, but until that’s supported, you’ll need to find a workaround using the MOI-level API.
