Materials-simulation-skills nonlinear-solvers
install
source · Clone the upstream repo
git clone https://github.com/HeshamFS/materials-simulation-skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HeshamFS/materials-simulation-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/core-numerical/nonlinear-solvers" ~/.claude/skills/heshamfs-materials-simulation-skills-nonlinear-solvers && rm -rf "$T"
manifest:
skills/core-numerical/nonlinear-solvers/SKILL.mdsource content
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.8+
- NumPy (for Jacobian diagnostics)
- SciPy (optional, for advanced analysis)
Inputs to Gather
| 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 | |
Decision Guidance
Solver Selection Flowchart
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
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 |
|---|---|
| , , |
| , , , |
| , , |
| , , , |
| , , |
| , , , |
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:
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:
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
# Select solver for large unconstrained optimization python3 scripts/solver_selector.py --size 50000 --smooth --memory-limited --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 # 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 Handling
| Error | Cause | Resolution |
|---|---|---|
| Invalid size | Check problem dimension |
| Unknown constraint | Use: none, bound, equality, inequality |
| Invalid residual data | Check residual computation |
| Invalid path | Verify Jacobian file exists |
Interpretation Guidance
Convergence Type
| Type | Meaning | Action |
|---|---|---|
| quadratic | Optimal Newton | Continue, near solution |
| superlinear | Quasi-Newton working | Monitor for stagnation |
| linear | Acceptable | May improve with preconditioner |
| sublinear | Too slow | 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 |
Security
Input Validation
(problem size) is validated as a positive integer, bounded at 10 billion--size
are validated as finite non-negative numbers, capped at 100,000 entries--residuals
and--tolerance
are validated as finite positive numbers--target-tolerance
and--problem-type
are validated against fixed allowlists--constraint-type
is validated against a fixed allowlist (--jacobian-quality
,good
, etc.)ill-conditioned- Step quality parameters (
,predicted-reduction
,actual-reduction
,step-norm
,gradient-norm
) are validated as finite numberstrust-radius
File Access
reads a single matrix file specified byjacobian_diagnostics.py
; no directory traversal beyond the given path--matrix- Matrix files are size-limited and loaded with
to prevent code executionallow_pickle=False - All other scripts read no external files; inputs are provided via CLI arguments
- Scripts write only to stdout (JSON output)
Tool Restrictions
- Read: Used to inspect script source, references, and user configuration files
- Bash: Used to execute the six Python analysis scripts (
,solver_selector.py
,convergence_analyzer.py
,jacobian_diagnostics.py
,globalization_advisor.py
,residual_monitor.py
) with explicit argument listsstep_quality.py - Write: Used to save analysis results or solver recommendations; writes are scoped to the user's working directory
- Grep/Glob: Used to locate relevant files and search references
Safety Measures
- No
,eval()
, or dynamic code generationexec() - All subprocess calls use explicit argument lists (no
)shell=True - Matrix dimension limits prevent memory exhaustion when loading Jacobian files
- Residual history analysis operates on bounded-length numeric arrays only
Limitations
- No global convergence guarantee: All methods may fail for pathological problems
- Jacobian accuracy: Finite-difference Jacobian may be inaccurate near discontinuities
- Large dense problems: May require specialized solvers not covered here
- Constrained optimization: Complex constraints need SQP or interior point methods
References
- Problem-based solver selectionreferences/solver_decision_tree.md
- Method details and parametersreferences/method_catalog.md
- Diagnosing convergence issuesreferences/convergence_diagnostics.md
- Line search and trust regionreferences/globalization_strategies.md
Version History
- v1.0.0 : Initial release with 6 analysis scripts