-
Notifications
You must be signed in to change notification settings - Fork 546
Modified _parse_gdx_results in GAMS.py to replace _parse_special_value and Updated Import Statement #3642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
from pyomo.common.dependencies import attempt_import | ||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a hard dependency on numpy. Importing numpy from dependencies
will keep this as a "soft" dependency:
from pyomo.common.dependencies import attempt_import | |
import numpy as np | |
from pyomo.common.dependencies import attempt_import, numpy as np |
It will still make numpy a hard dependency if you are going to use GAMS, but that is OK (although GAMS's available() should probably check both numpy_available and gdxcc_available)
…Removed the unused _parse_special_values function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor nits and I think this is good to merge (once we get the testing infrastructure back up and working)!
specVals[gdxcc.GMS_SVIDX_UNDEF] = float("nan") | ||
specVals[gdxcc.GMS_SVIDX_PINF] = float("inf") | ||
specVals[gdxcc.GMS_SVIDX_MINF] = float("-inf") | ||
specVals[gdxcc.GMS_SVIDX_NA] = struct.unpack(">d", bytes.fromhex("fffffffffffffffe"))[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not just float('nan')
?
@@ -1299,7 +1324,7 @@ def _parse_gdx_results(self, results_filename, statresults_filename): | |||
raise RuntimeError("GAMS GDX failure (gdxDataReadRaw).") | |||
|
|||
if stat in ('OBJEST', 'OBJVAL', 'ETSOLVE'): | |||
stat_vars[stat] = self._parse_special_values(ret[2][0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we can also remove / delete the _parse_special_values
method?
Fixes #3624
Summary/Motivation:
When parsing the results of a model after it has been solved, the level and dual value are obtained through a series of
if
statements in_parse_special_values
that may cause slowdowns. This PR added GAMS existing functions to handle data parser for these special values in_parse_gdx_results
.Changes proposed in this PR:
_parse_special_values
with GAMS special value parser in_parse_gdx_results
.attempt_import
to have fallback to pre-GAMS-45.0 API ifgams.core.gdx
is not available.Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: