Fastest interaction between GAMS and Python

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

Fastest interaction between GAMS and Python

Post by SBR » 2 months 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: 25
Joined: 2 years ago

Re: Fastest interaction between GAMS and Python

Post by Clemens » 2 months 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

SBR
User
User
Posts: 2
Joined: 2 months ago

Re: Fastest interaction between GAMS and Python

Post by SBR » 1 month ago

Thanks a lot Clemens.
I already used the SolveLink Option, and still have performance problems (other modelers are 6x faster).

I do not keep .lst temporary files anymore since I use the supress option but still got a lot of temporary gdx files (50K for my use case!).
Regarding the

Code: Select all

create_out_db = False
you mentioned, do you confirm I won't be able to get Objective value if activated ?

Best regards

Serge

Post Reply