# IPOPT suppress output file generation

**URL:** <https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595>\
**Category:** Optimization (Mathematical)\
**Created:** [April 1, 2025, 1:09pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595 "2025-04-01T13:09:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![hjalgra](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@hjalgra](https://discourse.julialang.org/u/hjalgra)\
**Post date:** [April 1, 2025, 1:09pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/1 "2025-04-01T13:09:57Z")

</div>

I am using `IPOPT` to solve a sequence of optimization problems (interfaced using `SNOW`). In order to prevent the creation of an output file I am initializing IPOPT using the following options

```julia
    ip_options = Dict(
        "max_iter" => 1000,
        "tol" => 1e-6,
        "print_level" => 0,
        "file_print_level" => 0,
        )

```

I then set up the problem with `SNOW` as follows

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

```

where the previously defined `Dict` is passed as the settings for `IPOPT`.

In my setup I am solving many optimization problems sequentially. After solving the first problem, I get the following error message:  
`ERROR: LoadError: IPOPT: Couldn't open output file.`

I think the problem has to do with the fact that, when solving my second problem, the output file is “still busy”, so IPOPT cannot open it. However, I would expect that there is no output file to cause this problem in the first place.

I have also tried explicitly adding

```julia
"output_file" => "",

```

to the dictionary of `ip_options`, but that did not solve the problem. The documentation of the different options for `IPOPT` can be found [here](https://coin-or.github.io/Ipopt/OPTIONS.html).

How can I overcome this issue?

---

<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, 6:58pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/2 "2025-04-01T18:58:37Z")

</div>

Hi @hjalgra, welcome to the forum 😄

This appears to be a bug in SNOW.jl, because they open the output file regardless of whether the filename is valid or the print level is `> 0`. See:

> <https://github.com/byuflowlab/SNOW.jl/blob/a40f4c7cf32c566d4cbd195401a79078483caefa/src/ipopt.jl#L118>

You could try opening a GitHub issue to report this: [Sign in to GitHub · GitHub](https://github.com/byuflowlab/SNOW.jl/issues/new)

Alternatively, you could look at other Ipopt wrappers, like using JuMP, or the [C API to Ipopt](https://github.com/jump-dev/Ipopt.jl?tab=readme-ov-file#c-api), or using NLPModels.jl, or Optimization.jl.

Edit: I’ve opened a PR to fix SNOW: [Set output\_file via addOption instead of OpenIpoptOutputFile by odow · Pull Request #18 · byuflowlab/SNOW.jl · GitHub](https://github.com/byuflowlab/SNOW.jl/pull/18)

---

<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, 9:00am UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/3 "2025-04-02T09:00:06Z")

</div>

I am not sure that the fact that the output file is held by a process happens because SNOW.jl writes the output file no matter the settings passed by the user.  
It should still be possible to write an output file (even if the user didn’t ask for it explicitely) without the file being held or not readable.

---

<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:27pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/4 "2025-04-02T19:27:02Z")

</div>

@nico, you wrote [Error with Ipopt.jl and ipopt.out file](https://discourse.julialang.org/t/error-with-ipopt-jl-and-ipopt-out-file/127596)

> Just so you know, I get the same issue also when I call IPOPT from JuMP.

Do you have a reproducible example?

> I believe it is related to some recent updates, probably of [Ipopt.jl](https://juliaregistries.github.io/General/packages/redirect_to_repo/Ipopt)

This is not a bug in Ipopt.jl, and there are no revelvant recent changes. `OpenIpoptOutputFile` calls the C API directly: [Ipopt.jl/src/C\_wrapper.jl at 801b6a0a055f79bbf5d785f80f9ba9cdb2333ec9 · jump-dev/Ipopt.jl · GitHub](https://github.com/jump-dev/Ipopt.jl/blob/801b6a0a055f79bbf5d785f80f9ba9cdb2333ec9/src/C_wrapper.jl#L341-L358)

If this is an issue, it is an issue in the upstream `coin-or/Ipopt`.

> I am not sure that the fact that the output file is held by a process happens

Agreed. My PR is a different fix. But I’m not even sure if it is the right fix, because I cannot reproduce the file lock on macOS.

My guess is that issue is that the file is manually opened. It won’t be closed until `FreeIpoptProblem` is called, which won’t happen until the `prob` is freed by the garbage collector.

The default for the [`file_append`](https://coin-or.github.io/Ipopt/OPTIONS.html#OPT_file_append) option is “no”, so two problems cannot write to the same file.

---

<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, 8:46pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/5 "2025-04-02T20:46:27Z")

</div>

I took a deeper look. I can’t reproduce this, even with pure Ipopt. Consider:

```julia
julia> using Ipopt

julia> function eval_f(x::Vector{Float64})
           return x[1] * x[4] * (x[1] + x[2] + x[3]) + x[3]
       end
eval_f (generic function with 1 method)

julia> function eval_g(x::Vector{Float64}, g::Vector{Float64})
           g[1] = x[1] * x[2] * x[3] * x[4]
           g[2] = x[1]^2 + x[2]^2 + x[3]^2 + x[4]^2
           return
       end
eval_g (generic function with 1 method)

julia> function eval_grad_f(x::Vector{Float64}, grad_f::Vector{Float64})
           grad_f[1] = x[1] * x[4] + x[4] * (x[1] + x[2] + x[3])
           grad_f[2] = x[1] * x[4]
           grad_f[3] = x[1] * x[4] + 1
           grad_f[4] = x[1] * (x[1] + x[2] + x[3])
           return
       end
eval_grad_f (generic function with 1 method)

julia> function eval_jac_g(
           x::Vector{Float64},
           rows::Vector{Int32},
           cols::Vector{Int32},
           values::Union{Nothing,Vector{Float64}},
       )
           if values === nothing
               rows .= [1, 1, 1, 1, 2, 2, 2, 2]
               cols .= [1, 2, 3, 4, 1, 2, 3, 4]
           else
               values[1] = x[2] * x[3] * x[4] # 1,1
               values[2] = x[1] * x[3] * x[4] # 1,2
               values[3] = x[1] * x[2] * x[4] # 1,3
               values[4] = x[1] * x[2] * x[3] # 1,4
               values[5] = 2 * x[1] # 2,1
               values[6] = 2 * x[2] # 2,2
               values[7] = 2 * x[3] # 2,3
               values[8] = 2 * x[4] # 2,4
           end
           return
       end
eval_jac_g (generic function with 1 method)

julia> function build_problem()
           prob = Ipopt.CreateIpoptProblem(
               4, # n
               [1.0, 1.0, 1.0, 1.0], # x_L
               [5.0, 5.0, 5.0, 5.0], # x_U
               2, # m
               [25.0, 40.0], # g_L
               [Inf, 40.0], # g_U
               8,
               10,
               eval_f,
               eval_g,
               eval_grad_f,
               eval_jac_g,
               nothing, # eval_h,
           )
           Ipopt.AddIpoptStrOption(prob, "hessian_approximation", "limited-memory")
           return prob
       end
build_problem (generic function with 1 method)

julia> p1 = build_problem();

julia> Ipopt.OpenIpoptOutputFile(p1, "ipopt.log", 5)

julia> p2 = build_problem();

julia> p2.x = [1.0, 4.75, 3.82, 1.379];

julia> Ipopt.OpenIpoptOutputFile(p2, "ipopt.log", 5)

julia> Ipopt.IpoptSolve(p2)
This is Ipopt version 3.14.14, running with linear solver MUMPS 5.6.2.

Number of nonzeros in equality constraint Jacobian...: 4
Number of nonzeros in inequality constraint Jacobian.: 4
Number of nonzeros in Lagrangian Hessian.............: 0

Total number of variables............................: 4
                     variables with only lower bounds: 0
                variables with lower and upper bounds: 4
                     variables with only upper bounds: 0
Total number of equality constraints.................: 1
Total number of inequality constraints...............: 1
        inequality constraints with only lower bounds: 1
   inequality constraints with lower and upper bounds: 0
        inequality constraints with only upper bounds: 0

iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
   0 1.7162928e+01 7.66e-02 5.20e-01 0.0 0.00e+00 - 0.00e+00 0.00e+00 0
   1 1.7103404e+01 1.81e-04 1.46e-02 -1.8 1.35e-01 - 9.91e-01 1.00e+00h 1
   2 1.7015921e+01 1.73e-04 3.11e-02 -3.1 1.36e-01 - 1.00e+00 9.99e-01f 1
   3 1.7014053e+01 5.93e-05 1.10e-02 -5.0 2.58e-03 - 1.00e+00 1.00e+00h 1
   4 1.7014006e+01 1.99e-05 4.20e-03 -6.4 3.53e-03 - 1.00e+00 9.95e-01h 1
   5 1.7014016e+01 1.43e-06 1.01e-05 -8.5 9.44e-04 - 1.00e+00 1.00e+00h 1
   6 1.7014017e+01 4.97e-14 2.07e-08 -11.0 1.49e-07 - 1.00e+00 1.00e+00h 1
   7 1.7014017e+01 0.00e+00 1.75e-12 -11.0 5.27e-11 - 1.00e+00 1.00e+00h 1

Number of Iterations....: 7

                                   (scaled) (unscaled)
Objective...............: 1.7014017140224173e+01 1.7014017140224173e+01
Dual infeasibility......: 1.7487404428810206e-12 1.7487404428810206e-12
Constraint violation....: 0.0000000000000000e+00 0.0000000000000000e+00
Variable bound violation: 9.9908077366706038e-09 9.9908077366706038e-09
Complementarity.........: 1.0000053295879501e-11 1.0000053295879501e-11
Overall NLP error.......: 1.0000053295879501e-11 1.0000053295879501e-11

Number of objective function evaluations = 8
Number of objective gradient evaluations = 8
Number of equality constraint evaluations = 8
Number of inequality constraint evaluations = 8
Number of equality constraint Jacobian evaluations = 8
Number of inequality constraint Jacobian evaluations = 8
Number of Lagrangian Hessian evaluations = 0
Total seconds in IPOPT = 0.073

EXIT: Optimal Solution Found.
0

julia> print(read("ipopt.log", String))
This is Ipopt version 3.14.14, running with linear solver MUMPS 5.6.2.

Number of nonzeros in equality constraint Jacobian...: 4
Number of nonzeros in inequality constraint Jacobian.: 4
Number of nonzeros in Lagrangian Hessian.............: 0

Total number of variables............................: 4
                     variables with only lower bounds: 0
                variables with lower and upper bounds: 4
                     variables with only upper bounds: 0
Total number of equality constraints.................: 1
Total number of inequality constraints...............: 1
        inequality constraints with only lower bounds: 1
   inequality constraints with lower and upper bounds: 0
        inequality constraints with only upper bounds: 0

iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
   0 1.7162928e+01 7.66e-02 5.20e-01 0.0 0.00e+00 - 0.00e+00 0.00e+00 0
   1 1.7103404e+01 1.81e-04 1.46e-02 -1.8 1.35e-01 - 9.91e-01 1.00e+00h 1
   2 1.7015921e+01 1.73e-04 3.11e-02 -3.1 1.36e-01 - 1.00e+00 9.99e-01f 1
   3 1.7014053e+01 5.93e-05 1.10e-02 -5.0 2.58e-03 - 1.00e+00 1.00e+00h 1
   4 1.7014006e+01 1.99e-05 4.20e-03 -6.4 3.53e-03 - 1.00e+00 9.95e-01h 1
   5 1.7014016e+01 1.43e-06 1.01e-05 -8.5 9.44e-04 - 1.00e+00 1.00e+00h 1
   6 1.7014017e+01 4.97e-14 2.07e-08 -11.0 1.49e-07 - 1.00e+00 1.00e+00h 1
   7 1.7014017e+01 0.00e+00 1.75e-12 -11.0 5.27e-11 - 1.00e+00 1.00e+00h 1

Number of Iterations....: 7

                                   (scaled) (unscaled)
Objective...............: 1.7014017140224173e+01 1.7014017140224173e+01
Dual infeasibility......: 1.7487404428810206e-12 1.7487404428810206e-12
Constraint violation....: 0.0000000000000000e+00 0.0000000000000000e+00
Variable bound violation: 9.9908077366706038e-09 9.9908077366706038e-09
Complementarity.........: 1.0000053295879501e-11 1.0000053295879501e-11
Overall NLP error.......: 1.0000053295879501e-11 1.0000053295879501e-11

Number of objective function evaluations = 8
Number of objective gradient evaluations = 8
Number of equality constraint evaluations = 8
Number of inequality constraint evaluations = 8
Number of equality constraint Jacobian evaluations = 8
Number of inequality constraint Jacobian evaluations = 8
Number of Lagrangian Hessian evaluations = 0
Total seconds in IPOPT = 0.073

EXIT: Optimal Solution Found.

julia> Ipopt.IpoptSolve(p1)
This is Ipopt version 3.14.14, running with linear solver MUMPS 5.6.2.

Number of nonzeros in equality constraint Jacobian...: 4
Number of nonzeros in inequality constraint Jacobian.: 4
Number of nonzeros in Lagrangian Hessian.............: 0

Total number of variables............................: 4
                     variables with only lower bounds: 0
                variables with lower and upper bounds: 4
                     variables with only upper bounds: 0
Total number of equality constraints.................: 1
Total number of inequality constraints...............: 1
        inequality constraints with only lower bounds: 1
   inequality constraints with lower and upper bounds: 0
        inequality constraints with only upper bounds: 0

iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
   0 4.1009029e+00 3.59e+01 1.54e+00 0.0 0.00e+00 - 0.00e+00 0.00e+00 0
   1 6.3369396e+00 3.43e+01 2.40e+01 -5.7 5.89e+00 - 2.21e-03 4.20e-02h 1
   2 5.4097700e+00 3.42e+01 1.38e+02 0.2 5.15e+00 - 1.72e-05 2.32e-03F 1
   3 3.9539430e+01 1.38e+01 1.45e+03 -1.1 4.74e+00 - 1.00e+00 3.76e-01h 2
   4 1.8118029e+01 2.90e+00 7.27e+02 0.7 2.49e+01 - 1.00e+00 6.47e-01f 1
   5 2.0775371e+01 1.57e-01 8.47e-01 0.1 1.12e+01 - 1.00e+00 1.00e+00f 1
   6 1.7334617e+01 1.78e-01 3.19e-01 -1.6 5.17e+00 - 9.23e-01 1.00e+00f 1
   7 1.6866329e+01 3.04e-01 1.62e-01 -1.6 3.10e-01 - 1.00e+00 1.00e+00h 1
   8 1.6989287e+01 4.78e-02 3.79e-02 -2.4 1.30e-01 - 9.95e-01 1.00e+00h 1
   9 1.7013532e+01 1.25e-03 6.00e-03 -3.7 1.35e-02 - 9.96e-01 1.00e+00h 1
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
  10 1.7014026e+01 5.99e-07 5.62e-04 -5.3 4.51e-04 - 1.00e+00 1.00e+00h 1
  11 1.7014017e+01 5.43e-08 3.78e-06 -7.4 1.84e-04 - 1.00e+00 1.00e+00h 1
  12 1.7014017e+01 1.56e-11 3.32e-09 -11.0 3.12e-06 - 1.00e+00 1.00e+00h 1

Number of Iterations....: 12

                                   (scaled) (unscaled)
Objective...............: 1.7014017140214442e+01 1.7014017140214442e+01
Dual infeasibility......: 3.3177681309590336e-09 3.3177681309590336e-09
Constraint violation....: 1.5603518477291800e-11 1.5603518477291800e-11
Variable bound violation: 9.9909249762220043e-09 9.9909249762220043e-09
Complementarity.........: 1.0110284647548166e-11 1.0110284647548166e-11
Overall NLP error.......: 3.3177681309590336e-09 3.3177681309590336e-09

Number of objective function evaluations = 17
Number of objective gradient evaluations = 13
Number of equality constraint evaluations = 17
Number of inequality constraint evaluations = 17
Number of equality constraint Jacobian evaluations = 13
Number of inequality constraint Jacobian evaluations = 13
Number of Lagrangian Hessian evaluations = 0
Total seconds in IPOPT = 0.014

EXIT: Optimal Solution Found.
0

julia> print(read("ipopt.log", String))
This is Ipopt version 3.14.14, running with linear solver MUMPS 5.6.2.

Number of nonzeros in equality constraint Jacobian...: 4
Number of nonzeros in inequality constraint Jacobian.: 4
Number of nonzeros in Lagrangian Hessian.............: 0

Total number of variables............................: 4
                     variables with only lower bounds: 0
                variables with lower and upper bounds: 4
                     variables with only upper bounds: 0
Total number of equality constraints.................: 1
Total number of inequality constraints...............: 1
        inequality constraints with only lower bounds: 1
   inequality constraints with lower and upper bounds: 0
        inequality constraints with only upper bounds: 0

iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
   0 4.1009029e+00 3.59e+01 1.54e+00 0.0 0.00e+00 - 0.00e+00 0.00e+00 0
   1 6.3369396e+00 3.43e+01 2.40e+01 -5.7 5.89e+00 - 2.21e-03 4.20e-02h 1
   2 5.4097700e+00 3.42e+01 1.38e+02 0.2 5.15e+00 - 1.72e-05 2.32e-03F 1
   3 3.9539430e+01 1.38e+01 1.45e+03 -1.1 4.74e+00 - 1.00e+00 3.76e-01h 2
   4 1.8118029e+01 2.90e+00 7.27e+02 0.7 2.49e+01 - 1.00e+00 6.47e-01f 1
   5 2.0775371e+01 1.57e-01 8.47e-01 0.1 1.12e+01 - 1.00e+00 1.00e+00f 1
   6 1.7334617e+01 1.78e-01 3.19e-01 -1.6 5.17e+00 - 9.23e-01 1.00e+00f 1
   7 1.6866329e+01 3.04e-01 1.62e-01 -1.6 3.10e-01 - 1.00e+00 1.00e+00h 1
   8 1.6989287e+01 4.78e-02 3.79e-02 -2.4 1.30e-01 - 9.95e-01 1.00e+00h 1
   9 1.7013532e+01 1.25e-03 6.00e-03 -3.7 1.35e-02 - 9.96e-01 1.00e+00h 1
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
  10 1.7014026e+01 5.99e-07 5.62e-04 -5.3 4.51e-04 - 1.00e+00 1.00e+00h 1
  11 1.7014017e+01 5.43e-08 3.78e-06 -7.4 1.84e-04 - 1.00e+00 1.00e+00h 1
  12 1.7014017e+01 1.56e-11 3.32e-09 -11.0 3.12e-06 - 1.00e+00 1.00e+00h 1

Number of Iterations....: 12

                                   (scaled) (unscaled)
Objective...............: 1.7014017140214442e+01 1.7014017140214442e+01
Dual infeasibility......: 3.3177681309590336e-09 3.3177681309590336e-09
Constraint violation....: 1.5603518477291800e-11 1.5603518477291800e-11
Variable bound violation: 9.9909249762220043e-09 9.9909249762220043e-09
Complementarity.........: 1.0110284647548166e-11 1.0110284647548166e-11
Overall NLP error.......: 3.3177681309590336e-09 3.3177681309590336e-09

Number of objective function evaluations = 17
Number of objective gradient evaluations = 13
Number of equality constraint evaluations = 17
Number of inequality constraint evaluations = 17
Number of equality constraint Jacobian evaluations = 13
Number of inequality constraint Jacobian evaluations = 13
Number of Lagrangian Hessian evaluations = 0
Total seconds in IPOPT = 0.014

EXIT: Optimal Solution Found.

```

`p1` opens the file first, then `p2` opens it, solves and writes to file, then when `p1` solves it overwrites the existing file. That seems to be working as expected?

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [April 2, 2025, 9:55pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/6 "2025-04-02T21:55:14Z")

</div>

Is this all happening on Windows and not on macOS/Linux?

---

<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, 10:11pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/7 "2025-04-02T22:11:25Z")

</div>

Seems so. Any ideas?

@nico also opened this issue [Error with Ipopt.jl and ipopt.out file · Issue #470 · jump-dev/Ipopt.jl · GitHub](https://github.com/jump-dev/Ipopt.jl/issues/470) which had

```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.'

```

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [April 2, 2025, 11:12pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/8 "2025-04-02T23:12:05Z")

</div>

Seems to be due to a windows update perhaps? We also noticed this: [Permission denied error on Windows on opening tmp file · Issue #126 · JuliaSmoothOptimizers/NLPModelsIpopt.jl · GitHub](https://github.com/JuliaSmoothOptimizers/NLPModelsIpopt.jl/issues/126)

---

<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, 11:18pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/9 "2025-04-02T23:18:40Z")

</div>

That looks like a different error. The OP issue is `OpenIpoptOutputFile` returning false:

> <https://github.com/jump-dev/Ipopt.jl/blob/801b6a0a055f79bbf5d785f80f9ba9cdb2333ec9/src/C_wrapper.jl#L349-L356>

which happens when `fopen` fails.

---

<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 3, 2025, 11:22am UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/10 "2025-04-03T11:22:30Z")

</div>

Hi, thank you for your kind replies.  
Yes, in my experience, I get this issue only on a Windows machine. One of my students has the same issue on his Windows machine. On a Mac computer I do not get the problem, as also observed by @odow .

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [April 3, 2025, 5:09pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/11 "2025-04-03T17:09:29Z")

</div>

Yes. It looks like the same error to me, except that we call `readlines` directly instead of the Ipopt function.

---

<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 3, 2025, 7:25pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/12 "2025-04-03T19:25:27Z")

</div>

Oh, now I understand you. I guess so, but I’m also then not sure what we can/should do about this. Windows is not my strong suit.

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [April 4, 2025, 1:35am UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/13 "2025-04-04T01:35:40Z")

</div>

Or mine ☹

---

<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 4, 2025, 2:09am UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/14 "2025-04-04T02:09:04Z")

</div>

@nico can you try

```julia
using Ipopt
function eval_f(x::Vector{Float64})
     return x[1] * x[4] * (x[1] + x[2] + x[3]) + x[3]
end
function eval_g(x::Vector{Float64}, g::Vector{Float64})
     g[1] = x[1] * x[2] * x[3] * x[4]
     g[2] = x[1]^2 + x[2]^2 + x[3]^2 + x[4]^2
     return
end
function eval_grad_f(x::Vector{Float64}, grad_f::Vector{Float64})
     grad_f[1] = x[1] * x[4] + x[4] * (x[1] + x[2] + x[3])
     grad_f[2] = x[1] * x[4]
     grad_f[3] = x[1] * x[4] + 1
     grad_f[4] = x[1] * (x[1] + x[2] + x[3])
     return
end
function eval_jac_g(
     x::Vector{Float64},
     rows::Vector{Int32},
     cols::Vector{Int32},
     values::Union{Nothing,Vector{Float64}},
)
     if values === nothing
          rows .= [1, 1, 1, 1, 2, 2, 2, 2]
          cols .= [1, 2, 3, 4, 1, 2, 3, 4]
     else
          values[1] = x[2] * x[3] * x[4] # 1,1
          values[2] = x[1] * x[3] * x[4] # 1,2
          values[3] = x[1] * x[2] * x[4] # 1,3
          values[4] = x[1] * x[2] * x[3] # 1,4
          values[5] = 2 * x[1] # 2,1
          values[6] = 2 * x[2] # 2,2
          values[7] = 2 * x[3] # 2,3
          values[8] = 2 * x[4] # 2,4
     end
     return
end
function build_problem()
     prob = Ipopt.CreateIpoptProblem(
          4, # n
          [1.0, 1.0, 1.0, 1.0], # x_L
          [5.0, 5.0, 5.0, 5.0], # x_U
          2, # m
          [25.0, 40.0], # g_L
          [Inf, 40.0], # g_U
          8,
          10,
          eval_f,
          eval_g,
          eval_grad_f,
          eval_jac_g,
          nothing, # eval_h,
     )
     Ipopt.AddIpoptStrOption(prob, "hessian_approximation", "limited-memory")
     return prob
end

function Ipopt.FreeIpoptProblem(prob::Ipopt.IpoptProblem)
     if prob.ipopt_problem === C_NULL
          println("Calling FreeIpoptProblem with NULL")
          return
     end
     println("Calling FreeIpoptProblem with valid pointer")
     @ccall Ipopt.libipopt.FreeIpoptProblem(prob::Ptr{Cvoid})::Cvoid
     prob.ipopt_problem = C_NULL
     return
end
 
p1 = build_problem();
Ipopt.OpenIpoptOutputFile(p1, "ipopt.log", 5)
Ipopt.IpoptSolve(p1)
Ipopt.FreeIpoptProblem(p1)
print(read("ipopt.log", String))
p2 = build_problem();
p2.x = [1.0, 4.75, 3.82, 1.379];
Ipopt.OpenIpoptOutputFile(p2, "ipopt.log", 5)
Ipopt.IpoptSolve(p2)
Ipopt.FreeIpoptProblem(p2)
print(read("ipopt.log", String))

```

---

<div class="post-metadata">

**Author:** ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.julialang.org/u/blob)\
**Post date:** [April 4, 2025, 7:01am UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/15 "2025-04-04T07:01:54Z")

</div>

I am not nico, but tried it on windows. When I run the code in VS code, I don’t get any errors from [this post](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/5), or from [this post](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/14), or from [the original post](https://github.com/jump-dev/Ipopt.jl/issues/470). I also tried running the code with the file “ipopt.log” open in Notepad, and the same thing, no errors. However, when I opened “ipopt.log” in MS Word and tried running the code, I got:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/9/794f4a4aea682ace3e632ec4b9307fdd5ce931b3.png)  
After closing the document in MS word manually, everything went back to normal with the code from [this post](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/5), or from [this post](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/14).

I do get a weird thing with the ipopt.out file from the original github issue:

```julia
Calling FreeIpoptProblem with valid pointererror in running finalizer: ErrorException("task switch not allowed from inside gc finalizer")
ijl_error at C:/workdir/src\rtutils.c:41
ijl_switch at C:/workdir/src\task.c:636
try_yieldto at .\task.jl:935
wait at .\task.jl:1009
uv_write at .\stream.jl:1048
unsafe_write at .\stream.jl:1120
write at .\strings\io.jl:248 [inlined]
print at .\strings\io.jl:250 [inlined]
print at .\strings\io.jl:46
jl_apply at C:/workdir/src\julia.h:1982 [inlined]
do_apply at C:/workdir/src\builtins.c:768
println at .\strings\io.jl:75
println at .\coreio.jl:4

```

Summary to get the weird thing:

1. Run

> **Code from github**
>
> ```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)
> 
> ```

1. Try opening ipopt.out manually with MS Word, click “cancel” when the pop up comes:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/e/5e056ff5bbedaf2f6359adcce58e8dca103af1f0.png). A blank MS word file opens, close it manually

3.Run the code from 1. again and get the error.

My versions:

- Julia Version 1.10.5
- Ipopt v1.8.0

---

<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 4, 2025, 8:15am UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/16 "2025-04-04T08:15:52Z")

