gams-dev / gamspy Goto Github PK
View Code? Open in Web Editor NEWPython-based algebraic modeling interface to GAMS
License: Other
Python-based algebraic modeling interface to GAMS
License: Other
When running gamspy for different optimization problems the log file reports the following error, which then also triggers a core dump, while the process seems to continue running:
terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::type_error'
what(): [json.exception.type_error.316] invalid UTF-8 byte at index 0: 0xA0
We also observed the error with indifferent optimization models. In the small model, the error is thrown while already in the external solver calls - in this case the process terminates with results. In the large model, the error is thrown while gamspy is still executing the temporary gms files. Here the process gets stuck and does no longer continue.
The following software stack was used:
Rocky Linux 8.9
python 3.12.4
gamspy 0.13.5
Sorry I write the issue here, it was intended for https://github.com/GAMS-dev/gdx/ but there is no issue board in that repo. I was wondering if you are considering the implementation of a Rust API to work with GDX files. Maybe not a full GAMS interface but at least some handling tools would be great.
I upgraded to version 0.13.0 and ran gamspy install license
, but it failed (see traceback below). Downgraded to 0.12.7 and the same command is working.
Traceback (most recent call last):
File "C:\ProgramData\mambaforge\envs\langbench\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\ProgramData\mambaforge\envs\langbench\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\ProgramData\mambaforge\envs\langbench\Scripts\gamspy.exe\__main__.py", line 7, in <module>
File "C:\ProgramData\mambaforge\envs\langbench\lib\site-packages\gamspy\_cli\cmdline.py", line 479, in main
install(args)
File "C:\ProgramData\mambaforge\envs\langbench\lib\site-packages\gamspy\_cli\cmdline.py", line 278, in install
install_license(args)
File "C:\ProgramData\mambaforge\envs\langbench\lib\site-packages\gamspy\_cli\cmdline.py", line 148, in install_license
raise ValidationError(process.stderr)
gamspy.exceptions.ValidationError: The license ID used is not valid
Error: Failed to obtain license
I encountered a bug: A static bound on a variable x[s]
, e.g. x[s].lo = 0
, is not applied or rather overwritten when the statement is executed before the records of set s
have been defined via s.setRecords()
. I provide a small example below, where only the line x.lo = 0
has to be moved after the s.setRecords()
call to make the model feasible.
This is especially relevant when wanting to do the "instantiation" of the model (i.e. setting all records) after its abstract definition. Static variable bounds might still be set before the instantiation.
"InfeasibleNoSolution" when x.lo = 0
is executed before s.setRecords()
from gamspy import Container, Sum, Sense
c = Container()
s = c.addSet("s")
x = c.addVariable("x", type="free", domain=s)
m = c.addModel(
problem="LP",
name="test",
sense=Sense.MIN,
objective=Sum(s, 1 * x[s]))
x.lo = 0
s.setRecords(["a"])
m.solve()
"OptimalGlobal" when x.lo = 0
is executed after s.setRecords()
from gamspy import Container, Sum, Sense
c = Container()
s = c.addSet("s")
x = c.addVariable("x", type="free", domain=s)
m = c.addModel(
problem="LP",
name="test",
sense=Sense.MIN,
objective=Sum(s, 1 * x[s]))
s.setRecords(["a"])
x.lo = 0
m.solve()
Hi, just a small bug I encountered: Trying to solve a model whose name contains a space leads to a compilation error, but there is no clear indication that the name is invalid. Also, it should not be possible to assign an invalid name in the first place.
A small example:
from gamspy import Container, Model, Sum, Sense
c = Container()
a = c.addSet("a", records=["a"])
var = c.addVariable("v", domain=a)
eq = c.addEquation("eq", domain=a)
eq[a] = var[a] >= 1
m = Model(container=c,
name="with space",
problem="LP",
equations=c.getEquations(),
sense=Sense.MIN,
objective=Sum(a, var[a]))
m.solve()
This leads to the following error:
GamspyException:
================================================================================
Error Summary
================================================================================
58 solve with space using LP MIN autogenerated_8ef7b1ba_475c_4475_b4c7_a1462bf49f70_variable;
**** $812
**** LINE 4 INPUT [C:\Users\<user name redacted>\AppData\Local\Temp\tmp48vx2ty7\_job_35566420-2f8b-4031-ab1b-a3f87a5830fb.gms](file:///C:/Users/<user name redacted>/AppData/Local/Temp/tmp48vx2ty7/_job_35566420-2f8b-4031-ab1b-a3f87a5830fb.gms)
**** 812 Solve keys expected - USING MAX/MIN SCENARIO
Meaning of return code 2: There was a compilation error
Can gamspy solve neural network functions trained with pytorch as the objective function?the objective function like y=net(Xi)
, where net
is trained with pytorch.
Here's an example:
from gamspy import Container, Sum, Sense
ct = Container()
s = ct.addSet("s", records=[1, 2])
x = ct.addVariable("x", type="positive", domain=s)
eq = ct.addEquation("eq", domain=s)
eq[s].where[~s.first] = x[s] >= 1
m = ct.addModel(
problem="LP",
name="test",
sense=Sense.MIN,
equations=[eq],
objective=Sum(s, x[s]))
res = m.solve()
print(res)
m.toGams(".")
This results in the following output:
Solver Status Model Status Objective Num of Equations Num of Variables Model Type Solver Solver Time
0 Normal OptimalGlobal 1 2 3 LP CPLEX 0
Traceback (most recent call last):
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gams\transfer\containers\_container.py", line 147, in __getitem__
return self.data[sym]
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gams\transfer\_internals\casepreservingdict.py", line 62, in __getitem__
return self.data[self._casefolded_key_map[key.casefold()]]
KeyError: 's.first'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\rech_ge\Documents\workspace\simplesom\simplesom\test\to_gams_example.py", line 19, in <module>
m.toGams(".")
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gamspy\_model.py", line 796, in toGams
all_needed_symbols = sorted(all_symbols, key=sort_names)
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gamspy\_model.py", line 784, in sort_names
return PRECEDENCE[type(self.container[name])]
File "C:\ProgramData\mambaforge\envs\simplesom\lib\site-packages\gams\transfer\containers\_container.py", line 149, in __getitem__
raise KeyError(
KeyError: 'Attempted retrieval of symbol `s.first`, but `s.first` does not exist in the Container'
The model is fine, but toGams()
fails. So GAMSPy must be using a different toGams()
function under the hood?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.