Skip to content

Commit cb1ab50

Browse files
Fix preferences to be stored in main LinearSolve.jl package
- Remove LocalPreferences.toml from sublibrary directory - Create LocalPreferences.toml in main LinearSolve.jl directory - Fix get_algorithm_preferences() to use load_preference (singular) instead of load_preferences - Update clear_algorithm_preferences() to check for preference existence before deletion - Preferences are now correctly stored in the main package where they belong - Use pattern-based preference loading since Preferences.jl doesn't have a get-all function 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 8276a95 commit cb1ab50

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

LocalPreferences.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[LinearSolve]
2+
autotune_timestamp = "2025-08-04T02:03:00.593"
3+
best_algorithm_BigFloat_256_512 = "GenericLUFactorization"
4+
best_algorithm_ComplexF64_128_256 = "AnotherAlgorithm"
5+
best_algorithm_Float64_0_128 = "NewTestAlgorithm"

lib/LinearSolveAutotune/LocalPreferences.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/LinearSolveAutotune/src/preferences.jl

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,25 @@ Handles both legacy and element type-specific preferences.
3535
function get_algorithm_preferences()
3636
prefs = Dict{String, String}()
3737

38-
# Get all LinearSolve preferences
39-
all_prefs = Preferences.load_preferences(LinearSolve, "")
38+
# Get all LinearSolve preferences by checking common preference patterns
39+
# Since there's no direct way to get all preferences, we'll check for known patterns
40+
common_patterns = [
41+
# Element type + size range combinations
42+
"Float64_0_128", "Float64_128_256", "Float64_256_512", "Float64_512plus",
43+
"Float32_0_128", "Float32_128_256", "Float32_256_512", "Float32_512plus",
44+
"ComplexF64_0_128", "ComplexF64_128_256", "ComplexF64_256_512", "ComplexF64_512plus",
45+
"ComplexF32_0_128", "ComplexF32_128_256", "ComplexF32_256_512", "ComplexF32_512plus",
46+
"BigFloat_0_128", "BigFloat_128_256", "BigFloat_256_512", "BigFloat_512plus",
47+
# Legacy patterns without element type
48+
"0_128", "128_256", "256_512", "512plus"
49+
]
4050

41-
# Filter for algorithm preferences
42-
for (key, value) in all_prefs
43-
if startswith(key, "best_algorithm_") && key != "best_algorithm_"
51+
for pattern in common_patterns
52+
pref_key = "best_algorithm_$pattern"
53+
value = Preferences.load_preference(LinearSolve, pref_key, nothing)
54+
if value !== nothing
4455
# Convert back to human-readable key
45-
readable_key = replace(key[16:end], "_" => "-", "plus" => "+") # Remove "best_algorithm_" prefix
56+
readable_key = replace(pattern, "_" => "-", "plus" => "+")
4657
prefs[readable_key] = value
4758
end
4859
end
@@ -59,18 +70,31 @@ Handles both legacy and element type-specific preferences.
5970
function clear_algorithm_preferences()
6071
@info "Clearing LinearSolve autotune preferences..."
6172

62-
# Get all LinearSolve preferences
63-
all_prefs = Preferences.load_preferences(LinearSolve, "")
73+
# Clear known preference patterns
74+
common_patterns = [
75+
# Element type + size range combinations
76+
"Float64_0_128", "Float64_128_256", "Float64_256_512", "Float64_512plus",
77+
"Float32_0_128", "Float32_128_256", "Float32_256_512", "Float32_512plus",
78+
"ComplexF64_0_128", "ComplexF64_128_256", "ComplexF64_256_512", "ComplexF64_512plus",
79+
"ComplexF32_0_128", "ComplexF32_128_256", "ComplexF32_256_512", "ComplexF32_512plus",
80+
"BigFloat_0_128", "BigFloat_128_256", "BigFloat_256_512", "BigFloat_512plus",
81+
# Legacy patterns without element type
82+
"0_128", "128_256", "256_512", "512plus"
83+
]
6484

65-
# Clear all algorithm-related preferences
66-
for (key, value) in all_prefs
67-
if startswith(key, "best_algorithm_")
68-
Preferences.delete_preferences!(LinearSolve, key; force = true)
69-
@info "Cleared preference: $key"
85+
for pattern in common_patterns
86+
pref_key = "best_algorithm_$pattern"
87+
# Check if preference exists before trying to delete
88+
if Preferences.has_preference(LinearSolve, pref_key)
89+
Preferences.delete_preferences!(LinearSolve, pref_key; force = true)
90+
@info "Cleared preference: $pref_key"
7091
end
7192
end
7293

73-
Preferences.delete_preferences!(LinearSolve, "autotune_timestamp"; force = true)
94+
# Clear timestamp
95+
if Preferences.has_preference(LinearSolve, "autotune_timestamp")
96+
Preferences.delete_preferences!(LinearSolve, "autotune_timestamp"; force = true)
97+
end
7498

7599
@info "Preferences cleared from LinearSolve.jl."
76100
end

0 commit comments

Comments
 (0)