# writeMPS()

**URL:** <https://discourse.julialang.org/t/writemps/21669>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 9, 2019, 9:59am UTC](https://discourse.julialang.org/t/writemps/21669 "2019-03-09T09:59:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Di11on](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/di11on/32/6352_2.png) [@Di11on](https://discourse.julialang.org/u/Di11on)\
**Post date:** [March 9, 2019, 9:59am UTC](https://discourse.julialang.org/t/writemps/21669/1 "2019-03-09T09:59:30Z")

</div>

Hi folks,

In JuMP 0.19, has `writeMPS` been removed? This issue alludes to it : [https://github.com/JuliaOpt/JuMP.jl/issues/1403](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 [Models — JuMP -- Julia for Mathematical Optimization 0.18 documentation](http://www.juliaopt.org/JuMP.jl/v0.18/refmodel.html?highlight=writemps) but not in later versions

---

<div class="post-metadata">

**Author:** ![Di11on](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/di11on/32/6352_2.png) [@Di11on](https://discourse.julialang.org/u/Di11on)\
**Post date:** [March 9, 2019, 3:06pm UTC](https://discourse.julialang.org/t/writemps/21669/2 "2019-03-09T15:06:05Z")

</div>

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?

---

<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:** [March 9, 2019, 5:40pm UTC](https://discourse.julialang.org/t/writemps/21669/3 "2019-03-09T17:40:27Z")

</div>

These writers are now in [https://github.com/odow/MathOptFormat.jl](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

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 9, 2019, 7:01pm UTC](https://discourse.julialang.org/t/writemps/21669/4 "2019-03-09T19:01:51Z")

</div>

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

```julia
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

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

```

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

---

<div class="post-metadata">

**Author:** ![Di11on](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/di11on/32/6352_2.png) [@Di11on](https://discourse.julialang.org/u/Di11on)\
**Post date:** [March 10, 2019, 12:40am UTC](https://discourse.julialang.org/t/writemps/21669/5 "2019-03-10T00:40:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 10, 2019, 7:46pm UTC](https://discourse.julialang.org/t/writemps/21669/6 "2019-03-10T19:46:49Z")

</div>

> 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

```julia
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")

```

---

<div class="post-metadata">

**Author:** ![fa-bien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fa-bien/32/5559_2.png) [@fa-bien](https://discourse.julialang.org/u/fa-bien)\
**Post date:** [May 9, 2019, 7:01am UTC](https://discourse.julialang.org/t/writemps/21669/7 "2019-05-09T07:01:44Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![d3netxer](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@d3netxer](https://discourse.julialang.org/u/d3netxer)\
**Post date:** [May 10, 2019, 5:57pm UTC](https://discourse.julialang.org/t/writemps/21669/8 "2019-05-10T17:57:37Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![d3netxer](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@d3netxer](https://discourse.julialang.org/u/d3netxer)\
**Post date:** [May 10, 2019, 6:07pm UTC](https://discourse.julialang.org/t/writemps/21669/9 "2019-05-10T18:07:05Z")

</div>

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](https://github.com/odow/MathOptFormat.jl)

---

<div class="post-metadata">

**Author:** ![iharjunk](https://avatars.discourse-cdn.com/v4/letter/i/e0b2c6/32.png) [@iharjunk](https://discourse.julialang.org/u/iharjunk)\
**Post date:** [May 16, 2019, 2:42pm UTC](https://discourse.julialang.org/t/writemps/21669/10 "2019-05-16T14:42:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 16, 2019, 3:28pm UTC](https://discourse.julialang.org/t/writemps/21669/11 "2019-05-16T15:28:08Z")

</div>

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

See [LP writer creating invalid names for COIN CBC · Issue #67 · odow/MathOptFormat.jl · GitHub](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.
