Skip to content

Commit f1bdc47

Browse files
ChrisRackauckas-ClaudeChrisRackauckasclaude
authored
Fix BenchmarkTools.DEFAULT_PARAMETERS const assignment error in Julia 1.12 (#765)
* Fix BenchmarkTools.DEFAULT_PARAMETERS const assignment error in Julia 1.12 - Remove global modification of BenchmarkTools.DEFAULT_PARAMETERS which fails in Julia 1.12+ due to const restriction - Pass seconds and samples parameters directly to @benchmark macro - Remove try/finally block that was only needed for parameter restoration - Fixes issue #744 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Fix BenchmarkTools.DEFAULT_PARAMETERS const assignment error in Julia 1.12 - Remove global modification of BenchmarkTools.DEFAULT_PARAMETERS which fails in Julia 1.12+ due to const restriction - Use @benchmarkable and BenchmarkTools.run with custom parameters - Remove try/finally block that was only needed for parameter restoration - Fixes issue #744 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: ChrisRackauckas <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent e86eb88 commit f1bdc47

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lib/LinearSolveAutotune/src/benchmarking.jl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ function benchmark_algorithms(matrix_sizes, algorithms, alg_names, eltypes;
8787
samples = 5, seconds = 0.5, sizes = [:tiny, :small, :medium, :large],
8888
check_correctness = true, correctness_tol = 1e0, maxtime = 100.0)
8989

90-
# Set benchmark parameters
91-
old_params = BenchmarkTools.DEFAULT_PARAMETERS
92-
BenchmarkTools.DEFAULT_PARAMETERS.seconds = seconds
93-
BenchmarkTools.DEFAULT_PARAMETERS.samples = samples
90+
# Note: We pass benchmark parameters directly to @benchmark instead of
91+
# modifying BenchmarkTools.DEFAULT_PARAMETERS to avoid const assignment
92+
# errors in Julia 1.12+
9493

9594
# Initialize results DataFrame
9695
results_data = []
@@ -111,8 +110,7 @@ function benchmark_algorithms(matrix_sizes, algorithms, alg_names, eltypes;
111110
progress = Progress(total_benchmarks, desc="Benchmarking: ",
112111
barlen=50, showspeed=true)
113112

114-
try
115-
for eltype in eltypes
113+
for eltype in eltypes
116114
# Initialize blocked algorithms dict for this element type
117115
blocked_algorithms[string(eltype)] = Dict{String, Int}()
118116

@@ -234,10 +232,13 @@ function benchmark_algorithms(matrix_sizes, algorithms, alg_names, eltypes;
234232
error_msg = "Insufficient time for benchmarking"
235233
else
236234
# Actual benchmark
237-
bench = @benchmark solve($prob, $alg) setup=(prob = LinearProblem(
235+
# Create benchmark with custom parameters
236+
bench_params = BenchmarkTools.Parameters(;seconds=seconds, samples=samples)
237+
b = @benchmarkable solve($prob, $alg) setup=(prob = LinearProblem(
238238
copy($A), copy($b);
239239
u0 = copy($u0),
240240
alias = LinearAliasSpecifier(alias_A = true, alias_b = true)))
241+
bench = BenchmarkTools.run(b, bench_params)
241242

242243
# Calculate GFLOPs
243244
min_time_sec = minimum(bench.times) / 1e9
@@ -269,11 +270,6 @@ function benchmark_algorithms(matrix_sizes, algorithms, alg_names, eltypes;
269270
ProgressMeter.next!(progress)
270271
end
271272
end
272-
end
273-
274-
finally
275-
# Restore original benchmark parameters
276-
BenchmarkTools.DEFAULT_PARAMETERS = old_params
277273
end
278274

279275
return DataFrame(results_data)

0 commit comments

Comments
 (0)