# Issues with exportModel in amplpy

**URL:** <https://discuss.ampl.com/t/issues-with-exportmodel-in-amplpy/581>\
**Category:** Support\
**Tags:** errors-and-messages\
**Created:** [May 29, 2023, 4:36pm UTC](https://discuss.ampl.com/t/issues-with-exportmodel-in-amplpy/581 "2023-05-29T16:36:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/jonathan/32/313_2.png) [@Jonathan](https://discuss.ampl.com/u/Jonathan)\
**Post date:** [May 29, 2023, 4:36pm UTC](https://discuss.ampl.com/t/issues-with-exportmodel-in-amplpy/581/1 "2023-05-29T16:36:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [May 29, 2023, 5:13pm UTC](https://discuss.ampl.com/t/issues-with-exportmodel-in-amplpy/581/2 "2023-05-29T17:13:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [June 5, 2023, 1:41pm UTC](https://discuss.ampl.com/t/issues-with-exportmodel-in-amplpy/581/3 "2023-06-05T13:41:13Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![Jonathan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/jonathan/32/313_2.png) [@Jonathan](https://discuss.ampl.com/u/Jonathan)\
**Post date:** [June 5, 2023, 8:21pm UTC](https://discuss.ampl.com/t/issues-with-exportmodel-in-amplpy/581/4 "2023-06-05T20:21:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jonathan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/jonathan/32/313_2.png) [@Jonathan](https://discuss.ampl.com/u/Jonathan)\
**Post date:** [June 8, 2023, 9:42pm UTC](https://discuss.ampl.com/t/issues-with-exportmodel-in-amplpy/581/5 "2023-06-08T21:42:57Z")

</div>

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._

---

<div class="post-metadata">

**Author:** ![mapgccv](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/mapgccv/32/17_2.png) [@mapgccv](https://discuss.ampl.com/u/mapgccv)\
**Post date:** [June 13, 2023, 10:17am UTC](https://discuss.ampl.com/t/issues-with-exportmodel-in-amplpy/581/6 "2023-06-13T10:17:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mapgccv](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/mapgccv/32/17_2.png) [@mapgccv](https://discuss.ampl.com/u/mapgccv)\
**Post date:** [June 15, 2023, 5:15am UTC](https://discuss.ampl.com/t/issues-with-exportmodel-in-amplpy/581/7 "2023-06-15T05:15:09Z")

</div>

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:

```auto
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.
