Skip to content

Non reproducible behaviour of pathfinder if run in parallel (even if every task gets passed its own RNG) #248

@nsiccha

Description

@nsiccha

As per the title. I have been unable to reproduce some results in a project I'm working on, and it seems to be due to pathfinder.

The following code results in output like the one below:

using Pathfinder, LogDensityProblems, Random, ForwardDiff, LogDensityProblemsAD
begin
    struct StdNormal
        dim::Int64
    end
    LogDensityProblems.dimension(p::StdNormal) = p.dim
    LogDensityProblems.logdensity(::StdNormal, x) = -.5sum(abs2, x)
    struct Funnel
        dim::Int64
    end
    LogDensityProblems.dimension(p::Funnel) = p.dim
    LogDensityProblems.logdensity(::Funnel, x) = -.5*x[1]^2-x[1]-.5sum(abs2, x[2:end]./exp(x[1]))

    n_rep = 100
    dim = 100
    rv = Vector{Any}(missing, n_rep)
    Threads.@threads for i in 1:n_rep
        rng = Xoshiro(1)
        problem = ADgradient(:ForwardDiff, StdNormal(dim))
        pathfinder(problem; rng)
        rv[i] = rng
    end
    display("Parallel normal"=>rv |> unique |> length)
    for i in 1:n_rep
        rng = Xoshiro(1)
        problem = ADgradient(:ForwardDiff, Funnel(dim))
        pathfinder(problem; rng)
        rv[i] = rng
    end
    display("Serial funnel"=>rv |> unique |> length)
    Threads.@threads for i in 1:n_rep
        rng = Xoshiro(1)
        problem = ADgradient(:ForwardDiff, Funnel(dim))
        pathfinder(problem; rng)
        rv[i] = rng
    end
    display("Parallel funnel"=>rv |> unique |> length)
end
"Parallel normal" => 1
"Serial funnel" => 1
┌ Warning: 2 (10.0%) updates to the inverse Hessian estimate were rejected to keep it positive definite.
└ @ Pathfinder ~/.julia/packages/Pathfinder/Dppsn/src/singlepath.jl:227
┌ Warning: 1 (4.5%) updates to the inverse Hessian estimate were rejected to keep it positive definite.
└ @ Pathfinder ~/.julia/packages/Pathfinder/Dppsn/src/singlepath.jl:227
┌ Warning: 1 (5.9%) updates to the inverse Hessian estimate were rejected to keep it positive definite.
└ @ Pathfinder ~/.julia/packages/Pathfinder/Dppsn/src/singlepath.jl:227
┌ Warning: 1 (5.0%) updates to the inverse Hessian estimate were rejected to keep it positive definite.
└ @ Pathfinder ~/.julia/packages/Pathfinder/Dppsn/src/singlepath.jl:227
┌ Warning: 1 (4.3%) updates to the inverse Hessian estimate were rejected to keep it positive definite.
└ @ Pathfinder ~/.julia/packages/Pathfinder/Dppsn/src/singlepath.jl:227
┌ Warning: 1 (6.2%) updates to the inverse Hessian estimate were rejected to keep it positive definite.
└ @ Pathfinder ~/.julia/packages/Pathfinder/Dppsn/src/singlepath.jl:227
┌ Warning: 1 (5.0%) updates to the inverse Hessian estimate were rejected to keep it positive definite.
└ @ Pathfinder ~/.julia/packages/Pathfinder/Dppsn/src/singlepath.jl:227
┌ Warning: 1 (5.6%) updates to the inverse Hessian estimate were rejected to keep it positive definite.
└ @ Pathfinder ~/.julia/packages/Pathfinder/Dppsn/src/singlepath.jl:227
"Parallel funnel" => 11

with Pkg.status() output of

(Pathfinder) pkg> status
Status `~/github/nsiccha/mwe/Pathfinder/Project.toml`
⌃ [f6369f11] ForwardDiff v0.10.38
  [6fdf6af0] LogDensityProblems v2.1.2
  [996a588d] LogDensityProblemsAD v1.13.0
  [b1d3bc72] Pathfinder v0.9.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions