I am trying to use Symbolics.jl to perform parallel symbolic manipulations, but it seems like the package is not threadsafe.
With the following code,
Threads.@threads for i in range(1,8)
@variables k
expand(k)
println(i)
end
I get the following error
ERROR: LoadError: TaskFailedException
Stacktrace:
[1] wait
@ ./task.jl:345 [inlined]
[2] threading_run(fun::var"#3#threadsfor_fun#2"{var"#3#threadsfor_fun#1#3"{UnitRange{Int64}}}, static::Bool)
@ Base.Threads ./threadingconstructs.jl:38
[3] top-level scope
@ ./threadingconstructs.jl:89
8
nested task error:
One of x or y already in this Bijection
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] setindex!(b::Bijections.Bijection{Any, Any}, y::SymbolicUtils.Sym{Real, Base.ImmutableDict{DataType, Any}}, x::DynamicPolynomials.PolyVar{true})
@ Bijections ~/.julia/packages/Bijections/IWrOY/src/Bijections.jl:74
[3] polyize(x::SymbolicUtils.Sym{Real, Base.ImmutableDict{DataType, Any}}, pvar2sym::Bijections.Bijection{Any, Any}, sym2term::Dict{SymbolicUtils.Sym, Any}, vtype::Type, pow::Function, Fs::Type, recurse::Bool)
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/qulQp/src/polyform.jl:178
[4] PolyForm(x::SymbolicUtils.Sym{Real, Base.ImmutableDict{DataType, Any}}, pvar2sym::Bijections.Bijection{Any, Any}, sym2term::Dict{SymbolicUtils.Sym, Any}, vtype::Type; Fs::Type, recurse::Bool, metadata::Base.ImmutableDict{DataType, Any})
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/qulQp/src/polyform.jl:196
[5] expand(expr::SymbolicUtils.Sym{Real, Base.ImmutableDict{DataType, Any}})
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/qulQp/src/polyform.jl:262
[6] expand(n::Num)
@ Symbolics ~/.julia/packages/Symbolics/FGTCH/src/Symbolics.jl:154
[7] macro expansion
@ ~/Documents/cmb_replication/test_example.jl:6 [inlined]
[8] (::var"#3#threadsfor_fun#2"{var"#3#threadsfor_fun#1#3"{UnitRange{Int64}}})(tid::Int64; onethread::Bool)
@ Main ./threadingconstructs.jl:84
[9] #3#threadsfor_fun
@ ./threadingconstructs.jl:51 [inlined]
[10] (::Base.Threads.var"#1#2"{var"#3#threadsfor_fun#2"{var"#3#threadsfor_fun#1#3"{UnitRange{Int64}}}, Int64})()
@ Base.Threads ./threadingconstructs.jl:307
Is there anyway to use locks or other thread-safe tools with Symbolics.jl to allow for parallel computation with this package?