Windows: I can't use ampl to call solver via pyomo

I use pyomo to formulate my problem and try to use ampl to call ipopt. According to documents, I have installed coin module via: python -m amplpy.modules install coin.
However when I use :pyo.SolverFactory(modules.find(f"{self.solver}"), solve_io=“nl”),
it reported that:
Failed to create solver with name ‘D’: Failed to set executable for
solver asl. File with name=D either does not exist or it is not executable. To
skip this validation, call set_executable with validate=False.
The SolverFactory was unable to create the solver “D”
and returned an UnknownSolver object. This error is raised at the point
where the UnknownSolver object was used as if it were valid (by calling
method “solve”).

The original solver was created with the following parameters:
executable: D
solve_io: nl
solver: \anaconda\envs\power\Lib\site-packages\ampl_module_coin\bin\ipopt.exe
type: D
_args: ()
options: {}

I have checked the value of modules.find(f"{self.solver}"), it shows :‘d:\anaconda\envs\power\Lib\site-packages\ampl_module_coin\bin\ipopt.exe’
Which I think it is correct. So I wonder why it didn’t work?

Hi @Zhang,

Could you please try with modules.find(self.solver) instead of modules.find(f"{self.solver}")? Since there are forward slashes in the path, it may be causing trouble to have them in a f-string.

It doesn’t work either, with following outputs:

here, self.solver=‘ipopt’

Hi @Zhang,

The issue is that Pyomo parses the executable path in a way that does not work well on Windows. In this case it assumes that the solver name is “D” because that is the beginning of the path.

The following should fix the issue by specifying the executable path:

from amplpy import modules
import pyomo.environ as pyo
solver_name = "ipopt"
solver = pyo.SolverFactory(solver_name+"nl", executable=modules.find(solver_name), solve_io="nl")

We will update the instructions at AMPL Modules for Python — AMPL Resources to help people that may be facing the same issue.

Thanks a lot for your solution, and I have fixed this issue already. However I encountered another issue recently, so sorry to bother you again.
The license used is 30-Day Free Student Full-Sized Trial. My program is to solve a optimization problem with a lot of iterations and each time I will change a few parameters, which means the size of my optimization problem didn’t change at all. However after a few iterations, it suddenly reported that “Sorry, a demo license is limited to 10 variables and 10 constraints and objectives.” More detail shows below:

So is there any ways to solve this issue? Looking forward to your reply. Appreciate your help again.

Hi @Zhang ,

It seems that you are using a demo license instead of your student-trial one.

You need to download your license in order to use knitro, which is a commercial solver.

It should not happen with ipopt.