Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to print the solvers in memory representation #3948

Closed
joaquimg opened this issue Feb 23, 2025 · 7 comments · Fixed by #3956
Closed

Add option to print the solvers in memory representation #3948

joaquimg opened this issue Feb 23, 2025 · 7 comments · Fixed by #3956

Comments

@joaquimg
Copy link
Member

Writing?

model = Model(HiGHS.Optimizer)
@variable(model, p1, set = Parameter(1.0))
@variable(model, p2 == 1.0)
write_to_file(model, "model.mps")
optimize!(model)
highs = unsafe_backend(model).inner
tmp_filename = "model.mps"
HiGHS.Highs_writeModel(highs, tmp_filename)

is hard for non-super-heavy users.

This is helpful for people with minimal understanding of solution methods.

@odow
Copy link
Member

odow commented Feb 23, 2025

is hard for non-super-heavy users.

Should these users be printing out the internal model? I wouldn't really be in favor of them doing that.

This is also quite solver-dependent. Maybe it just needs better documentation in each solver's README.

Having said that, perhaps we could make MOI.write_to_file(::HiGHS.Optimizer, filename::String) work, and have write_to_file(model, "model.mps"; use_internal_solver_method = true)

@odow
Copy link
Member

odow commented Feb 24, 2025

I looked into this. The current isn't too bad:

using JuMP, HiGHS
model = Model(HiGHS.Optimizer)
@variable(model, x >= 1)
optimize!(model)
Highs_writeModel(unsafe_backend(model), "model.mps")

we could perhaps make it

using JuMP, HiGHS
model = Model(HiGHS.Optimizer)
@variable(model, x >= 1)
optimize!(model)
MOI.write_to_file(unsafe_backend(model), "model.mps")

I'm not really sure who this method is aimed at. Someone who wants to deeply introspect the solver's model, knowing that there is a bug somewhere between JuMP and the solver, so JuMP.write_to_file(model) doesn't work, but also has no understanding of Highs_writeModel?

@blegat
Copy link
Member

blegat commented Feb 24, 2025

It's also sometimes useful when you're transitioning from ... to JuMP and get different answers and want to check what's the difference. MOI.write_to_file(unsafe_backend(model), "model.mps") is the right way to do it, I don't think we need other changes

@joaquimg
Copy link
Member Author

I like:
MOI.write_to_file(unsafe_backend(model), "model.mps")
Documenting it should solve the issue.
Some places where is might be useful:
1 - debug tutorial
2 - transitioning tutorial
3 - reference in the write_to_file docstring
4 - the solver readme

@odow
Copy link
Member

odow commented Feb 25, 2025

@odow
Copy link
Member

odow commented Feb 25, 2025

I think there's an argument for (3) and (4). Strong disagreement about (2), and moderate disagreement about (1).

In almost every case, write_to_file(model, filename) should be sufficient. If someone is using Gurobi AND they are using things like nonlinear AND they want Gurobi's custom MPS format to send support, then there is an argument. But I don't see how an MPS file is useful to someone debugging unless there is a bug in the MOI file writers.

@odow
Copy link
Member

odow commented Feb 25, 2025

Re (4): I opened a PR do document how to write an MPS file for support in Gurobi: jump-dev/Gurobi.jl#613

My other issue with something generic is that it really applies only to Gurobi/CPLEX/Xpress/HiGHS/Mosek. It won't apply for Ipopt, or SCS, or any number of other solvers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants