Issues with exportModel in amplpy

Hi!
I am implementing some callbacks to the solver using amplpy in Jupyter notebook, and I’m having some strange problems with exportModel. The respective code line is:

ampls_model=ampl.exportModel(solver,[“return_mipgap=5”])
#My base solver is CPLEX

Since I work from different places, I use until 3 machines for that. So, in the first machine that line works well, while in the second one I get the following error:

TypeError: AMPL.export_model() takes 2 positional arguments but 3 were given

And, in the third machine that line works well with CPLEX but get the previous error when I switched the solver to Gurobi.

Any ideas of the root of the issue, and how to avoid it?, please

Thanks in advance

1 Like

Hi @Jonathan,

Thanks for reporting this issue. There was a release of amplpy-cplex last week that by mistake did not include the options in the export functions. Could you please try installing the previous pip install amplpy-cplex==0.1.0b18 --upgrade and see if the problem persists? We should release amplpy-cplex again in a few days with the options as second argument like before.

1 Like

Hi @Jonathan,

amplpy_cplex and amplpy_gurobi v0.1.2 have just been released and export model has options again. Note, however, that the method exportModel is now called to_ampls, so after upgrading you should update your code to:

ampls_model = ampl.to_ampls(solver, ["return_mipgap=5"])

Hi Filipe,
Thanks a lot for your effort to update the amplpy_gurobi. Everything is going well now.

1 Like

Hi Filipe,
Sorry to add a new problem. After using ampls_model = ampl.to_ampls(solver, [“return_mipgap=5”]), my routine callback.setCurrentGap() doesn’t work because the command “setAMPLsParameter” is not recognized anymore. So, I thought that the command changed its name to “setAMPLParameter”, but it doesn’t work either. Please, can you tell me if there is a new command for that?
My callback.setCurrentGap() routine:

def setCurrentGap(self):
gaptolpct = 100*self._stoprule[‘gaptol’][self._current]
stopnodes = self._stoprule[‘nodes’][self._current]
print(“Increasing gap tolerance to "
f”{gaptolpct:.2f}% after {stopnodes:.1f} nodes")
ampls_model.setAMPLsParameter(ampls.SolverParams.DBL_MIPGap,
self._stoprule[‘gaptol’][self._current])
self._current += 1

Thanks

Atte.

Hi Johnatan,
I am Christian, principal developer of the ampls libs. I am investigating this, will let you know shortly.
Thanks to you for all your feedback and for coping with us as we restructure the libs.
Christian

1 Like

Hi again,

took me a bit to track it down to the technique we use to be able to use native Python enums in place of C ones. A fix i in progress but i will not be able to release it today.
In the meantime, you could use the function setAMPLParameter with the enumeration value, on the lines of:

model.setAMPLParameter(ampls.SolverParams.DBL_MIPGap.value, gapvalue)

Note that the code above will continue working even after the fix; I will keep you posted on the next release.

1 Like