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

Errors when running JuMP examples from documentation (ERROR: LoadError: UndefVarError: optimize! not defined) #2656

Closed
Peter-Jolly opened this issue Aug 7, 2021 · 2 comments

Comments

@Peter-Jolly
Copy link

Hi,

I have tried running several of the examples from the docs only to get the error that optimize! is undefined. Please see code taken from docs below. Hope someone can help? Probably need to inlcude another package?

Thanks,

Peter

import Pkg
Pkg.add("JuMP")
# Pkg.add("NLopt")
Pkg.add("Ipopt")
Pkg.add("Test")

using JuMP
import Ipopt
import Test

function example_qcp(; verbose = true)
    model = Model(Ipopt.Optimizer)
    set_silent(model)
    @variable(model, x)
    @variable(model, y >= 0)
    @variable(model, z >= 0)
    @objective(model, Max, x)
    @constraint(model, x + y + z == 1)
    @constraint(model, x * x + y * y - z * z <= 0)
    @constraint(model, x * x - y * z <= 0)
    optimize!(model)
    if verbose
        print(model)
        println("Objective value: ", objective_value(model))
        println("x = ", value(x))
        println("y = ", value(y))
    end
    Test.@test termination_status(model) == MOI.LOCALLY_SOLVED
    Test.@test primal_status(model) == MOI.FEASIBLE_POINT
    Test.@test objective_value(model) ≈ 0.32699 atol = 1e-5
    Test.@test value(x) ≈ 0.32699 atol = 1e-5
    Test.@test value(y) ≈ 0.25707 atol = 1e-5
    return
end

example_qcp()
ERROR: LoadError: UndefVarError: optimize! not defined
Stacktrace:
 [1] example_qcp(; verbose::Bool)
   @ Main c:\Users\peter\Documents\Julia_Code\MPC_Development\Quadratic_Optimization.jl:21
 [2] example_qcp()
   @ Main c:\Users\peter\Documents\Julia_Code\MPC_Development\Quadratic_Optimization.jl:12
 [3] top-level scope
   @ c:\Users\peter\Documents\Julia_Code\MPC_Development\Quadratic_Optimization.jl:36
in expression starting at c:\Users\peter\Documents\Julia_Code\MPC_Development\Quadratic_Optimization.jl:36
@blegat
Copy link
Member

blegat commented Aug 7, 2021

optimize! was added in JuMP v0.19, I would guess you are using an older version. Maybe another package like JuMPeR is holding JuMP's version back. Try using a local project with Pkg.activate(".") to avoid any conflicts between packages used by different projects

@Peter-Jolly
Copy link
Author

Thanks for responding and help. I replaced all of the "import" statements with "using" and the program worked. Just to mention I am running the script using VScode under Windows 10 using Julia 1.6.2

using JuMP
using Ipopt
using Test

@joaquimg joaquimg closed this as completed Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants