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)