Be careful when using a third-party API to write a model file
Many users call the Gurobi solver through third-party APIs like JuMP.jl, CVXPY, or Pyomo. Such tools may not provide a way to write an MPS model file to disk. Even if the interface is able to write an MPS file, the model file is likely constructed by the third-party API, not Gurobi's internal file-writer. As a result, the generated MPS model file will almost certainly not match the model stored internally by Gurobi.
Use Gurobi to write a model file
When using third-party solver interfaces, you can direct Gurobi to write an MPS file by setting the GURO_PAR_DUMP parameter to 1.
If you are not sure how to pass parameters to the third-party API or if the API doesn't allow you to set this parameter, you can use a Gurobi environment file. This involves creating a text file named gurobi.env in the current working directory for your application (the directory where you launch the process). The gurobi.env file should contain the following line:
When the optimization starts, the solver generates the following files in the current working directory: gurobi.mps, gurobi.prm, and gurobi.attr. To anonymize the names of variables and constraints in the MPS model file, you can additionally add the line
IGNORENAMES 1 to the gurobi.env file.
Note that the generated files are overwritten by the most recent optimization run. Additionally, the GURO_PAR_DUMP parameter is not supported with Gurobi Instant Cloud.