model2tex on macOS

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
hermann.westerholt
User
User
Posts: 13
Joined: 1 year ago

model2tex on macOS

Post by hermann.westerholt » 1 year ago

Hi,

I am currently using GAMS 24.9 for macOS High Sierra 10.13.3 in combination with Python 2.7.10, and I would love to use the neat model2tex feature.

After a first few failed attempts and a bit of research on the web, I downloaded the attached file model2tex1.gms (which I found here). This is the output I get when I try to run "gams model2tex1.gms":

Code: Select all

gams model2tex1.gms
--- Job model2tex1.gms Start 01/31/18 13:03:50 24.9.2 r64480 DEX-DEG x86 64bit/Mac OS X
GAMS 24.9.2   Copyright (C) 1987-2017 GAMS Development. All rights reserved
--- Starting compilation
--- model2tex1.gms(5) 2 Mb
--- call gamslib -q trnsport
--- model2tex1.gms(7) 2 Mb
--- call rm -f transport.tex
--- model2tex1.gms(9) 2 Mb
--- call gams trnsport lo=1 docFile=transport
--- Job trnsport Start 01/31/18 13:03:50 24.9.2 r64480 DEX-DEG x86 64bit/Mac OS X
GAMS 24.9.2   Copyright (C) 1987-2017 GAMS Development. All rights reserved
--- Starting compilation
--- trnsport.gms(68) 3 Mb
--- RefFile /myFolder/transport.ref
--- DocFile /myFolder/transport.txt
--- GDX File /myFolder/transport.gdx
*** Status: Normal completion
--- Job trnsport.gms Stop 01/31/18 13:03:50 elapsed 0:00:00.010
***
*** Abort we should have python available
***
--- model2tex1.gms(16) 2 Mb 1 Error
*** Status: Compilation error(s)
--- Job model2tex1.gms Stop 01/31/18 13:03:50 elapsed 0:00:00.102
The error message that "we should have python available" is quite confusing to me since a quick python check reveals:

Code: Select all

python
Python 2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Any suggestions as to how to solve this problem are highly appreciated. Thank you in advance.

Best regards,
Hermann
Attachments
model2tex1.gms
(952 Bytes) Downloaded 47 times

User avatar
Clemens
Posts: 39
Joined: 2 years ago

Re: model2tex on macOS

Post by Clemens » 1 year ago

Hermann,

The GAMS file you found is part of the GAMS Test Library which is primarily designed to be used for testing by the GAMS staff. Therefore certain models in this library might have specific prerequisites. For model2tex1.gms, an environment variable called PYTHON27 needs to be set to a Python 2.7 interpreter. You should be able to do this by executing the following code from a Terminal:

Code: Select all

export PYTHON27=/usr/local/bin/python2.7
gams model2tex1.gms
You might need to adjust the path in case your Python interpreter is located in a different location.
I would also be interested in seeing the error you get from running model2tex on your actual model.

Best,
Clemens

hermann.westerholt
User
User
Posts: 13
Joined: 1 year ago

Re: model2tex on macOS

Post by hermann.westerholt » 1 year ago

Dear Clemens,

Thank you very much for your fast answer and apologies for unintentionally poking my nose into the GAMS test library. I am glad to hear, though, that there is a reason why the contents of this GAMS file looked slightly more mysterious to me than the ones I usually find on the site.

I slightly modified your code to point to my python installation located at

Code: Select all

/usr/bin/python2.7
and ran it.
  • bad news: code still crashes
  • good news: it does so consistently, i.e. I get the same error message for model2tex1.gms that I got for my actual model
Result for model2tex1.gms:

Code: Select all

gams model2tex1.gms
--- Job model2tex1.gms Start 01/31/18 18:43:27 24.9.2 r64480 DEX-DEG x86 64bit/Mac OS X
GAMS 24.9.2   Copyright (C) 1987-2017 GAMS Development. All rights reserved
Licensee: GAMS Development Corporation, USA              G871201/0000CA-ANY
          Free Demo, +1 202-342-0180, support@gams.com, www.gams.com DC0000
--- Starting compilation
--- model2tex1.gms(5) 2 Mb
--- call gamslib -q trnsport
--- model2tex1.gms(7) 2 Mb
--- call rm -f transport.tex
--- model2tex1.gms(9) 2 Mb
--- call gams trnsport lo=1 docFile=transport
--- Job trnsport Start 01/31/18 18:43:27 24.9.2 r64480 DEX-DEG x86 64bit/Mac OS X
GAMS 24.9.2   Copyright (C) 1987-2017 GAMS Development. All rights reserved
Licensee: GAMS Development Corporation, USA              G871201/0000CA-ANY
          Free Demo, +1 202-342-0180, support@gams.com, www.gams.com DC0000
--- Starting compilation
--- trnsport.gms(68) 3 Mb
--- RefFile /myFolder/transport.ref
--- DocFile /myFolder/transport.txt
--- GDX File /myFolder/transport.gdx
*** Status: Normal completion
--- Job trnsport.gms Stop 01/31/18 18:43:27 elapsed 0:00:00.010
--- model2tex1.gms(20) 2 Mb
--- call /usr/bin/python2.7 /Applications/GAMS24.9/sysdir/model2tex.py transport > /dev/null
Traceback (most recent call last):
  File "/Applications/GAMS24.9/sysdir/model2tex.py", line 17, in <module>
    _gdxcc = swig_import_helper()
  File "/Applications/GAMS24.9/sysdir/model2tex.py", line 16, in swig_import_helper
    return importlib.import_module('_gdxcc')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: dlopen(/Applications/GAMS24.9/sysdir/_gdxcc.so, 2): Library not loaded: @loader_path/../../../libgcc_s.1.dylib
  Referenced from: /Applications/GAMS24.9/sysdir/_gdxcc.so
  Reason: image not found
