# Save JuMP Model to File

**URL:** <https://discourse.julialang.org/t/save-jump-model-to-file/126220>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [February 23, 2025, 7:36pm UTC](https://discourse.julialang.org/t/save-jump-model-to-file/126220 "2025-02-23T19:36:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stuart\_Rogers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stuart_rogers/32/10694_2.png) [@Stuart\_Rogers](https://discourse.julialang.org/u/Stuart_Rogers)\
**Post date:** [February 23, 2025, 7:36pm UTC](https://discourse.julialang.org/t/save-jump-model-to-file/126220/1 "2025-02-23T19:36:16Z")

</div>

I want to save a JuMP model to a .MPS file without appending .MPS to the filename in the second argument to `write_to_file`, .i.e. not using `write_to_file(model,"test.MPS")`. The approach below does not work.

> **[JuMP · JuMP](https://jump.dev/JuMP.jl/stable/api/JuMP/#write_to_file)**
>
> Documentation for JuMP.

> <https://github.com/jump-dev/MathOptInterface.jl/blob/v1.35.2/src/FileFormats/FileFormats.jl#L23-L36>

```julia
julia> using JuMP

julia> model = Model()
A JuMP Model
├ solver: none
├ objective_sense: FEASIBILITY_SENSE
├ num_variables: 0
├ num_constraints: 0
└ Names registered in the model: none

julia> write_to_file(model,"test", FORMAT_MPS)
ERROR: UndefVarError: `FORMAT_MPS` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

```

---

<div class="post-metadata">

**Author:** ![Stuart\_Rogers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stuart_rogers/32/10694_2.png) [@Stuart\_Rogers](https://discourse.julialang.org/u/Stuart_Rogers)\
**Post date:** [February 23, 2025, 8:03pm UTC](https://discourse.julialang.org/t/save-jump-model-to-file/126220/2 "2025-02-23T20:03:53Z")

</div>

The approach below generates an MPS file named `test`. Is it possible to have `write_to_file` generate an MPS file named `test.MPS` without explicitly passing `test.MPS` as the second argument to `write_to_file`?

```julia
write_to_file(model, "test", format = MOI.FileFormats.FORMAT_MPS)

```

---

<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:** [February 23, 2025, 8:38pm UTC](https://discourse.julialang.org/t/save-jump-model-to-file/126220/3 "2025-02-23T20:38:07Z")

</div>

> Is it possible to have `write_to_file` generate an MPS file named `test.MPS` without explicitly passing `test.MPS` as the second argument to `write_to_file`

No. We either infer the file format from the extension, or you must pass the `format` kwarg, in which case we do not care about the extension of `filename`.

However, this is trivially fixed by defining your own function:

```Julia
function write_mps_to_file(model, filename)
    return JuMP.write_to_file(model, filename * ".mps")
end

```
