MilesCranmer / SymbolicRegression.jl

Distributed High-Performance Symbolic Regression in Julia
https://ai.damtp.cam.ac.uk/symbolicregression/
Apache License 2.0
636 stars 82 forks source link

EquationSearch freezes with zero CPU utilization #8

Closed baggepinnen closed 3 years ago

baggepinnen commented 3 years ago

I'm trying a very simple example on v0.3.3 (julia v1.6 beta1) and it just freezes without using any CPU. If I ctrl-C, I get the error below

using SymbolicRegression
options = SymbolicRegression.Options(
    binary_operators=(+, *, /, -),
    unary_operators=(cos, sin, sqrt),
    npopulations=20
)
niterations = 5

X = randn(3, 10)
y = randn(10)

hallOfFame = EquationSearch(X, y, niterations=niterations, options=options)
ERROR: InterruptException:

...and 19 more exceptions.

Stacktrace:
 [1] sync_end(c::Channel{Any})
   @ Base ./task.jl:364
 [2] macro expansion
   @ ./task.jl:383 [inlined]
 [3] EquationSearch(X::Matrix{Float64}, y::Vector{Float64}; niterations::Int64, weights::Nothing, varMap::Nothing, options::Options{Tuple{typeof(+), typeof(*), typeof(/), typeof(-)}, Tuple{typeof(cos), typeof(sin), typeof(sqrtm)}})
   @ SymbolicRegression ~/.julia/packages/SymbolicRegression/sSsHc/src/SymbolicRegression.jl:117
 [4] top-level scope
   @ REPL[19]:1
 [5] eval
   @ ./boot.jl:360 [inlined]
baggepinnen commented 3 years ago

I can add that if I add some addprocs ~it seems to work~, but I guess it would be good to support also the single-process setting?

EDIT: it worked for a while, then I got a segmentation fault. Unfortunately, vscode kills the terminal once you get the segmentation fault so I cannot copy the trace :/

MilesCranmer commented 3 years ago

Hey @baggepinnen, thanks for trying it out! Sorry it's not giving you useful error messages - I should add some warning about workers not being set up.

But yeah, unfortunately it only works in a distributed fashion for right now, for example,

using Distributed
procs = addprocs(4)
@everywhere using SymbolicRegression

X = randn(Float32, 5, 100)
y = 2 * cos.(X[4, :]) + X[1, :] .^ 2 .- 2

options = SymbolicRegression.Options(
    binary_operators=(+, *, /, -),
    unary_operators=(cos, exp),
    npopulations=20
)
niterations = 5
hallOfFame = EquationSearch(X, y, niterations=niterations, options=options)
rmprocs(procs)

However, the (draft) pull request #7 should add functionality to automatically set up workers internal to the module. It should be much easier to set up then!

Cheers, Miles

MilesCranmer commented 3 years ago

By the way, when you used addprocs, did you also import with @everywhere? That might be why it got the segfault-perhaps one of the workers can't call the module functions.

baggepinnen commented 3 years ago

Yep, I called it exactly like so

procs = addprocs(4)
@everywhere using SymbolicRegression

Before it crashed, it ran for about 5 minutes and some 20-30 iterations, producing some outputs in the terminal. I'll experiment a bit more from the standard terminal and see if it happens again.

MilesCranmer commented 3 years ago

Would definitely be good for this package to support serial computation too; I'll add it to my todo list.

Weird, did you call rmprocs(procs) at the end? I get some errors if I don't remove the workers before exiting. This code runs okay for me:

procs = addprocs(4)
@everywhere using SymbolicRegression
options = SymbolicRegression.Options(
    binary_operators=(+, *, /, -),
    unary_operators=(cos, sin, sqrt),
    npopulations=20
)
niterations = 5

X = randn(3, 10)
y = randn(10)

hallOfFame = EquationSearch(X, y, niterations=niterations, options=options)
rmprocs(procs)
MilesCranmer commented 3 years ago

Hey @baggepinnen;

Try out v0.4.0 - it sets up the workers automatically! No more having to call Distributed and @everywhere in your script.

e.g.,

using SymbolicRegression

X = randn(Float32, 5, 100)
y = 2 * cos.(X[4, :]) + X[1, :] .^ 2 .- 2

options = SymbolicRegression.Options(
    binary_operators=(+, *, /, -),
    unary_operators=(cos, exp),
    npopulations=20
)

hallOfFame = EquationSearch(X, y, niterations=5, options=options, numprocs=4)
MilesCranmer commented 3 years ago

FYI @baggepinnen with v0.4.1 I also added a mechanism for entirely non-distributed code. Just use numprocs=0 in the call to EquationSearch, and all computation will happen sequentially.