The issue to connect gamspy and NEOS

Dear support team,

I hope you are doing well. I am having an issue to run the model with the Neos server. The model is as follows:

from gamspy import Container, Variable, Equation, Model, Sense, Problem, NeosClient
import gamspy as gp 

m = gp.Container() 
x1 = gp.Variable(m) 
x2 = gp.Variable(m) 
x3 = gp.Variable(m) 

eq1 = gp.Equation(m) 
eq2 = gp.Equation(m) 
eq3 = gp.Equation(m) 

eq1[...] = x1 + 2 * x2 >= 3 
eq2[...] = x3 + x2 >= 5 
eq3[...] = x1 + x3 == 4 
obj = x1 + 3 * x2 + 3 * x3 

LP1 = gp.Model( m, equations=m.getEquations(), problem="lp", sense="min", objective=obj ) 

client= NeosClient(email="<abb.omidi@gmail.com>") 
LP1.solve(backend="neos", client=client)

and the error would be:

[NEOS - INFO] Job Number: 0, Job Password: Error parsing XML file: line 6, column 29
INFO:NEOS:Job Number: 0, Job Password: Error parsing XML file: line 6, column 29
---------------------------------------------------------------------------
NeosClientException                       Traceback (most recent call last)
<ipython-input-20-560949da0714> in <cell line: 25>()
     23 import os
     24 client= NeosClient(email="<abb.omidi@gmail.com>")
---> 25 LP1.solve(backend="neos", client=client)

3 frames
/usr/local/lib/python3.10/dist-packages/gamspy/_backend/neos.py in submit_job(self, output, xml_path, is_blocking, working_directory)
    387 
    388         if job_number == 0:
--> 389             raise NeosClientException(f"NEOS Server error! {job_password}")
    390 
    391         if is_blocking:

NeosClientException: NEOS Server error! Error parsing XML file: line 6, column 29

I was wondering if, how can I fix that?
All the best

Collecting gamspy
  Downloading gamspy-1.0.0-py3-none-any.whl.metadata (6.2 kB)
Collecting gamsapi==47.5.0 (from gamsapi[control,transfer]==47.5.0->gamspy)
  Downloading gamsapi-47.5.0-cp310-cp310-manylinux_2_17_x86_64.whl.metadata (5.5 kB)
Collecting gamspy-base==47.5.0 (from gamspy)
  Downloading gamspy_base-47.5.0-py3-none-manylinux_2_17_x86_64.whl.metadata (1.5 kB)

Hi @abb.omidi ,

You have to remove the angle brackets. The following should work.

client= NeosClient(email="abb.omidi@gmail.com") 

I hope this helps!

Fred

Dear Fred,

Many thanks for your answer. It can solve my issue.
However, I have a follow-up question. Would you please, say how I can set a specific solver to run on the Neos? What I tried is something like this

import sys
import os
client= NeosClient(email="abb.omidi@gmail.com")
model_1.solve(solver= "cplex", output = sys.stdout, backend="neos", client=client)

but it throws an error as:

[NEOS - INFO] Job Number: 0, Job Password: Error: mip:cplex:GAMS is not a valid option on the NEOS Server
INFO:NEOS:Job Number: 0, Job Password: Error: mip:cplex:GAMS is not a valid option on the NEOS Server
---------------------------------------------------------------------------
NeosClientException                       Traceback (most recent call last)
<ipython-input-10-55750541f138> in <cell line: 33>()
     31 import os
     32 client= NeosClient(email="abb.omidi@gmail.com")
---> 33 transport.solve(solver= "cplex", output = sys.stdout, backend="neos", client=client)

3 frames
/usr/local/lib/python3.10/dist-packages/gamspy/_backend/neos.py in submit_job(self, output, xml_path, is_blocking, working_directory)
    387 
    388         if job_number == 0:
--> 389             raise NeosClientException(f"NEOS Server error! {job_password}")
    390 
    391         if is_blocking:

NeosClientException: NEOS Server error! Error: mip:cplex:GAMS is not a valid option on the NEOS Server

Best regards

Dear Fred,

Would you confirm that the following can solve my issue:

mode_1.solve(output = sys.stdout, backend="neos", client=client, options=Options(mip="cplex"))

All the best

Yes, but you need to add Options to the initial import statement.

Best,
Fred

Not sure why this fails. Maybe you can share a reproducible example instead of just a snippet?

Thanks,
Fred

Dear Fred,

This is a tiny model which can reproduce the error:

from gamspy import Container, Variable, Equation, Model, Sense, Problem, NeosClient
import gamspy as gp

mdl = gp.Container()
x1 = gp.Variable(mdl, type= 'integer')
x2 = gp.Variable(mdl, type= 'integer')
x3 = gp.Variable(mdl, type= 'integer')

eq1 = gp.Equation(mdl)
eq2 = gp.Equation(mdl)
eq3 = gp.Equation(mdl)
eq1[...] = x1 + 2 * x2 >= 3
eq2[...] = x3 + x2 >= 5
eq3[...] = x1 + x3 == 4
obj = x1 + 3 * x2 + 3 * x3

LP1 = gp.Model( mdl, equations=mdl.getEquations(), problem="mip", sense="min", objective=obj )

import sys
import os
client= NeosClient(email="abb.omidi@gmail.com")
LP1.solve(solver= "cplex", output = sys.stdout, backend="neos", client=client)

Best

Thank you so much.
I am unsure to fully understand what you mean by to add Options to the initial import statement. as the model seems to run without any error. Could you write what you proposed as the initial import?

Regards

The problem is caused by the name mismatch between GAMSPy and NEOS Server. In GAMSPy, mixed integer problems are abbreviated as MIP but on NEOS Server it is abbreviated as MILP. This will be fixed soon.

1 Like

You were asking if the following works

mode_1.solve(output = sys.stdout, backend="neos", client=client, options=Options(mip="cplex"))

I wasn’t aware of the name mismatch MIP vs MILP, so the statement looked fine for me but it uses solve options. Solve options can be specified using the gamspy.Options() class. Hence you need to make sure to add

from gamspy import Options

which you did not have in your initial post.

I hope this helps!

Fred

Dear Fred,
Dear Muhammet,

Many thanks for your helps.
Please, inform us when the issue is fixed.

Best regards
Abbas

@abb.omidi This issue has been fixed with GAMSPy 1.0.1. Your code snippet to run the mip model on NEOS Server should work fine now.

Dear support team,

Many thanks. Now, it seems everything works well. ( :ok_hand:)

All the best

Just out of curiosity, is CPLEX the only solver that can be reached via Neos by the following?

model_1.solve(solver= "CPLEX", output = sys.stdout, backend="neos", client=client)

e.g. when I tried to set xpress, it threw the following error:

ValidationError: Provided solver name `xpress` is not installed on your machine. Install `xpress` with `gamspy install solver xpress`

No. You should be able to use all problem type - solver pairs from this list: NEOS Solvers

This validation check needs to be done only for the local backend. We will fix it in the next release. As a workaround, you can just run gamspy install solver xpress and send your job to NEOS.

Dear Muhammet,

Thank you so much.

Regards