-
Notifications
You must be signed in to change notification settings - Fork 5
Bug in assemble when using threads #47
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
@cortner Here is the bug with assemble. Basically you need to have PR #46 in use. Then this triggers the bug
using Folds
function broken_assemble(data::AbstractArray, basis; kwargs...)
W = Threads.@spawn ACEfit.assemble_weights(data; kwargs...)
raw_data = Folds.map( data ) do d # this will bug out
#raw_data = pmap( data ) do d # this works
A = ACEfit.feature_matrix(d, basis; kwargs...)
Y = ACEfit.target_vector(d; kwargs...)
(A, Y)
end
A = [ a[1] for a in raw_data ]
Y = [ a[2] for a in raw_data ]
A_final = reduce(vcat, A)
Y_final = reduce(vcat, Y)
return A_final, Y_final, fetch(W)
endWhen you try same input several times, it gives different results and some times the arrays have even different sizes
Here is a full working example:
using ACEmd
using ACEfit
using ACEpotentials
model = acemodel(
elements = [:Ti, :Al],
order = 3,
totaldegree = 6,
rcut = 5.5,
Eref = [:Ti => -1586.0195, :Al => -105.5954]
)
basis = model.basis
data_j, _, meta = ACEpotentials.example_dataset("TiAl_tutorial")
train_new = [ FlexibleSystem(x) for x in data_j[1:5:end] ]
# Ref data
A, Y, W = ACEfit.assemble(train_new, basis; energy_default_weight=5, energy_ref=model.Vref)
## Broken code
using Folds
function broken_assemble(data::AbstractArray, basis; kwargs...)
W = Threads.@spawn ACEfit.assemble_weights(data; kwargs...)
raw_data = Folds.map( data ) do d # this will bug out
#raw_data = pmap( data ) do d # this works
A = ACEfit.feature_matrix(d, basis; kwargs...)
Y = ACEfit.target_vector(d; kwargs...)
(A, Y)
end
A = [ a[1] for a in raw_data ]
Y = [ a[2] for a in raw_data ]
A_final = reduce(vcat, A)
Y_final = reduce(vcat, Y)
return A_final, Y_final, fetch(W)
end
##
for i in 1:10
a, y, w = broken_assemble(train_new, basis; energy_default_weight=5, energy_ref=model.Vref)
# Compare results
@info "Maximum error " maximum(abs2, A - a)
endReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working