QuEraComputing / Bloqade.jl

Package for the quantum computation and quantum simulation based on the neutral-atom architecture.
https://queracomputing.github.io/Bloqade.jl/dev/
Other
181 stars 35 forks source link

[BUG] Using Bloqade together with EnsembleDistributed() #586

Open benmcdonough20 opened 1 year ago

benmcdonough20 commented 1 year ago

Describe the bug When constructing an EnsembleProblem with a SchrodingerProblem and using the EnsembleDistributed algorithm to parallelize the simulations, several workers cannot run simultaneously due to a lock on .CondaPkg. The error message produced is the following:

From worker 3:    ┌ Info: CondaPkg: Waiting for lock to be freed. You may delete this file if no other process is resolving.
From worker 3:    └   lock_file = "/Users/queraintern/.julia/environments/v1.9/.CondaPkg/lock"

To Reproduce Here is a minimum working example:

using Bloqade
using OrdinaryDiffEq

atoms = generate_sites(ChainLattice(), 1, scale = 1)
h = rydberg_h(atoms; Ω = 2π)
reg = zero_state(1)

problem = SchrodingerProblem(reg, 1.0, h)

ep = EnsembleProblem(problem)

sim = solve(ep, DP8(), EnsembleDistributed(); trajectories = 2)

Running this code with julia -p 2 minimum_working_example.jl produces the issue.

Version Info

benmcdonough20 commented 1 year ago

Update: I think that PythonCall is the issue. The bug can be fixed by avoiding the Bloqade init through replacing using Bloqade with using BloqadeExpr, BloqadeODE, BloqadeLattices.

kaihsin commented 1 year ago

A quick fix is to only let the master process import Python Call, and only allow master proc to plot

So if we modify the following part in src/Bloqade.jl :

using PythonCall
const plt = PythonCall.pynew()

function __init__()
    # copied from PyPlotCall.jl
    PythonCall.pycopy!(plt, pyimport("matplotlib.pyplot"))
    return
end

to

using Distributed
const plt = nothing
@spawnat 1 :(using PythonCall)
@spawnat 1 :(const plt = PythonCall.pynew())

function __init__()
    if getpid()==1
        # copied from PyPlotCall.jl
        PythonCall.pycopy!(plt, pyimport("matplotlib.pyplot"))
    end
    return
end

@weinbe58 @Roger-luo

kaihsin commented 1 year ago

Also might related to #554