heshamfs/materials-simulation-skills/nonlinear-solvers
Claude Code and agent skill by heshamfs/materials-simulation-skills
- community
Checking that the SKILL.md file is still in the repository.
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."
Install
npx vskill@latest install heshamfs/materials-simulation-skills/nonlinear-solversSKILL.md
Nonlinear Solvers
Goal
Provide a universal workflow to select a nonlinear solver, configure globalization strategies, and diagnose convergence for root-finding, optimization, and least-squares problems.
Requirements
- Python 3.10+
- NumPy (for Jacobian diagnostics)
- SciPy (optional, for advanced analysis)
Inputs to Gather
| Input | Description | Example | |
|---|---|---|---|
| Problem type | Root-finding, optimization, least-squares | root-finding | |
| Problem size | Number of unknowns | n = 10000 | |
| Jacobian availability | Analytic, finite-diff, unavailable | analytic | |
| Jacobian cost | Cheap or expensive to compute | expensive | |
| Constraints | None, bounds, equality, inequality | none | |
| Smoothness | Is objective/residual smooth? | yes | |
| Residual history | Sequence of residual norms | 1,0.1,0.01,... |
Decision Guidance
Solver Selection Flowchart
Quick Reference
| 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 Outputs (JSON Fields)
| Script | Key Outputs | |
|---|---|---|
scripts/solver_selector.py | recommended, alternatives, notes | |
scripts/convergence_analyzer.py | converged, convergence_type, estimated_rate, diagnosis | |
scripts/jacobian_diagnostics.py | condition_number, jacobian_quality, rank_deficient | |
scripts/globalization_advisor.py | strategy, line_search_type, trust_region_type, parameters | |
scripts/residual_monitor.py | patterns_detected, alerts, recommendations | |
scripts/step_quality.py | ratio, step_quality, accept_step, trust_radius_action |
Workflow
- Characterize problem - Identify type, size, Jacobian availability
- Select solver - Run
scripts/solver_selector.py - Choose globalization - Run
scripts/globalization_advisor.py - Analyze Jacobian - If available, run
scripts/jacobian_diagnostics.py - Monitor residuals - During solve, use
scripts/residual_monitor.py - Analyze convergence - Run
scripts/convergence_analyzer.py - Evaluate steps - For trust region, use
scripts/step_quality.py
Conversational Workflow Example
User: My Newton solver for a phase-field simulation is converging very slowly. After 50 iterations, the residual only dropped from 1 to 0.1.
Agent workflow:
- Analyze convergence:
``bash python3 scripts/convergence_analyzer.py --residuals 1,0.8,0.6,0.5,0.4,0.3,0.2,0.15,0.12,0.1 --json ``
- Check globalization strategy:
``bash python3 scripts/globalization_advisor.py --problem-type root-finding --jacobian-quality ill-conditioned --previous-failures 0 --json ``
- Recommend: Switch to trust region with Levenberg-Marquardt regularization, or use Newton-Krylov with better preconditioning.
Pre-Solve Checklist
- [ ] Confirm problem type (root-finding, optimization, least-squares)
- [ ] Assess Jacobian availability and cost
- [ ] Check initial guess quality
- [ ] Set appropriate tolerances
- [ ] Choose globalization strategy
- [ ] Prepare to monitor convergence
CLI Examples
Error Handling
| Error | Cause | Resolution | |
|---|---|---|---|
problem_size must be positive | Invalid size | Check problem dimension | |
problem_size (...) exceeds maximum (...) | Size above 10 billion cap | Re-check the unit/value | |
constraint_type must be one of... | Unknown constraint | Use: none, bound, equality, inequality | |
problem_type must be one of... | Unknown problem type | Use: root-finding, optimization, least-squares | |
residuals must be non-negative | Invalid residual data | Check residual computation | |
residuals must be finite | NaN/Inf in residual data | Sanitize residual history | |
residual list length (...) exceeds limit (...) | More than 100,000 entries | Downsample the history | |
Matrix file not found | Invalid path | Verify Jacobian file exists | |
Matrix file exceeds size limit ... | Matrix file too large | Use a smaller / sparser matrix |
Interpretation Guidance
Convergence Type
| 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 |
Jacobian Quality
| 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 |
Step Quality (Trust Region)
| 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 |
Verification checklist
Do not trust a "solved" claim until these concrete artifacts are recorded:
- [ ] Logged the full residual norm history and ran
convergence_analyzer.py --residuals <history>; recordedconvergence_typeandestimated_rate, and confirmedconverged: trueagainst the actual solver tolerance (not the default1e-10). - [ ] Confirmed the residual sequence is monotone-decreasing or fed it to
residual_monitor.py; recordedpatterns_detectedand verified it does NOT includediverging,oscillating,plateau, orslow_convergencewhile still above tolerance. - [ ] If a Jacobian is available, ran
jacobian_diagnostics.py --matrix J.txtand recordedcondition_numberandjacobian_quality; for an analytic Jacobian, passed--finite-diff-matrixand confirmedfinite_diff_erroris below ~1e-2 (no "Large discrepancy" note). - [ ] Checked
rank_deficientfromjacobian_diagnostics.pyisfalse(or documented why a rank-deficient/near-singular Jacobian is expected and that Levenberg-Marquardt regularization is in use). - [ ] For a trust-region solve, evaluated accepted steps with
step_quality.pyand recorded the reductionratio; confirmed accepted steps haveratio >= 0.25(notvery_poor/poor) and that thetrust_radius_actionmatches the recorded ρ. - [ ] Recorded the solver and globalization actually used and confirmed they match
solver_selector.pyandglobalization_advisor.pyrecommendations for the stated problem type, size, and Jacobian quality (e.g., large/expensive-Jacobian → Newton-Krylov; least-squares → Levenberg-Marquardt trust region). - [ ] Re-confirmed convergence after any change to tolerance, initial guess, or preconditioner — the convergence type can flip (e.g., quadratic → linear/stagnated) and must be re-classified, not assumed.
Common pitfalls & rationalizations
| 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 — convergence_analyzer.py reports this as linear (annotated "fast linear"). Superlinear requires the ratio to tend to zero (order p > 1.2). Don't claim Newton-quality convergence from a flat ratio. | |
| "It stopped without erroring, so the solver converged." | Run completion is not convergence. Check converged from convergence_analyzer.py/residual_monitor.py against the real tolerance; a stagnated or plateau result also "stops" but has not solved f(x)=0. | |
| "Two iterations look like they're shrinking, so the rate is fine." | Order estimation needs at least 3 strictly decreasing positive residuals; with fewer, convergence_analyzer.py returns unknown/falls back to rate-only. Gather more iterations before quoting a convergence type. | |
| "I coded the analytic Jacobian, so it must be right." | A wrong Jacobian still produces some step. Run jacobian_diagnostics.py --finite-diff-matrix and confirm finite_diff_error is small; a "Large discrepancy with finite-diff" note means the analytic Jacobian is buggy, which silently degrades Newton to linear convergence. | |
| "Newton diverged, so I'll just shrink the global tolerance and call it close enough." | Divergence (convergence_type: diverged, or diverging pattern) signals a bad step direction or far-from-solution start — add globalization. Run globalization_advisor.py (use --far-from-solution / report failures) and switch to a trust region or damped step instead of loosening the target. | |
| "Trust-region step decreased the objective, so accept and expand the radius." | Acceptance and radius growth depend on the reduction ratio ρ, not just sign. step_quality.py only flags expand when ρ ≥ 0.75 and the step hit the boundary; a small positive ρ (marginal) means accept-but-shrink. Use the recorded trust_radius_action. | |
| "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, solver_selector.py routes to matrix-free Newton-Krylov (JFNK) precisely because forming/factoring J is infeasible; use Jacobian-vector products plus a preconditioner instead. |
Security
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 98 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/core-numerical/nonlinear-solvers/SKILL.md
Popularity
- Repository stars
- 40
- Repository forks
- 3
- 7-day trend score
- 19
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/heshamfs/materials-simulation-skills/nonlinear-solvers)