Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9 bug cant use decisionthresholdconvergence object #10

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TaijaParallel"
uuid = "bf1c2c22-5e42-4e78-8b6b-92e6c673eeb0"
authors = ["Patrick Altmeyer <[email protected]>"]
version = "1.0.2"
version = "1.0.3"

[deps]
CounterfactualExplanations = "2f13d31b-18db-44c1-bc43-ebaf2cff0be0"
Expand Down
21 changes: 16 additions & 5 deletions src/TaijaParallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,47 @@ macro with_parallelizer(parallelizer, expr)
expr = expr.args[end]
end

Meta.show_sexpr(expr)
println("")

# Unpack arguments:
pllr = esc(parallelizer)
f = esc(expr.args[1])
args = expr.args[2:end]

# Split args into positional and keyword arguments:
aargs = []
aakws = Pair{Symbol,Any}[]
kwargs_names = []
kwargs_values = []
for el in args
if Meta.isexpr(el, :parameters)
for kw in el.args
k = kw.args[1] # parameter name
v = kw.args[2] # parameter value
v = typeof(v) == QuoteNode ? v.value : v
push!(aakws, Pair(k, v))
# v = typeof(v) == QuoteNode ? v.value : v
push!(kwargs_names, k)
push!(kwargs_values, v)
end
else
push!(aargs, el)
end
end

# Escape arguments:
# Escape arguments and create a tuple:
escaped_args = Expr(:tuple, esc.(aargs)...)
kwargs_names = tuple(kwargs_names...)
sym = QuoteNode.(kwargs_names)
kwargs_values = tuple(kwargs_values...)

# Parallelize:
output = quote
if !TaijaParallel.parallelizable($f)
throw(AssertionError("$($f) is not a parallelizable process."))
else
@info "Parallelizing with $($pllr)"
end
output = TaijaBase.parallelize($pllr, $f, $escaped_args...; $aakws...)
escaped_kwargs = $NamedTuple{($(sym...),)}(($(esc.(kwargs_values)...),))
output = TaijaBase.parallelize($pllr, $f, $escaped_args...; escaped_kwargs...)
output
end
return output
Expand Down
4 changes: 3 additions & 1 deletion test/CounterfactualExplanations.jl/threads.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterfactualExplanations
using CounterfactualExplanations.Convergence
using TaijaData
using TaijaParallel: ThreadsParallelizer, @with_parallelizer

Expand All @@ -11,6 +12,7 @@ counterfactual_data =
data[2],
)
M = fit_model(counterfactual_data, :MLP)
conv = DecisionThresholdConvergence(decision_threshold = 0.95)
generator = GenericGenerator()
factual = 1
target = 2
Expand All @@ -19,7 +21,7 @@ xs = select_factual(counterfactual_data, chosen)

parallelizer = ThreadsParallelizer()
ces = @with_parallelizer parallelizer begin
generate_counterfactual(xs, target, counterfactual_data, M, generator)
generate_counterfactual(xs, target, counterfactual_data, M, generator; convergence = conv)
end

@test true
Loading
Loading