Tutorials

Learn curve fitting with NLSQ through comprehensive, hands-on tutorials organized for two types of users:

  • Routine Users: Use the 3-workflow system (auto, auto_global, hpc) via fit()

  • Advanced Users: Design custom workflows using NLSQ’s API layer

Note

Coming from SciPy? Check out Migration Guide for a quick migration guide.

Choose Your Path

Routine User Tutorials

Learn the 3-workflow system for standard curve fitting tasks. Covers fit(), GUI, GPU acceleration, and troubleshooting.

~2.5 hours | Beginner-friendly

Routine User Tutorials
Advanced User Tutorials

Design custom optimization pipelines using NLSQ’s API layer. Covers architecture, protocols, orchestration components.

~5 hours | Requires Python experience

Advanced User Tutorials

Tutorial Sections

Additional Tutorials

The 3-Workflow System

NLSQ’s core feature is the 3-workflow system that automatically handles memory management, optimization strategy, and GPU acceleration:

Workflow

Description

Bounds

Use Case

auto

Memory-aware local optimization

Optional

Default - standard fitting

auto_global

Memory-aware global optimization

Required

Multiple minima, unknown guess

hpc

Global + checkpointing

Required

Long HPC jobs

Quick Example

from nlsq import fit
import jax.numpy as jnp


def model(x, a, b, c):
    return a * jnp.exp(-b * x) + c


# Default workflow (auto)
popt, pcov = fit(model, x, y, p0=[1.0, 0.5, 0.0])

# Global optimization
popt, pcov = fit(
    model,
    x,
    y,
    p0=[1.0, 0.5, 0.0],
    workflow="auto_global",
    bounds=([0, 0, -1], [10, 5, 1]),
)

Prerequisites

Routine Tutorials:

  • Python 3.12 or higher

  • Basic Python knowledge

  • No curve fitting experience required

Advanced Tutorials:

  • Completed routine tutorials

  • Python classes and type hints

  • Basic optimization concepts

Next Steps

After completing the tutorials: