fdabrandao / MO-book-with-AMPL

Mathematical Opimization
https://ampl.com/mo-book
MIT License
2 stars 1 forks source link

Chapter 6: Conic Optimization #1

Closed glebbelov closed 1 year ago

glebbelov commented 1 year ago

Use Ipopt, Mosek, Gurobi, Knitro to solve SOCP and exponential cones (Gurobi only SOCP). Progress status for text only:

Progress status for models:

glebbelov commented 1 year ago

Started Economic order quantity 4629c8b

glebbelov commented 1 year ago

@fdabrandao do we need the g parameter for tools.ampl_notebook? It is not self-explanatory and it fails for me:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[196], line 4
      2 import numpy as np
      3 import pandas as pd
----> 4 ampl = tools.ampl_notebook(
      5     modules=["ipopt", "mosek"], # modules to install
      6     license_uuid="default", # license to use
      7     g=globals()      ### --------- Fails for me. Can this be default, would anyone change it?
      8 ) # instantiate AMPL object and register magics

TypeError: ampl_notebook() got an unexpected keyword argument 'g'
fdabrandao commented 1 year ago

Hi @glebbelov,

You seem to have an outdated version of amplpy. Could you please run pyton -m install amplpy --upgrade and try again?

That last argument is necessary to give access to the globals in the notebook and enabling %%ampl_eval to access the global object named ampl. It cannot be a default because globals() returns the global variables accessible from where it is invoked, globals() inside a module returns the globals inside that module.

fdabrandao commented 1 year ago

ChatGPT told me that IPython.get_ipython().user_global_ns gives me access to the global environment of the notebook too so that argument is going to go away in the next release.

glebbelov commented 1 year ago

@fdabrandao Concerning the Markowitz, the original notebook presents x' Sigma x <= s in the mathematical model, but then <= s^2 in Python. Changing model to <= s allows Mosek to be used. I am doing this in our notebook. Probably, authors should be notified about this mistake. Should I still add a model where the factorized matrix is used?

glebbelov commented 1 year ago

@fdabrandao SVM notebook did not run. I fixed general Python code. Should the authors be notified?

fdabrandao commented 1 year ago

@glebbelov, for any errors you find in the original notebooks you can open issues at: https://github.com/mobook/MO-book/issues (they asked me to open issues there for any mistakes we find)