Converting Gurobipy Code for Use with AMPL

I wrote a long Python code using gurobipy and solved it with the Gurobi solver. I want to use another solver with AMPL. Do I need to manually rewrite the Python code written with gurobipy, or is there a way to convert it? I tried exporting the gurobipy model as an MSP or LP file and reading it with AMPL, but it didn’t work.

We have had a lot of good results using AI to translate from one modeling language to another. We have mainly used ChatGPT, but other AI chatbots may be worth trying. Start the chat with a request like this,

Translate the following gurobipy program to an amplpy program:

followed by the text of the gurobipy code that you want to translate. ChatGPT’s translation includes a model in the AMPL language, plus code in Python — using the amplpy API — for reading data and displaying results.

There may be things that you need to fix before the translation is entirely correct, but still you should finish a lot faster than if you tried to rewrite the gurobipy code by hand. If there are any systematic errors, you can follow up with requests to the chatbot to fix them. See the AMPL Python API page for links to amplpy documentation and examples.

Feel free to follow up with any feedback regarding your experiences.