LoadError: UndefVarError: Grisu not defined

I’m getting the above error with JuMP / MathOptInterface when I attempt to write a model to a file:

MOI.write_to_file(lp_model, gName*".lp")

I note that there has been some discussion about Grisu in a plots+1.6 context recently but this error has existed for me in previous (< v1.6) versions – though I am now running 1.6.0.

Would anybody have any suggestions, please? Many thanks.

The first few lines of stacktrace are:

ERROR: LoadError: UndefVarError: Grisu not defined
Stacktrace:
  [1] write_function(io::IOStream, model::MathOptFormat.LP.InnerModel{Float64}, func::MathOptInterface.ScalarAffineFunction{Float64}, variable_names::Dict{MathOptInterface.VariableIndex, String})
    @ MathOptFormat.LP ~/.julia/packages/MathOptFormat/3cISG/src/LP/LP.jl:88
  [2] write_objective(io::IOStream, model::MathOptFormat.LP.InnerModel{Float64}, variable_names::Dict{MathOptInterface.VariableIndex, String})
    @ MathOptFormat.LP ~/.julia/packages/MathOptFormat/3cISG/src/LP/LP.jl:174
  [3] write(io::IOStream, model::MathOptFormat.LP.InnerModel{Float64})
    @ MathOptFormat.LP ~/.julia/packages/MathOptFormat/3cISG/src/LP/LP.jl:195
  [4] #5
    @ ~/.julia/packages/MathOptFormat/3cISG/src/MathOptFormat.jl:100 [inlined]
  [5] open(::MathOptFormat.var"#5#6"{MathOptFormat.LP.InnerModel{Float64}}, ::String, ::Vararg{String, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./io.jl:330
  [6] open(::Function, ::String, ::String)

Have you tried to install the Grisu package ?

Yes. Unless it should have been installed in some way other than the straightforward add Grisu; using Grisu way then it is not solving the issue.

MathOptFormat.jl is deprecated. You can write directly from JuMP now.

using JuMP
model = Model()
write_to_file(model, "model.lp")

https://jump.dev/JuMP.jl/v0.21.8/manual/models/#Write-a-model-to-file

You can also write directly from MathOptInterface:
https://jump.dev/MathOptInterface.jl/stable/submodules/FileFormats/overview/#Write-to-file

Thank you. That’s nice to know.

However when I tried upgrading my JuMP package I got teh below. I’m sure I’m doing something wrong here.

(@v1.6) pkg> add JuMP@0.21.8
   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package DataStructures [864edb3b]:
 DataStructures [864edb3b] log:
 ├─possible versions are: 0.9.0-0.18.9 or uninstalled
 ├─restricted to versions * by an explicit requirement, leaving only versions 0.9.0-0.18.9
 ├─restricted by compatibility requirements with JuMP [4076af6c] to versions: 0.18.0-0.18.9
 │ └─JuMP [4076af6c] log:
 │   ├─possible versions are: 0.18.3-0.21.8 or uninstalled
 │   └─restricted to versions 0.21.8 by an explicit requirement, leaving only versions 0.21.8
 └─restricted by compatibility requirements with Compose [a81c6b42] to versions: 0.11.0-0.17.20 — no versions left
   └─Compose [a81c6b42] log:
     ├─possible versions are: 0.6.1-0.9.2 or uninstalled
     └─restricted by compatibility requirements with PlotShapefiles [297584a0] to versions: 0.8.1-0.8.2
       └─PlotShapefiles [297584a0] log:
         ├─possible versions are: 0.1.0-0.2.2 or uninstalled
         └─restricted to versions * by an explicit requirement, leaving only versions 0.1.0-0.2.2
1 Like

The error says that PlotShapeFiles requires Compose 0.8, which doesn’t support DataStructures 0.18, as required by JuMP.

Documentation: 3. Managing Packages · Pkg.jl

That means you can’t use the latest versions of ComposePlotShapeFiles and JuMP together.

Either remove ComposePlotShapeFiles ] rm PlotShapeFiles, or more preferably, use a Pkg environment to minimize the conflicts: 4. Working with Environments · Pkg.jl.

1 Like

The latest version of Compose is 0.9.2, which is compatible with DataStructures 0.18. The issue is that PlotShapeFiles requires an old version of Compose.

1 Like

Ah, you’re right. I don’t know why I got confused.