jeffgortmaker / pyblp

BLP Demand Estimation with Python
https://pyblp.readthedocs.io
MIT License
228 stars 82 forks source link

Knitro attribute not available on Knitro 13.2 #128

Open flucoe opened 1 year ago

flucoe commented 1 year ago

Hi Jeff,

I was trying to use Knitro but I'm getting an odd message for version 13.2.0

Specifically, I can import it (and actually use it for non-pyblp things, such as the examples*.py provided with Knitro) but when defining the optimization (kn = pyblp.Optimization('knitro')) I get

  File [relevant_path/] pyblp/configurations/optimization.py", line 470, in knitro_context_manager
    knitro_context = knitro.KTR_new()
AttributeError: module 'knitro' has no attribute 'KTR_new'

I tried this on my local machine and on an HPRC system (to make sure it was not my installation that was generating the problem), and in both cases I get the same message (with different path to optimization.py, of course). Any ideas of what could be happening? I was not getting this with previous versions of Knitro such as 13.0.1.

Also, I can I use Knitro without trouble outside pyblp.

Thanks.

jeffgortmaker commented 1 year ago

Ugh, I was hoping Knitro would keep their software backwards-compatible. My best guess is they dropped compatibility with their old API in one of the newest versions, but I don't have the newest version installed on my machine, so I can't check right now.

When you use Knitro outside of PyBLP, are you calling functions that look different than the ones I call in the following code? https://github.com/jeffgortmaker/pyblp/blob/8ff613dec6f2b8d9640bb5fd65bdc73a965b5c72/pyblp/configurations/optimization.py#L345-L486

If so, I'll leave this issue open as a reminder that PyBLP's Knitro wrapper has to be updated for newer versions. Until then, you have a few options:

  1. Downgrade your Knitro version so it's PyBLP-compatible.
  2. Write a custom Optimization method that uses the new Knitro API. It might help to refer to the above code I use to interface with the old API.
  3. Make a pull request that adds support for the new API to the above code. I'm happy to look over it, etc.
flucoe commented 1 year ago

Hi Jeff. I'm sorry for the slow reply.

I'll check whether it is possible to downgrade for now. If not, I'll try to figure out how to use the custom optimization method. Regarding my use of Knitro: I have been using the approach in exampleSciPy.py within examples/Python/examples with scipy minimize() function but with the kn_minimize method.

jeffgortmaker commented 1 year ago

Sounds good -- if you do end up making a custom optimization method and don't mind posting it here, it would be a great starting point for making the package compatible with the newer interface.

allen107 commented 2 months ago

Hi fluce, @flucoe

I have encounter same probelm here. Can you share your code that uses kn_minimize method? Thx.