Change :auto sparse heuristic to size-based threshold#158
Open
hmzh-khn wants to merge 4 commits into
Open
Conversation
Tests define expected behavior for sparse_threshold parameter: - NonlinearSolverOptions accepts sparse_threshold (default=50) - :auto mode uses M matrix size instead of graph position - Nash games (all leaves) get sparse solve for large M - Small M matrices stay on dense path with high threshold Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace graph-position-based heuristic (!is_leaf) with size-based heuristic (size(M, 1) >= sparse_threshold). This means leaf players with large M matrices now benefit from sparse factorization too. Key changes: - Add sparse_threshold::Int field to NonlinearSolverOptions (default=50) - Thread sparse_threshold through solve_raw → run_nonlinear_solver → compute_K_evals - Update _merge_options to support sparse_threshold override - Change heuristic: size(M_buf, 1) >= sparse_threshold instead of !is_leaf(graph, ii) The default threshold of 50 rows means: - 3-player chain P3 (24×24 leaf): stays dense (below threshold) - 3-player chain P2 (56×64 leader): uses sparse (above threshold) - 4-player chain all players (60-204 rows): all use sparse Co-Authored-By: Claude Opus 4.6 <[email protected]>
Results show the new :auto (threshold=50) matches :always performance: - 3-player chain: 0.33ms → 0.18ms (-45%), 1238KB → 556KB (-55%) - 4-player chain: 9.56ms → 2.27ms (-76%), 11659KB → 6648KB (-43%) The new :auto even beats :always on allocations for 3-player chain because Player 3 (24×24) stays on dense path, avoiding sparse overhead. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
hmzh-khn
pushed a commit
that referenced
this pull request
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the graph-position-based
:autosparse heuristic (!is_leaf) with a size-based heuristic (size(M, 1) >= sparse_threshold). This means leaf players with large M matrices now benefit from sparse LU factorization, dramatically improving performance for medium-to-large problems.Changes
src/types.jl: Addsparse_threshold::Intfield toNonlinearSolverOptions(default=50), thread throughNonlinearSolverconstructorsrc/nonlinear_kkt.jl: Change heuristic from!is_leaf(graph, ii)tosize(M_buf, 1) >= sparse_thresholdincompute_K_evals; addsparse_thresholdkwarg tocompute_K_evalsandrun_nonlinear_solversrc/solve.jl: Addsparse_thresholdto_merge_options,solve, andsolve_rawtest/test_sparse_threshold.jl: 14 new tests covering options, heuristic behavior, Nash games, and integrationtest/test_tiers.jl,test/test_test_tiers.jl: Register new test filescripts/benchmark_sparse_threshold.jl: Benchmark comparing :never, new :auto, and :alwaysRETROSPECTIVES.md: PR retrospectiveBenchmark Results
New
:automatches:alwaysfor large matrices and beats it on allocations for the 3-player chain because Player 3 (24×24) stays on the faster dense path.Testing
julia --project=. -e 'using Pkg; Pkg.test()')Changelog
🤖 Generated with Claude Code