Skip to content

Commit

Permalink
Merge pull request #507 from JuliaTrustworthyAI/issue-with-benchmark
Browse files Browse the repository at this point in the history
Fix small issue in benchmark function
  • Loading branch information
pat-alt authored Jan 1, 2025
2 parents 3c7b76f + 6171f71 commit 218b297
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
### Changed

- Slight change to `FlattenedCE` and `unflatten` to ensure that basic functionality remains intact. [#505]
- Fixed small issue in `benchmark` function.

## Version [1.4.1] - 2024-12-19

Expand Down
6 changes: 4 additions & 2 deletions src/evaluation/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ function benchmark(
)

# Unflatten for evaluation:
@assert typeof(ces) == Vector{FlattenedCE} "Expecting a vector of `FlattenedCE`. Did you accidentally set `return_flattened=false`?"
@assert all(typeof.(ces) .== FlattenedCE) "Expecting a vector of `FlattenedCE`. Did you accidentally set `return_flattened=false`?"
ces = convert(Vector{FlattenedCE}, ces)
ces = unflatten_for_eval(ces, data, Ms, gens, kwrgs)

# Meta Data:
Expand Down Expand Up @@ -432,7 +433,8 @@ function benchmark(
)

# Unflatten for evaluation:
@assert typeof(ces) == Vector{FlattenedCE} "Expecting a vector of `FlattenedCE`. Did you accidentally set `return_flattened=false`?"
@assert all(typeof.(ces) .== FlattenedCE) "Expecting a vector of `FlattenedCE`. Did you accidentally set `return_flattened=false`?"
ces = convert(Vector{FlattenedCE}, ces)
ces = unflatten_for_eval(ces, data, Ms, gens, kwrgs)

# Free up memory:
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
TaijaData = "9d524318-b4e6-4a65-86d2-b2b72d07866c"
TaijaParallel = "bf1c2c22-5e42-4e78-8b6b-92e6c673eeb0"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Expand Down
12 changes: 12 additions & 0 deletions test/other/evaluation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using CounterfactualExplanations.Evaluation:
using CounterfactualExplanations.Objectives: distance
using Serialization: serialize
using TaijaData: load_moons, load_circles
using TaijaParallel: ThreadsParallelizer

# Dataset
data = TaijaData.load_overlapping()
Expand Down Expand Up @@ -70,6 +71,17 @@ end
@testset "Benchmarking" begin
bmk = Evaluation.benchmark(counterfactual_data; convergence=:generator_conditions)

@testset "Parallelization" begin
@testset "Threads" begin
parallelizer = ThreadsParallelizer()
bmk = benchmark(
counterfactual_data;
convergence=:generator_conditions,
parallelizer=parallelizer,
)
end
end

@testset "Basics" begin
@test typeof(bmk()) <: DataFrame
@test typeof(bmk(; agg=nothing)) <: DataFrame
Expand Down

2 comments on commit 218b297

@pat-alt
Copy link
Member Author

@pat-alt pat-alt commented on 218b297 Jan 1, 2025

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/122241

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.4.2 -m "<description of version>" 218b297e81de08c900ddf98321cf7220054c0411
git push origin v1.4.2

Please sign in to comment.