AMPL license activation

I downloaded the Knitro solver files. To use it, I need to activate the ampl license. However, I couldn’t activate the license and so I can’t use knitro. Can you help me?

Hi @LANIELSON_ANDRADE_SI,

Thank you for reaching out. Which error did you get when you tried to activate the license?

The license has been activated, but I can’t use ‘knitro’ in my pyomo scrip in vscode. How can I proceed?

image

To use Knitro with Pyomo you should just need to pass the path to it to SolverFactory. Are you getting a license error when you try to use it?

You can also try with the modules for Python that also work with Pyomo: AMPL Modules for Python — AMPL Resources

Exactly, there seems to be a problem with the license:

However, the license is activated and working. Please note:

What could it be?

Could you please check the value of os.envion["AMPL_LICFILE"]? Somehow seems to have a different value than the one in .bashrc. Alternatively, you could also update the value in .bashrc to that one and move the license to the location where Knitro is looking for it.

I changed the line
export PATH=/opt/ampl.linux-intel64/:$PATH
to
export PATH=$PATH:"$HOME/.ampl/ampl.linux-intel64/”
I thought that was the error, but it still doesn’t work.

image

I updated bashrc after this change, but the error persists.

Error:

I’ve checked:
image

Since os.environ["AMPL_LICFILE] is pointing to $HOME/.ampl/ampl.lic. Knitro will be looking for the license there. You may need to restart the notebook in order to load the new environment variable value in .bashrc.

I restarted my PC and was able to use knitro:

However, when trying to use a global solver, such as baron, the following error appeared:

Why were there no errors in the knitro, but there were in the baron?

In the first argument of SolverFactory you should use “baronnl” instead of “baron” since Pyomo will try to use a bar file otherwise.

In case you used the python modules, the code for any solver would be:

!pip install amplpy pyomo -q
!python -m amplpy.modules install <solver-name> -q
!python -m amplpy.modules activate <license-uuid>
from amplpy import modules
import pyomo.environ as pyo
solver_name = "<solver-name>"
solver = pyo.SolverFactory(solver_name+"nl", executable=modules.find(solver_name), solve_io="nl")