Re: [AMPL 6468] Integrating AMPL into Gurobi/Python Environment

342 views
Skip to first unread message

victor.z...@gmail.com

unread,
Jan 9, 2013, 12:48:37 AM1/9/13
to am...@googlegroups.com
Hi,

Some time ago I implemented so called "cell magic" that integrates AMPL with IPython. It is still work in progress but I've put it in this GitHub repository in case it might be useful to you or anyone else. It will allow you to combine AMPL and Python code in one notebook and access the AMPL objects (sets, parameters, variables, objectives and constraints) from Python. I've written a small blog post about this: http://zverovich.net/2013/01/08/ampl-magic-using-ipython-as-an-interface-to-ampl.html

HTH,
Victor


On Tue, Jan 8, 2013 at 1:23 PM, Andrew B. Martin <andrew.br...@gmail.com> wrote:
Hello, 

I have set-up an environment using gurobi, ipython, matplotlib, and an extensive library of homemade python functions to analyze model results in a python (actually pylab) shell.

First question: I have not found any mention of anything similar in the AMPL or other web resources, but is there a way to integrate AMPL into this environment?

Second question: I have tried using the 'write mfilename' command to generate an .mps from AMPL and read that into my Gurobi/python environment, but gurobi finds the .mps infeasible; however, when I issue the solve command within AMPL gurobi finds an optimal solution. I have also tried using 'expand >filename.lp' with the same results. Is there another way I could use AMPL to generate my model from a .mod file and then migrate the resulting model into my gurobi/python environment?

Andrew

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ampl/-/2_owySj54E0J.
To post to this group, send email to am...@googlegroups.com.
To unsubscribe from this group, send email to ampl+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ampl?hl=en.

victor.z...@gmail.com

unread,
Jan 15, 2013, 2:33:40 PM1/15/13
to am...@googlegroups.com
Hi Andrew,

Yes, it is possible to use the IPython command-line console instead of the web notebook. The console can be started with the following command:

  ipython console

You can read more about command-line usage of IPython here:

HTH,
Victor


On Tue, Jan 15, 2013 at 10:23 AM, Andrew B. Martin <andrew.br...@gmail.com> wrote:
Hi Vitaut,

Your interface sounds excellent.

In your blog post you mention it can be run through the command line instead of notebook. Is there anywhere I can find instructions on how to do this?

Andrew 

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ampl/-/gTWzOpM_xUQJ.

jyoti...@gmail.com

unread,
Mar 24, 2014, 4:35:05 PM3/24/14
to am...@googlegroups.com
Hi Victor,

I was trying to run example.pynb in IPython and for that I had installed ampl using easy_install when I tried to run the cell it gave me an error "Couldn't find program: 'ampl'". Would you know what could be the cause of error? There was no error at the time of ampl installation.. and it was able to load ampl successfully using %load_ext ampl..

Thanks,
Jyoti

victor.z...@gmail.com

unread,
Mar 25, 2014, 11:44:20 AM3/25/14
to am...@googlegroups.com
Hi Jyoti,

It means that the ampl executable is not on the search paths. easy_install only installs the IPython extension for working with AMPL, not AMPL itself.

HTH,
Victor


To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.

To post to this group, send email to am...@googlegroups.com.
Visit this group at http://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

dines...@gmail.com

unread,
Nov 28, 2016, 8:16:17 AM11/28/16
to AMPL Modeling Language
Hi Victor,

Can you show me how to add the search path for ampl? I already have ampl installed and I mostly use ipopt for my models. I am trying to get it to run using ipython notebooks, but it only returns an error that says Couldn't find program ampl. I have ampl's executable in my bash profile and I am able to solve all my models anywhere in any directory, but still face this error.

Robert Fourer

unread,
Nov 29, 2016, 10:24:23 AM11/29/16
to am...@googlegroups.com
The instructions say that, "To use iampl you should have ampl and solvers executables available on the search path." Try the command "which ampl" to see if the ampl executable is found anywhere in your current search path. If not, add the directory containing the ampl executable to the path using a command of the general form "PATH=$PATH:<your ampl dir>" and then try using iampl again.

If you still have trouble, try posting a question at the iampl blog post, http://zverovich.net/2013/01/08/ampl-magic-using-ipython-as-an-interface-to-ampl.html. This should reach Victor who is the author of iampl.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages