Did anyone have experiences with Pyomo and GAMS as solver? I had looked into the pyomo documentation (GAMSShell Solver) and in the CPLEX Manuals, but doesnt find the correct syntax.

My Code looks like:

slv = SolverFactory('gams')
results = slv.solve(model, tee=True,timelimit=100)

I have also tried it with the io_options=dict(timelimit=100):

results = slv.solve(model,tee=True,io_options=io_options)

I get all time the error: "ValueError - GAMS writer passed unrecognized io_options". I think the problem I have is that I havent the correct parameter to set the time limit over the Python GAMS API.

Did anyone know how I can set the time limit with the GAMS Python API ?

  • $\begingroup$ Welcome to OR.SE. Why do not you try using Pyomo itself instead of GAMS or vice versa? $\endgroup$
    – A.Omidi
    Sep 29, 2020 at 9:29
  • $\begingroup$ Hi and welcome to OR.SE. Did you import GAMSShell in your script? If you did, what does this comment prints? print(GAMSShell.available()) in your code? Could you use GAMS without io_options? $\endgroup$ Sep 29, 2020 at 16:25

1 Answer 1


Which options to use

The problem is that the "time limit" is not handled by Pyomo (which just connects to a solver), but by the solver itself. Different solvers have different names for "time limit" options. See this StackOverflow post about that. The timelimit option you're setting above would work for CPLEX, but maybe not for GAMS (see next paragraph).

I happen to use GAMS with Pyomo, and I know that GAMS uses an option called resLim. This webpage lists all GAMS options. Note that GAMS, like Pyomo, really just interfaces to lower-level solver executables, and some GAMS options depend on which solver you're using. The link above differentiates between "solver-specific" parameters. GAMS seems to do a good job of making this process easy - for example, the CPLEX solver has a timelimit option, and GAMS will automatically pass your value for the resLim option as timelimit if you are calling a CPLEX solver via GAMS. (I believe you can also pass options to GAMS and specify which solver they should apply to in the case of a GAMS solver that uses subsolvers, for example option CPLEX.timelimit=100;, but I can't find documentation on this).

Passing options (via Pyomo)

Usually to set a solver option, you should use io_options rather than passing a keyword argument directly to solve (though that may sometimes work).

results = slv.solve(model,tee=True,io_options=io_options)

Note that you may want to put many options for your GAMS solver in a file. This could be helpful if you call many solvers via GAMS, and you want them all to have different options specified, and you don't want this to clutter your Python code. Instead, you can just tell GAMS "check the DICOPT options file for DICOPT options, etc.". Let's say you're using the DICOPT solver via GAMS, and you have dozens of options. You can store them in a file called DICOPT.opt in your GAMS working directory that looks like this

max_iter 200000
resLim 100

then tell Pyomo to read from the file like this:

io_options = dict(
results = slv.solve(model,tee=True,io_options=io_options)

This tells GAMS to look for the correct file (that is, SOLVERNAME.opt) and read options from it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.