Fastest interaction between GAMS and Python

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
SBR
User
User
Posts: 1
Joined: 3 weeks ago

Fastest interaction between GAMS and Python

Post by SBR » 3 weeks ago

Hello,
I need to run successively hundred of thousand times a small model in python, with each time different dimensions and values for the sets and parameters.
Before parallelizing, I'd like to know if there are few tricks to reduce computation time.
What is the faster ?
  • load model from string or from file ?
  • creating a database once and update with sync each time or creating the db each time ?
  • what about dynamically writing in python the dataset in the model stream ?
  • other tricks ?
To finish, what is the solution to run a model without temporary files (gdx, lst, etc.) ?
I have found in the documentation options Suppress but I don't know how to use it:

Code: Select all

opt.defines['suppress'] = "SuppressCompilerListing" ?
Would it fix my problem ?

Thanks a lot in advance
Best regards

Serge

Clemens
Posts: 24
Joined: 1 year ago

Re: Fastest interaction between GAMS and Python

Post by Clemens » 3 weeks ago

Serge,

1) Loading a model form string or from file is very unlikely to make any difference in terms of performance. In any case a GamsJob will result in a file containing the source code when the run() method is called.
2) This depends on your specific situation. If large parts of the GamsDatabase remain the same, updating only certain symbols might be faster than creating a GamsDatabase from scratch all the time.
3) Do you mean putting the data directly into the GAMS source code?
4) Without knowing the architecture of your program it is hard to make assumptions about any performance bottlenecks and their solution. If you have multiple very similar GAMS models to solve, the GamsModelInstance might be interesting for you. You might also want to have a look at the SolveLink option: https://www.gams.com/latest/docs/UG_Gam ... Osolvelink

Regarding the suppression of certain output:
This will suppress the compiler listing in the .lst file:

Code: Select all

opt.suppress = Suppress.SuppressCompilerListing
This will prevent the creation of the out database:

Code: Select all

t1.run(create_out_db = False)
Hope that helps,
Clemens

Post Reply