--- model2tex1.gms(21) 2 Mb
***
*** Abort could not run python
***
--- model2tex1.gms(21) 2 Mb 1 Error
*** Status: Compilation error(s)
--- Job model2tex1.gms Stop 01/31/18 18:43:27 elapsed 0:00:00.214

And, for the sake of completeness, for my actual model:

Code: Select all

python /Applications/GAMS24.9/sysdir/model2tex.py AluSale
Traceback (most recent call last):
  File "/Applications/GAMS24.9/sysdir/model2tex.py", line 17, in <module>
    _gdxcc = swig_import_helper()
  File "/Applications/GAMS24.9/sysdir/model2tex.py", line 16, in swig_import_helper
    return importlib.import_module('_gdxcc')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: dlopen(/Applications/GAMS24.9/sysdir/_gdxcc.so, 2): Library not loaded: @loader_path/../../../libgcc_s.1.dylib
  Referenced from: /Applications/GAMS24.9/sysdir/_gdxcc.so
  Reason: image not found

User avatar
Clemens
Posts: 39
Joined: 2 years ago

Re: model2tex on macOS

Post by Clemens » 1 year ago

Hermann,

This is a bug that will be fixed in future releases of GAMS. Thank you very much for reporting this. The actual problem is a wrong library dependency in the file _gdxcc.so.
You can fix the problem on your machine by navigating into your GAMS system directory using a Terminal. In a sub directory called sysdir you will find the file _gdxcc.so which you need to modify using install_name_tool.

Code: Select all

cd /Applications/GAMS24.9/sysdir/
install_name_tool -change @loader_path/../../../libgcc_s.1.dylib @rpath/libgcc_s.1.dylib _gdxcc.so
Your actual GAMS system directory might be different, so you might need to adjust it. You just need to make sure that you are in the GAMS root directory. If you find the model2tex.py script in the directory then you are right.
You can use otool -L _gdxcc.so before and after install_name_tool in order to see if the change was applied.

Let me know if this helps,
Clemens

hermann.westerholt
User
User
Posts: 13
Joined: 1 year ago

Re: model2tex on macOS

Post by hermann.westerholt » 1 year ago

Clemens,

Thank you once again for the quick response. Thanks to your proposed fix, I am now able to run the test file and get the desired LaTeX output. Sadly, the same does not apply to my actual model but at least the problem now seems to be model-related.

Windows terminal output:

Code: Select all

U:\1_GMS>model2tex myModel
Traceback (most recent call last):
  File "model2tex.py", line 110, in <module>
  File "inst2py.py", line 357, in parseInstructions
IndexError: pop from empty list
Failed to execute script model2tex
macOS output (basically the same but slightly more detailed):

Code: Select all

python /Applications/GAMS24.9/sysdir/model2tex.py myModel
Traceback (most recent call last):
  File "/Applications/GAMS24.9/sysdir/model2tex.py", line 3120, in <module>
    modelRepr = parseInstructions(instEqu, uels, symDims, binVars)
  File "/Applications/GAMS24.9/sysdir/model2tex.py", line 1195, in parseInstructions
    op = [valStack.pop(), valStack.pop()]
IndexError: pop from empty list
Since the call to

Code: Select all

gams myModel.gms docFile=myModel
completes normally, I have no idea why parsing of the docfiles fails.

Thank you again for your help,
Hermann

User avatar
Clemens
Posts: 39
Joined: 2 years ago

Re: model2tex on macOS

Post by Clemens » 1 year ago

Hermann,

This seems to be related to your model. Is it possible to give me access to your model or to the files generated by the docFile command? A minimal example that generates this error would also be sufficient. GAMS syntax can be quite versatile and most likely there is another bug in model2tex itself which is revealed by your model.

Best,
Clemens

hermann.westerholt
User
User
Posts: 13
Joined: 1 year ago

Re: model2tex on macOS

Post by hermann.westerholt » 1 year ago

Clemens,

Please find attached the requested MWE. Uploading GDX files to the forum seems to be impossible, so I put the files into an archive. As you can see, most of my modelling is done in Matlab and I use the Matlab-GAMS interface GDXMRW. Could this possibly be the problem?

Best,
Hermann
Attachments
Archiv.zip
(27.58 KiB) Downloaded 53 times

User avatar
Clemens
Posts: 39
Joined: 2 years ago

Re: model2tex on macOS

Post by Clemens » 1 year ago

Hermann,

The use of GAMS singleton sets in your model cause a problem in model2tex. The bug will be fixed in future releases of GAMS. Thank you very much for reporting this!

Best,
Clemens

hermann.westerholt
User
User
Posts: 13
Joined: 1 year ago

Re: model2tex on macOS

Post by hermann.westerholt » 1 year ago

Dear Clemens,

I got rid of the singleton set and it all works like a charm, thank you so much!

Best regards,
Hermann

Post Reply