Advanced User Tutorials¶
These tutorials are for developers and scientists who want to leverage NLSQ’s full API capabilities: custom optimization pipelines, protocol-based design, performance tuning, and extending the library.
Note
Prerequisites: Complete the Routine User Tutorials first. Understanding the 3-workflow system is essential before diving into the API layer.
Who This Guide Is For¶
Developers building custom optimization workflows
Scientists with specialized fitting requirements
Researchers extending NLSQ for new algorithms
Power users wanting maximum control
What You’ll Learn¶
NLSQ’s internal architecture and design patterns
How to use core API classes directly
Factory functions and dependency injection
The v0.6.4 orchestration component system
Performance tuning and profiling
Creating custom optimizers and extensions
Learning Path¶
# |
Chapter |
What You’ll Learn |
Time |
|---|---|---|---|
1 |
Package structure, optimization pipeline, JAX patterns |
30 min |
|
2 |
CurveFit, LeastSquares, TRF classes |
45 min |
|
3 |
Factory functions, protocols, dependency injection |
30 min |
|
4 |
v0.6.4 decomposed components |
45 min |
|
5 |
Build your own optimization pipelines |
45 min |
|
6 |
JIT caching, memory management, profiling |
30 min |
|
7 |
Numerical guards, SVD fallback, recovery |
30 min |
|
8 |
Custom protocols, plugins, testing |
30 min |
Prerequisites¶
Completed routine user tutorials
Python experience (classes, decorators, type hints)
Understanding of optimization concepts
Familiarity with JAX (helpful but not required)
Quick Reference: API Levels¶
NLSQ provides multiple API levels:
High Level fit() function
│ │
│ ▼
│ CurveFit class
│ │
│ ▼
Mid Level LeastSquares class
│ │
│ ▼
Low Level TrustRegionReflective
Choose based on needs:
fit(): Simple, automatic (routine users)CurveFit: Reusable, stateful fittingLeastSquares: Direct optimizer controlTRF: Algorithm-level customization
Import Patterns¶
# High-level API
from nlsq import fit, curve_fit, CurveFit
# Core classes
from nlsq.core.least_squares import LeastSquares
from nlsq.core.trf import TrustRegionReflective
# Factories
from nlsq.core.factories import create_optimizer, configure_curve_fit
# Orchestration (v0.6.4+)
from nlsq.core.orchestration import (
DataPreprocessor,
OptimizationSelector,
CovarianceComputer,
StreamingCoordinator,
)
# Protocols
from nlsq.interfaces import (
OptimizerProtocol,
CurveFitProtocol,
CacheProtocol,
)
# Facades
from nlsq.facades import (
OptimizationFacade,
StabilityFacade,
DiagnosticsFacade,
)