# Serialized and deserialized JuMP CPLEX models are not the same

**URL:** <https://discourse.julialang.org/t/serialized-and-deserialized-jump-cplex-models-are-not-the-same/73194>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, cplex, serialization\
**Created:** [December 16, 2021, 10:42am UTC](https://discourse.julialang.org/t/serialized-and-deserialized-jump-cplex-models-are-not-the-same/73194 "2021-12-16T10:42:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Post date:** [December 16, 2021, 10:42am UTC](https://discourse.julialang.org/t/serialized-and-deserialized-jump-cplex-models-are-not-the-same/73194/1 "2021-12-16T10:42:16Z")

</div>

I want to run some long simulations with JuMP. After the simulations ends, I will start with the metaanalysis. So what I wanted to do is store the solved model in the filesystem and analyze it afterwards.  
During my pre-testing I realized that the model is serialized in the filesystem as not solved, although it is.

Is this a desired behavior ? if not is it a JuMP, a CPLEX or a Serialization problem ?

Minimal example script:

```julia
ENV["CPLEX_STUDIO_BINARIES"] = "my/path/to/CPLEX/bins";
using JuMP
using CPLEX
using Serialization

model = Model(CPLEX.Optimizer)
@variable(model, x >= 0)
@variable(model, 0 <= y <= 3)
@objective(model, Min, 12x + 20y)
@constraint(model, c1, 6x + 8y >= 100)
@constraint(model, c2, 7x + 12y >= 120)
optimize!(model)

serialize("model.dat", model)
modelde = deserialize("model.dat")

@show model |> termination_status
@show modelde |> termination_status

```

which prints:

```julia
model |> termination_status = MathOptInterface.OPTIMAL
modelde |> termination_status = MathOptInterface.OPTIMIZE_NOT_CALLED

```

---

<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:** [December 16, 2021, 5:36pm UTC](https://discourse.julialang.org/t/serialized-and-deserialized-jump-cplex-models-are-not-the-same/73194/2 "2021-12-16T17:36:57Z")

</div>

You cannot serialize jump models like this.

The solutions are stored inside the CPLEX model which is not written to disk on serialize.

(All Julia sees is a pointer to the CPLEX memory.)

There are no workarounds. You should compute the results you want to save and write them to disk, not the jump model.