</div>

> [@blob](#):
>
> However, when I opened “ipopt.log” in MS Word and tried running the code, I got:

That’s expected. Interesting that you can’t reproduce the other errors. I guess we’ll have to wait for Nico. Thanks for checking!

---

<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 10, 2025, 9:02am UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/17 "2025-04-10T09:02:20Z")

</div>

> [@odow](#):
>
> ```julia
> using Ipopt
> function eval_f(x::Vector{Float64})
> return x[1] * x[4] * (x[1] + x[2] + x[3]) + x[3]
> end
> function eval_g(x::Vector{Float64}, g::Vector{Float64})
> g[1] = x[1] * x[2] * x[3] * x[4]
> g[2] = x[1]^2 + x[2]^2 + x[3]^2 + x[4]^2
> return
> end
> function eval_grad_f(x::Vector{Float64}, grad_f::Vector{Float64})
> grad_f[1] = x[1] * x[4] + x[4] * (x[1] + x[2] + x[3])
> grad_f[2] = x[1] * x[4]
> grad_f[3] = x[1] * x[4] + 1
> grad_f[4] = x[1] * (x[1] + x[2] + x[3])
> return
> end
> function eval_jac_g(
> x::Vector{Float64},
> rows::Vector{Int32},
> cols::Vector{Int32},
> values::Union{Nothing,Vector{Float64}},
> )
> if values === nothing
> rows .= [1, 1, 1, 1, 2, 2, 2, 2]
> cols .= [1, 2, 3, 4, 1, 2, 3, 4]
> else
> values[1] = x[2] * x[3] * x[4] # 1,1
> values[2] = x[1] * x[3] * x[4] # 1,2
> values[3] = x[1] * x[2] * x[4] # 1,3
> values[4] = x[1] * x[2] * x[3] # 1,4
> values[5] = 2 * x[1] # 2,1
> values[6] = 2 * x[2] # 2,2
> values[7] = 2 * x[3] # 2,3
> values[8] = 2 * x[4] # 2,4
> end
> return
> end
> function build_problem()
> prob = Ipopt.CreateIpoptProblem(
> 4, # n
> [1.0, 1.0, 1.0, 1.0], # x_L
> [5.0, 5.0, 5.0, 5.0], # x_U
> 2, # m
> [25.0, 40.0], # g_L
> [Inf, 40.0], # g_U
> 8,
> 10,
> eval_f,
> eval_g,
> eval_grad_f,
> eval_jac_g,
> nothing, # eval_h,
> )
> Ipopt.AddIpoptStrOption(prob, "hessian_approximation", "limited-memory")
> return prob
> end
> 
> function Ipopt.FreeIpoptProblem(prob::Ipopt.IpoptProblem)
> if prob.ipopt_problem === C_NULL
> println("Calling FreeIpoptProblem with NULL")
> return
> end
> println("Calling FreeIpoptProblem with valid pointer")
> @ccall Ipopt.libipopt.FreeIpoptProblem(prob::Ptr{Cvoid})::Cvoid
> prob.ipopt_problem = C_NULL
> return
> end
>  
> p1 = build_problem();
> Ipopt.OpenIpoptOutputFile(p1, "ipopt.log", 5)
> Ipopt.IpoptSolve(p1)
> Ipopt.FreeIpoptProblem(p1)
> print(read("ipopt.log", String))
> p2 = build_problem();
> p2.x = [1.0, 4.75, 3.82, 1.379];
> Ipopt.OpenIpoptOutputFile(p2, "ipopt.log", 5)
> Ipopt.IpoptSolve(p2)
> Ipopt.FreeIpoptProblem(p2)
> print(read("ipopt.log", String))
> 
> ```

Running this, I do not get an error…

---

<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 10, 2025, 9:10am UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/18 "2025-04-10T09:10:45Z")

