Loop through symbols in gdx

Hey,

I think I’ve found a bug while trying to loop through all symbols in a gdx file with the Python API.

Consider the following code:

ws = gams.control.GamsWorkspace(system_directory=gams_path)
gdx_db = ws.add_database_from_gdx(gdx_file)
for sym in gdx_db:
print(sym)

It works fine with the 47.6.0 version of the Python API but if I upgrade it to 48.6.0, then there is the following error:

File “c:\Users\bfsan\OneDrive\Desktop\minimum.py”, line 13, in
for sym in gdx_db:
^^^^^^
File “C:\Users\bfsan\anaconda3\envs\test_gams\Lib\site-packages\gams\control\database.py”, line 1400, in next
return self.next()
^^^^^^^^^^^
File “C:\Users\bfsan\anaconda3\envs\test_gams\Lib\site-packages\gams\control\database.py”, line 1383, in next
self._check_for_gmd_error(_int_value_and_free(rc))
File “C:\Users\bfsan\anaconda3\envs\test_gams\Lib\site-packages\gams\control\database.py”, line 1289, in _check_for_gmd_error
raise gams.control.workspace.GamsException(msg, workspace)
gams.control.workspace.GamsException: Symbol index 28 is out of range

In this example, there were exactly 28 symbols in the gdx, so it seems to be some sort of off-by-one error.

Hi,

Perhaps you have a mismatch between the Python API version and the GAMS version. You should see a warning in this case, something like this: --- Warning: The GAMS version (47.6.0) differs from the API version (48.6.0)..
You can also verify manually that the versions match by running the following code:

import gams

ws = gams.GamsWorkspace()
print(f"GAMS version: {ws.version}")
print(f"API version: {gams.__version__}")

Best,
Clemens

Hi Clemens,

You are right that there is a mismatch between versions. My GAMS version was 45.7.0, while I tried Python API versions 47.6.0 and 48.6.0.