Skip to content

Commit

Permalink
Merge pull request #10 from JuliaTrustworthyAI/9-bug-cant-use-decisio…
Browse files Browse the repository at this point in the history
…nthresholdconvergence-object
  • Loading branch information
pat-alt authored Apr 29, 2024
2 parents 303a831 + 1ea2443 commit 8534c12
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 133 deletions.
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

2 comments on commit 8534c12

@pat-alt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105801

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.3 -m "<description of version>" 8534c12b67a9f1ecda0186d992843d249e6a0a28
git push origin v1.0.3

Please sign in to comment.