# Error with Ipopt.jl and ipopt.out file

**URL:** <https://discourse.julialang.org/t/error-with-ipopt-jl-and-ipopt-out-file/127596>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization, snow, ipopt\
**Created:** [April 1, 2025, 1:31pm UTC](https://discourse.julialang.org/t/error-with-ipopt-jl-and-ipopt-out-file/127596 "2025-04-01T13:31:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nico](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nico/32/211667_2.png) [@nico](https://discourse.julialang.org/u/nico)\
**Post date:** [April 1, 2025, 1:31pm UTC](https://discourse.julialang.org/t/error-with-ipopt-jl-and-ipopt-out-file/127596/1 "2025-04-01T13:31:36Z")

</div>

Hi,  
I have a simple test code, that used to work and now gives an error.  
When I run the code the first time, Ipopt manages to solve the toy problem and print the output to a .txt file.  
The second time I run the code, without killing the Julia REPL/terminal, the output file is still held by some process and the code cannot run because it can not access the output file.

The error:

```julia
 ERROR: IPOPT: Couldn't open output file.
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:35
 [2] OpenIpoptOutputFile
   @ C:\Users\nicolo\.julia\packages\Ipopt\Tn8LH\src\C_wrapper.jl:355 [inlined]
 [3] optimize(solver::IPOPT{…}, cache::SNOW.DenseCache{…}, x0::Vector{…}, lx::Vector{…}, ux::Vector{…}, lg::Vector{…}, ug::Vector{…}, rows::Vector{…}, cols::Vector{…})
   @ SNOW C:\Users\nicolo\.julia\packages\SNOW\E3ZCP\src\ipopt.jl:118
 [4] minimize(func!::Function, x0::Vector{…}, ng::Int64, lx::Vector{…}, ux::Vector{…}, lg::Vector{…}, ug::Vector{…}, options::Options{…})
   @ SNOW C:\Users\nicolo\.julia\packages\SNOW\E3ZCP\src\interface.jl:73
 [5] runOptimization(objFun::typeof(f), objFunGrad::typeof(∇f), conFun::typeof(g), conFunGrad::typeof(∇g), ng::Int64, x0::Vector{…}, lx::Vector{…}, ux::Vector{…}, lc::Vector{…}, uc::Vector{…}, gradType::String)
   @ Main c:\Users\nicolo\Dropbox\Work\Code\Julia\Tests\Test_SNOW_IPOPT\Use_SNOWjl.jl:33
 [6] top-level scope
   @ c:\Users\nicolo\Dropbox\Work\Code\Julia\Tests\Test_SNOW_IPOPT\Use_SNOWjl.jl:64
Some type information was truncated. Use `show(err)` to see complete types.'

```

Julia version: 1.11.4  
Ipopt.jl v1.8.0

Code giving the issue:

```julia
using SNOW # http://flow.byu.edu/SNOW.jl/index.html

function runOptimization(objFun, objFunGrad, conFun, conFunGrad, ng, x0, lx, ux, lc, uc, gradType)
    function objCon!(g, x)
        f = objFun(x)
        g .= conFun(x)
        return f
    end

    function objConGrad!(g, df, dg, x)
        f = objFun(x)
        df .= objFunGrad(x)
        g .= conFun(x)
        dg .= conFunGrad(x)
        return f
    end

    ip_options = Dict(
        "max_iter" => 1000,
        "tol" => 1e-6,
        "output_file" => "ipopt.out")

    if gradType == "automatic"

        options = Options(solver = IPOPT(ip_options), 
                            derivatives=ForwardAD()) # choosing IPOPT solver
        xopt, fopt, info = minimize(objCon!, x0, ng, lx, ux, lc, uc, options)

    elseif gradType == "analytic"

        options = Options(solver = IPOPT(ip_options), 
                            derivatives=UserDeriv()) # choosing IPOPT solver
        xopt, fopt, info = minimize(objConGrad!, x0, ng, lx, ux, lc, uc, options)

    end

    println("xstar = ", round.(xopt, digits=3))
    println("fstar = ", round(fopt, digits=3))
    println("info = ", info)

    return xopt, fopt, info
end

f(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2 # Objective function (Rosenbrock)
∇f(x) = [-2*(1.0 - x[1]) - 400*(x[2] - x[1]^2)*x[1], 200.0 * (x[2] - x[1]^2)]

g1(x) = x[1]^2 + x[2]^2 - 1 # 1st constraint
∇g1(x) = [2*x[1], 2*x[2]]

g2(x) = x[1] + 3*x[2] - 5 # 2nd constraint
∇g2(x) = [1.0, 3.0]

g(x) = [g1(x); g2(x)]
∇g(x) = [∇g1(x)'; ∇g2(x)']

ng = 2 # Number of constraints
x0 = [1.3, 0.5] # Starting point
lx = [-2.0, -1.0] # Lower bound for design variables
ux = [+2.0, +3.0] # Upper bound for design variables
lc = [-Inf; -Inf] # Lower bound for nonlinear constraints
uc = [0.0; 0.0] # Upper bound for nonlinear constraints
gradType = "analytic" # options: automatic, analytic

xopt, fopt, info = runOptimization(f, ∇f, g, ∇g, ng, x0, lx, ux, lc, uc, gradType)

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 1, 2025, 9:41pm UTC](https://discourse.julialang.org/t/error-with-ipopt-jl-and-ipopt-out-file/127596/2 "2025-04-01T21:41:44Z")

</div>

Duplicate of [IPOPT suppress output file generation](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595) and [Error with Ipopt.jl and ipopt.out file · Issue #470 · jump-dev/Ipopt.jl · GitHub](https://github.com/jump-dev/Ipopt.jl/issues/470)

p.s., there’s no need to post both an issue on GitHub and a post on Discourse. I tend to read almost everything … 😄

---

<div class="post-metadata">

**Author:** ![nico](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nico/32/211667_2.png) [@nico](https://discourse.julialang.org/u/nico)\
**Post date:** [April 2, 2025, 8:57am UTC](https://discourse.julialang.org/t/error-with-ipopt-jl-and-ipopt-out-file/127596/3 "2025-04-02T08:57:15Z")

</div>

Hi thank you for your answer.  
Just so you know, I get the same issue also when I call IPOPT from JuMP.  
I believe it is related to some recent updates, probably of Ipopt.jl.  
The ipopt output file is held by a process and cannot be opened or visualized in VS Code as well, once the optimization terminates.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 2, 2025, 7:16pm UTC](https://discourse.julialang.org/t/error-with-ipopt-jl-and-ipopt-out-file/127596/4 "2025-04-02T19:16:29Z")

</div>

Let’s please stick to a single thread: [IPOPT suppress output file generation](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595)
