StackOverflowError when using PRIMA.jl on Ubuntu (works fine on macOS and Windows)

Hi everyone,

I’m running into a strange StackOverflowError when using Julia on Ubuntu. The same code runs without any issues on macOS and Windows.

I’m using PRIMA.jl (via OptimizationPRIMA.jl) to optimize a function. My real use case is more complex, but I was able to replicate the error with the following minimal working example:

using Optimization, OptimizationPRIMA

function debug_objective(x, p)
    result = sum((x .- p).^2)
    return result
end

function test_optimizer()
    x0 = [1.0, 2.0]
    p  = [3.0, 4.0]
    lb = [0.0, 0.0]
    ub = [10.0, 10.0]

    prob = OptimizationProblem(debug_objective, x0, p; lb=lb, ub=ub)
    result = Optimization.solve(prob, BOBYQA(), maxiters=100)

    return result
end

test_optimizer()

I have checked related GitHub issues and discussions about platform-specific behavior, but nothing helped so far.

Has anyone encountered similar issues using PRIMA.jl on Ubuntu, or do you have any ideas on how to debug further?

Thanks in advance!

Edit 1: I found a GitHub issue that seems to describe the same problem: Problems with Linux (Arch) · Issue #25 · libprima/PRIMA.jl · GitHub

Edit 2: After discussing it with @abraemer, I observed that when I run the code above sequentially in the terminal, there is no problem. When I run it in VS Code, I do encounter the problem.

However, running the code in parallel results in the same problem both in the terminal and in VS Code. Here’s the parallel version that reproduces the issue:

using Distributed
addprocs(8)  # Add some workers

@everywhere begin
    using Optimization, OptimizationPRIMA

    function debug_objective(x, p)
        result = sum((x .- p).^2)
        return result
    end

    function test_optimizer()
        x0 = [1.0, 2.0]
        p  = [3.0, 4.0]
        lb = [0.0, 0.0]
        ub = [10.0, 10.0]

        prob = OptimizationProblem(debug_objective, x0, p; lb=lb, ub=ub)
        result = Optimization.solve(prob, BOBYQA(), maxiters=100)
        return result
    end
end

# Run the optimizer on the worker (process 2)
result = fetch(@spawnat 2 test_optimizer())
println(result)

cannot confirm. What’s your OS and versioninfo()?

julia> test_optimizer()
retcode: Success
u: 2-element Vector{Float64}:
 2.999999999999999
 3.999999999999999

julia> versioninfo()
Julia Version 1.11.4
Commit 8561cc3d68d (2025-03-10 11:36 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 4800H with Radeon Graphics
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

shell> lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04.2 LTS
Release:	24.04
Codename:	noble

Thanks for checking. I don’t know what is happening. Others have found similar issue: Problems with Linux (Arch) · Issue #25 · libprima/PRIMA.jl · GitHub

Julia Version 1.11.6
Commit 9615af0f269 (2025-07-09 12:58 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 32 × Intel(R) Core(TM) i9-14900
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 32 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_VSCODE_REPL = 1

shell> lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04.2 LTS
Release:	24.04
Codename:	noble


Some updates on your comment. When I run the code sequentially in the terminal, there is no problem. When I run it in VS Code, I do encounter the problem.

However, running the code in parallel results in the same problem both in the terminal and in VS Code.

using Distributed
addprocs(8)  # Add some workers

@everywhere begin
    using Optimization, OptimizationPRIMA

    function debug_objective(x, p)
        result = sum((x .- p).^2)
        return result
    end

    function test_optimizer()
        x0 = [1.0, 2.0]
        p  = [3.0, 4.0]
        lb = [0.0, 0.0]
        ub = [10.0, 10.0]

        prob = OptimizationProblem(debug_objective, x0, p; lb=lb, ub=ub)
        result = Optimization.solve(prob, BOBYQA(), maxiters=100)
        return result
    end
end

# Run the optimizer on the worker (process 2)
result = fetch(@spawnat 2 test_optimizer())
println(result)

Ok tried again with that code and that does indeed reproduce the issue for me. Strange that even Distributed.jl causes this. Since Distributed.jl uses processes and each process has its own copy of the library I am really surprised that this changes things. Anyhow I don’t think that I can contribute more besides reproducing the issue :sweat_smile:

1 Like