writeMPS()

Hi folks,

In JuMP 0.19, has writeMPS been removed? This issue alludes to it : https://github.com/JuliaOpt/JuMP.jl/issues/1403

If so, why and is there a replacement?

And if not, where is the function documented - a google search returns very little.

Edit: I find writeMPS in the v. 0.18 docs http://www.juliaopt.org/JuMP.jl/v0.18/refmodel.html?highlight=writemps but not in later versions

Actually… I see that writers.jl is no longer part of the repo since v0.18. Is it just a matter of converting it to work with JuMP 0.19 and Julia 1.0 or is it gone forever?

These writers are now in https://github.com/odow/MathOptFormat.jl, although it doesn’t appear to be documented at the moment how to write an MPS file from a JuMP model.
@odow

I will add some documentation, but in the mean time:

using JuMP, MathOptFormat
jump_model = JuMP.Model()
@variable(jump_model, x)
@constraint(jump_model, con1, 2x <= 1)

mps_model = MathOptFormat.MPS.Model()
MOI.copy_to(mps_model, JuMP.backend(jump_model))
MOI.write_to_file(mps_model, "my_model.mps")

@mlubin If we wanted to streamline things, we could make MathOptFormat a dependency of JuMP, and then have an API like

JuMP.write_to_file(model::Model, filename::String)

We could detect the file extension and dispatch to the appropriate MathOptFormat model type.

Many thanks for this. The suggestion to streamline would be great. Is there a performance impact from the copy_to step for large models, or is this unavoidable?

By the way, if a variable has no coefficients in the objective function or constraints, it is skipped in the column section but the bounds are still reported leading to unknown column errors. I will raise an issue in github.

Is there a performance impact from the copy_to step for large models, or is this unavoidable?

If you have an example where the copy represents an unacceptable overhead, that would be interesting to analyse.

If you only want to use JuMP to write a file, you can load the MPS writer as a “solver” an avoid this overhead

model = Model(with_optimizer(MathOptFormat.MPS.Model))
# or
model = JuMP.direct_model(MathOptFormat.MPS.Model())
@variable(model, x)
@constraint(model,con1, 2x <= 1)
MOI.write_to_file(JuMP.backend(model), "my_model.mps")

Thanks a lot. Just here to emphasise that having a streamlined way to write a model to a file with a single call from JuMP would be really nice. At the moment we need to write more code to do the same thing as with 0.18 (plus the additional dependency).

How can you add MathOptFormat? I am running into this problem:

julia> import Pkg

julia> Pkg.add(“MathOptFormat”)

Updating registry at ~/.julia/registries/General

Updating git-repo https://github.com/JuliaRegistries/General.git

ERROR: The following package names could not be resolved:

  • MathOptFormat (not found in project, manifest or registry)

Please specify by known name=uuid.

Ok I figured it out. First you need to know that Pkg comes with its own REPL mode, which can be entered from the Julia REPL by pressing ]

then you can add MathOptFormat with this command: add https://github.com/odow/MathOptFormat.jl

1 Like

Another question on this topic!

I tried this package to export LP-files (more readable for debugging)… I really liked the old “WriteLP” function as it was quick & simple

Unfortunately, the resulting LP file is not really acceptable as it does not work with solvers due to the fact that is uses the brackets and commas for indices i.e. x[1,3] instead of x_1_3.

Will this be fixed?

At some point, we will integrate MathOptFormat into JuMP so that it is seamless. It just hasn’t happened yet.

See https://github.com/odow/MathOptFormat.jl/issues/67.

Someone just needs to do the work (hint, hint).

As a work-around, you could always write to MPS.