</div>

On the other hand, if I run this code multiple times:

```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)

```

I still get, sometimes, this 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\Desktop\test_ipopt_error\test2ipopt.jl:33
 [6] top-level scope
   @ c:\Users\nicolo\Desktop\test_ipopt_error\test2ipopt.jl:64
Some type information was truncated. Use `show(err)` to see complete types.

```

The issue is not consistent. Sometimes the code runs, and sometimes it gives this error.  
A note, I run the code in a Desktop folder, which is not synced to any cloud storage. And the output file is not open by any file reader.

---

<div class="post-metadata">

**Author:** ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.julialang.org/u/blob)\
**Post date:** [April 10, 2025, 10:11am UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/19 "2025-04-10T10:11:59Z")

</div>

I was able to reproduce this error (it took four runs after restarting repl, the fourth errored):  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/b/fb0f44fd856ee680a99c5472bb1bd26c818e7455.png)  
in an environment where I added only SNOW:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/6/e6d2ed6f0000d85333b6f57adb7afd911f1263ed.png)  
But it is inconsistent after that, sometimes it errors twice in a row, sometimes it takes two runs.

Funnily enough, the error only happens after I restart repl. If I first run the more involved environment, then `activate justSNOW` I don’t get the error after many runs. However, it always takes four runs after restarting repl.

When I run the code in a more involved environment:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/5/b506499230715d4a3bbb3173c1b47d1562687052.png)  
I couldn’t get the same error even after many runs.

---

<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 10, 2025, 8:20pm UTC](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595/20 "2025-04-10T20:20:04Z")

</div>

> Running this, I do not get an error…

So I think this means that Ipopt is releasing the file handle only when `FreeIpoptProblem` is called, which you currently can’t do manually because we don’t support calling the finalizer twice.

Even if we fixed Ipopt.jl to allow this, we’d still need to patch SNOW to call it, and probably JuMP and Ipopt.jl, except that persisting the IpoptProblem between solves is desired behavior in many cases.

This might need to be fixed upstream in coin-or/Ipopt.

[Next page](https://discourse.julialang.org/t/ipopt-suppress-output-file-generation/127595.md?page=2)
