Loading...
Loading...
Select and configure linear solvers for Ax=b systems arising in numerical simulations — choose between direct (LU, Cholesky) and iterative (CG, GMRES, BiCGSTAB, MINRES) methods, analyze sparsity patterns and matrix conditioning, recommend preconditioners (AMG, ILU, IC), apply row/column scaling, and diagnose convergence stagnation from residual histories. Use when setting up a linear solve for FEM/FVM assembly, debugging slow or stalled Krylov iterations, choosing a preconditioner for SPD or nonsymmetric systems, or investigating ill-conditioning, even if the user only says "my solver is slow" or "GMRES won't converge."
npx skill4agent add heshamfs/materials-simulation-skills linear-solvers| Input | Description | Example |
|---|---|---|
| Matrix size | Dimension of system | |
| Sparsity | Fraction of nonzeros | |
| Symmetry | Is A = Aᵀ? | |
| Definiteness | Is A positive definite? | |
| Conditioning | Estimated condition number | |
Is matrix dense and small enough to factor in memory (dense float64
storage n²·8 bytes < ~2 GB, i.e. n ≲ 16000)?
├── YES → Use direct solver (Cholesky/LDLᵀ/LU by symmetry)
└── NO → Is matrix symmetric?
├── YES → Is it positive definite?
│ ├── YES → Use CG with AMG/IC preconditioner
│ └── NO → Use MINRES
└── NO → Is it nearly symmetric?
├── YES → Use BiCGSTAB
└── NO → Use GMRES with ILU/AMG| Matrix Type | Solver | Preconditioner |
|---|---|---|
| SPD, sparse | CG | AMG, IC |
| Symmetric indefinite | MINRES | SPD preconditioner (SSOR, symmetric block-diagonal, or AMG on SPD part) |
| Nonsymmetric | GMRES, BiCGSTAB | ILU, AMG |
| Dense | LU, Cholesky | None |
| Saddle point | Schur complement, Uzawa | Block preconditioner |
| Script | Key Outputs |
|---|---|
| |
| |
| |
| |
| |
| |
scripts/sparsity_stats.pyscripts/solver_selector.pyscripts/preconditioner_advisor.pyscripts/scaling_equilibration.pyscripts/convergence_diagnostics.pyscripts/residual_norms.pypython3 scripts/convergence_diagnostics.py --residuals 1,0.1,0.01,0.005,0.003,0.002,0.002,0.002 --jsonpython3 scripts/preconditioner_advisor.py --matrix-type nonsymmetric --sparse --ill-conditioned --json# Analyze sparsity pattern
python3 scripts/sparsity_stats.py --matrix A.npy --json
# Select solver for SPD sparse system
python3 scripts/solver_selector.py --symmetric --positive-definite --sparse --size 1000000 --json
# Get preconditioner recommendation
python3 scripts/preconditioner_advisor.py --matrix-type spd --sparse --json
# Diagnose convergence from residual history
python3 scripts/convergence_diagnostics.py --residuals 1,0.2,0.05,0.01 --json
# Apply scaling
python3 scripts/scaling_equilibration.py --matrix A.npy --symmetric --json
# Compute residual norms
python3 scripts/residual_norms.py --residual 1,0.1,0.01 --rhs 1,0,0 --json| Error | Cause | Resolution |
|---|---|---|
| Invalid path | Check file exists |
| Non-square input | Verify matrix dimensions |
| Invalid residual data | Check input format |
convergence_diagnostics.pyrateasymptotic_ratestagnationasymptotic_rateasymptotic_rate| Asymptotic rate | Meaning | Action |
|---|---|---|
| < 0.1 | Excellent | Current setup optimal |
| 0.1 - 0.5 | Good | Acceptable for most problems |
| 0.5 - 0.95 | Slow | Consider better preconditioner |
| > 0.95 | Stagnation | Change solver or preconditioner |
| Pattern | Likely Cause | Fix |
|---|---|---|
| Flat residual | Poor preconditioner | Improve preconditioner |
| Oscillating | Near-singular or indefinite | Check matrix, try different solver |
| Very slow decay | Ill-conditioned | Apply scaling, use AMG |
asymptotic_rateconvergence_diagnostics.pyrateresidual_norms.py--rel-tol--require-bothrhssolver_selector.pyrecommendedsparsity_stats.pysymmetryscaling_equilibration.pyrow_scale_max/row_scale_mincol_scale_max/col_scale_min--symmetricsparsity_stats.pynoteszero_rowszero_colsscaling_equilibration.pypreconditioner_advisor.py| Tempting shortcut | Why it's wrong / what to do |
|---|---|
"The mean | |
| "The absolute residual is tiny, so we're done." | A small absolute norm can be meaningless if the RHS is large or unscaled. Check the |
| "It's symmetric, so just use CG." | CG requires symmetric AND positive-definite. A symmetric-indefinite matrix needs MINRES (with an SPD preconditioner); using CG can break down or stall. Confirm definiteness before selecting. |
| "Large system, so factor it directly." | |
| "Scaling is just dividing each row by its max." | One-sided row scaling does not equilibrate. For nonsymmetric matrices derive |
| "GMRES stagnates, so add more iterations." | A flat tail means the preconditioner or restart length is the problem, not iteration count. Strengthen the preconditioner (higher ILU fill / AMG), increase the restart parameter, or switch methods. |
solver_selector.py--size--matrix-typespdsymmetric-indefinitenonsymmetric--symmetric--positive-definite--sparse--ill-conditionedsparsity_stats.pyscaling_equilibration.py.npy--matrixnp.load()allow_pickle=False.npyallowed-toolsBasheval()exec()shell=Truereferences/solver_decision_tree.mdreferences/preconditioner_catalog.mdreferences/convergence_patterns.mdreferences/scaling_guidelines.md