Loading...
Loading...
Select and configure nonlinear solvers for root-finding f(x)=0, optimization min F(x), and least-squares problems — choose among Newton, Newton-Krylov, quasi-Newton (BFGS, L-BFGS), Broyden, Anderson acceleration, and Levenberg-Marquardt methods, configure line search or trust-region globalization, diagnose convergence rate (quadratic, linear, stagnated), and assess Jacobian quality and conditioning. Use when a Newton solver converges slowly or diverges, choosing between line search and trust region, debugging nonlinear iteration failures in FEM or phase-field codes, or selecting a solver for large-scale unconstrained optimization, even if the user only says "my Newton iterations aren't converging."
npx skill4agent add heshamfs/materials-simulation-skills nonlinear-solvers| Input | Description | Example |
|---|---|---|
| Problem type | Root-finding, optimization, least-squares | |
| Problem size | Number of unknowns | |
| Jacobian availability | Analytic, finite-diff, unavailable | |
| Jacobian cost | Cheap or expensive to compute | |
| Constraints | None, bounds, equality, inequality | |
| Smoothness | Is objective/residual smooth? | |
| Residual history | Sequence of residual norms | |
Is Jacobian available and cheap?
├── YES → Problem size?
│ ├── Small (n < 1000) → Newton (full)
│ └── Large (n ≥ 1000) → Newton-Krylov
└── NO → Is objective smooth?
├── YES → Memory limited?
│ ├── YES → L-BFGS or Broyden
│ └── NO → BFGS
└── NO → Anderson acceleration or Picard| Problem Type | First Choice | Alternative | Globalization |
|---|---|---|---|
| Small root-finding | Newton | Broyden | Line search |
| Large root-finding | Newton-Krylov | Anderson | Trust region |
| Optimization | L-BFGS | BFGS | Wolfe line search |
| Least-squares | Levenberg-Marquardt | Gauss-Newton | Trust region |
| Bound constrained | L-BFGS-B | Trust-region reflective | Projected |
| Script | Key Outputs |
|---|---|
| |
| |
| |
| |
| |
| |
scripts/solver_selector.pyscripts/globalization_advisor.pyscripts/jacobian_diagnostics.pyscripts/residual_monitor.pyscripts/convergence_analyzer.pyscripts/step_quality.pypython3 scripts/convergence_analyzer.py --residuals 1,0.8,0.6,0.5,0.4,0.3,0.2,0.15,0.12,0.1 --jsonpython3 scripts/globalization_advisor.py --problem-type root-finding --jacobian-quality ill-conditioned --previous-failures 0 --json# Select solver for large unconstrained optimization
python3 scripts/solver_selector.py --size 50000 --smooth --memory-limited --json
# Select solver for a small nonlinear least-squares (data-fitting) problem
python3 scripts/solver_selector.py --problem-type least-squares --size 6 --jacobian-available --smooth --json
# Analyze convergence from residual history
python3 scripts/convergence_analyzer.py --residuals 1,0.1,0.01,0.001,0.0001 --tolerance 1e-6 --json
# Diagnose Jacobian quality
python3 scripts/jacobian_diagnostics.py --matrix jacobian.txt --json
# Get globalization recommendation
python3 scripts/globalization_advisor.py --problem-type optimization --jacobian-quality good --json
# Globalization for a distant initial guess (favors trust region)
python3 scripts/globalization_advisor.py --problem-type root-finding --jacobian-quality good --far-from-solution --json
# Monitor residual patterns
python3 scripts/residual_monitor.py --residuals 1,0.8,0.9,0.7,0.75,0.6 --target-tolerance 1e-8 --json
# Evaluate step quality for trust region
python3 scripts/step_quality.py --predicted-reduction 0.5 --actual-reduction 0.4 --step-norm 0.8 --gradient-norm 1.0 --trust-radius 1.0 --json| Error | Cause | Resolution |
|---|---|---|
| Invalid size | Check problem dimension |
| Size above 10 billion cap | Re-check the unit/value |
| Unknown constraint | Use: none, bound, equality, inequality |
| Unknown problem type | Use: root-finding, optimization, least-squares |
| Invalid residual data | Check residual computation |
| NaN/Inf in residual data | Sanitize residual history |
| More than 100,000 entries | Downsample the history |
| Invalid path | Verify Jacobian file exists |
| Matrix file too large | Use a smaller / sparser matrix |
| Type | Meaning | Action |
|---|---|---|
| quadratic | Optimal Newton (order p ≈ 2) | Continue, near solution |
| superlinear | Ratios shrinking toward 0 (1 < p < 2); quasi-Newton working | Monitor for stagnation |
| linear | Constant contraction ratio (p ≈ 1); a small constant ratio is fast-linear, not superlinear | May improve with preconditioner |
| sublinear | Too slow (ratio → 1) | Change method or formulation |
| stagnated | No progress | Check Jacobian, preconditioner |
| diverged | Increasing residual | Add globalization, check Jacobian |
| Quality | Condition Number | Action |
|---|---|---|
| good | < 10⁶ | Standard Newton works |
| moderately-conditioned | 10⁶ - 10¹⁰ | Consider scaling |
| ill-conditioned | > 10¹⁰ | Use regularization |
| near-singular | ∞ | Reformulate or use LM |
| Ratio ρ | Quality | Trust Radius |
|---|---|---|
| ρ < 0 | very_poor | Shrink aggressively |
| ρ < 0.25 | marginal | Shrink |
| 0.25 ≤ ρ < 0.75 | good | Maintain |
| ρ ≥ 0.75 | excellent | Expand if at boundary |
convergence_analyzer.py --residuals <history>convergence_typeestimated_rateconverged: true1e-10residual_monitor.pypatterns_detecteddivergingoscillatingplateauslow_convergencejacobian_diagnostics.py --matrix J.txtcondition_numberjacobian_quality--finite-diff-matrixfinite_diff_errorrank_deficientjacobian_diagnostics.pyfalsestep_quality.pyratioratio >= 0.25very_poorpoortrust_radius_actionsolver_selector.pyglobalization_advisor.py| Tempting shortcut | Why it's wrong / what to do |
|---|---|
| "The residual ratio is a small constant (~0.1), so it's converging superlinearly." | A constant contraction ratio is linear, not superlinear — |
| "It stopped without erroring, so the solver converged." | Run completion is not convergence. Check |
| "Two iterations look like they're shrinking, so the rate is fine." | Order estimation needs at least 3 strictly decreasing positive residuals; with fewer, |
| "I coded the analytic Jacobian, so it must be right." | A wrong Jacobian still produces some step. Run |
| "Newton diverged, so I'll just shrink the global tolerance and call it close enough." | Divergence ( |
| "Trust-region step decreased the objective, so accept and expand the radius." | Acceptance and radius growth depend on the reduction ratio ρ, not just sign. |
| "The Jacobian is large and expensive, but full Newton is the gold standard, so I'll form it anyway." | For n ≥ 1000 or expensive Jacobians, |
--size--residuals--tolerance--target-tolerance--problem-type--constraint-type--jacobian-qualitygoodill-conditionedpredicted-reductionactual-reductionstep-normgradient-normtrust-radiusjacobian_diagnostics.py--matrixallow_pickle=Falsesolver_selector.pyconvergence_analyzer.pyjacobian_diagnostics.pyglobalization_advisor.pyresidual_monitor.pystep_quality.pyeval()exec()shell=Truereferences/solver_decision_tree.mdreferences/method_catalog.mdreferences/convergence_diagnostics.mdreferences/globalization_strategies.md--problem-typesolver_selector.py--far-from-solutionglobalization_advisor.py-Infinity