Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching solver malfunctioning #2074

Closed
haoxiangyang89 opened this issue Oct 1, 2019 · 3 comments · Fixed by #2084
Closed

Switching solver malfunctioning #2074

haoxiangyang89 opened this issue Oct 1, 2019 · 3 comments · Fixed by #2084

Comments

@haoxiangyang89
Copy link

haoxiangyang89 commented Oct 1, 2019

Previous to v.0.19 to switch from a solver to another, or modify the solver parameter, all we have to do is: (the following is an example)

mp = Model(solver = GurobiSolver(OutputFlag = 0));
mp.solver = IpoptSolver(print_level = 0);

Once JuMP was upgraded, MOI employs the solver in this way:

mp = Model();
optimize!(with_optimizer(Gurobi.Optimizer, OutputFlag = 0));

Now if I change the solver by running optimize! again, it throws me an error. Here is the code I run to generate this error:

using JuMP, Ipopt, Gurobi;
mp = Model();
@variable(mp, x1 >= 0);
@variable(mp, x2 >= 0);
@constraint(mp, x1 + 2x2 <= 1);
@constraint(mp, x2 + 2x1 <= 1);
@objective(mp, Max, x1 + x2);
optimize!(mp, with_optimizer(Gurobi.Optimizer));
optimize!(mp, with_optimizer(Ipopt.Optimizer));

Here is the printout of the error. The first solve is successful and then the second fails. If I want to solve the model again, I have to use Gurobi.Optimizer without changing any parameters/to another solver. It appears the same if I set up an optimizer when setting up the JuMP model instead of leaving it blank initially.

ERROR: An optimizer factory cannot both be provided in the Model constructor and at the optimize call.
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] #optimize!#78(::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(optimize!), ::Model, ::OptimizerFactory) at /home/haoxiang/.julia/packages/JuMP/iGamg/src/optimizer_interface.jl:121
[3] optimize!(::Model, ::OptimizerFactory) at /home/haoxiang/.julia/packages/JuMP/iGamg/src/optimizer_interface.jl:111
[4] top-level scope at REPL[162]:1

@blegat
Copy link
Member

blegat commented Oct 1, 2019

You can do

optimize!(mp, with_optimizer(Gurobi.Optimizer))
set_optimizer(mp, with_optimizer(Ipopt.Optimizer))
optimize!(mp)

The error message could be improved. Or we could even make it work.

@odow odow added the Type: Bug label Oct 2, 2019
@mlubin
Copy link
Member

mlubin commented Oct 2, 2019

The second argument to optimize! makes it look like the optimizer is tossed out after the solve. Given that this is not how it actually works, maybe we should remove this method and force a call to set_optimizer.

@odow
Copy link
Member

odow commented Oct 9, 2019

👍 on removing this in favor of set_optimizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants