Skip to content

Commit f846320

Browse files
check fixes
1 parent 86c6045 commit f846320

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/RobustPmap.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import FileIO
1414
function checkexceptions(x::Any, t::Type=Any, args...)
1515
for i in eachindex(x)
1616
if isa(x[i], Exception)
17-
@error("Execution failed for one of the runs (run #$(i)) with exception error $(typeof(x[i]))!")
17+
@error("Execution failed for one of the runs (run $(i) out of $(length(x))) with exception error $(typeof(x[i]))!")
1818
@error("Failing input parameter set: $(args[1][i])")
19-
throw(TypeError(:RobustPmap, t, x[i]))
19+
throw(ErrorException("Run failed with exception error $(typeof(x[i]))!"))
2020
elseif !isa(x[i], t)
21-
@error("Execution failed for one of the runs (run #$(i))")
21+
@error("Execution failed for one of the runs (run $(i) out of $(length(x))) producing an expected output of type $(typeof(x[i]))!")
2222
@error("Failing input parameter set: $(args[1][i])")
2323
throw(TypeError(:RobustPmap, t, x[i]))
2424
end
@@ -27,14 +27,14 @@ function checkexceptions(x::Any, t::Type=Any, args...)
2727
end
2828

2929
"Robust pmap call"
30-
function rpmap(f::Function, args...; t::Type=Any)
30+
function rpmap(f::Function, args...; t::Type=Any, checkoutputs::Bool=true)
3131
x = Distributed.pmap(f, args...; on_error=x->x)
32-
checkexceptions(x, t, args...)
33-
return convert(Vector{t}, x)
32+
checkoutputs && checkexceptions(x, t, args...)
33+
return convert(Array{t}, x) # x can be either a matrix or vector
3434
end
3535

3636
"Robust pmap call with checkpoints"
37-
function crpmap(f::Function, checkpointfrequency::Int, filerootname::AbstractString, args...; t::Type=Any)
37+
function crpmap(f::Function, checkpointfrequency::Int, filerootname::AbstractString, args...; t::Type=Any, checkoutputs::Bool=true)
3838
fullresult = t[]
3939
hashargs = hash(args)
4040
if checkpointfrequency <= 0
@@ -47,7 +47,7 @@ function crpmap(f::Function, checkpointfrequency::Int, filerootname::AbstractStr
4747
if isfile(filename)
4848
partialresult = FileIO.load(filename, "partialresult")
4949
else
50-
partialresult = rpmap(f, map(x->x[r], args)...; t=t)
50+
partialresult = rpmap(f, map(x->x[r], args)...; t=t, checkoutputs=checkoutputs)
5151
FileIO.save(filename, "partialresult", partialresult)
5252
end
5353
append!(fullresult, partialresult)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if Distributed.nworkers() < 2
99
end
1010

1111
@Distributed.everywhere rpmfn(x) = x > 0 ? 1 : 1.
12+
1213
function testtypecheck()
1314
@Test.test_throws TypeError RobustPmap.rpmap(rpmfn, [-1, 0, 1]; t=Int)
1415
end

0 commit comments

Comments
 (0)