How patrick-kidger/optimistix works
1. What this repository is
- Optimistix is a JAX-based nonlinear solving library. Its main purpose is to expose a small set of high-level solve APIs for root finding, minimisation, least squares, and fixed points.
- The package is structured as a reusable solver framework rather than a single algorithm implementation.
2. Public API layer
- The top-level optimistix/__init__.py is the user-facing entry point.
- Core API modules map directly to problem types: _root_find.py, _minimise.py, _least_squares.py, and _fixed_point.py.
- This is the boundary where users pass JAX functions, initial guesses, tolerances, and solver objects, and receive a structured solution object back.
3. Problem orchestration vs algorithm execution
- The library separates problem orchestration from numerical methods.
- Orchestration code decides how to interpret the problem, how to iterate, when to stop, and how to package results.
- Actual step computations are delegated to solver implementations under optimistix/_solver.
4. Solver plugin layer
- optimistix/_solver/ contains the algorithm modules: Newton-style methods, quasi-Newton, BFGS/L-BFGS, conjugate gradient variants, Nelder–Mead, golden search, bisection, trust-region methods, dogleg, Gauss–Newton, Levenberg–Marquardt, and fixed-point-specific methods.
- This directory is the main algorithm library and is where modularity comes from: different problem types can share or adapt solver components.
- The presence of both derivative-based and derivative-free solvers indicates the package supports a wide spectrum of nonlinear optimization/search workflows.
5. Shared iteration and search infrastructure
- _iterate.py, _search.py, _solution.py, and _misc.py provide the common machinery used across all problem classes.
- These modules likely standardize iteration state, termination logic, candidate evaluation, and result reporting.
- _custom_types.py centralizes shared type definitions for JAX/PyTree-friendly APIs.
6. Autodiff and implicit differentiation boundary
- _ad.py and _adjoint.py represent the differentiation layer.
- This is an important architectural boundary because Optimistix is designed to work naturally with JAX transformations, including gradients through solver calls.
- In practice, this layer connects iterative solves to JAX autodiff so solutions can be differentiated through or used in larger differentiable programs.
7. Compatibility and interoperability
- compat/ provides a compatibility layer, with _impl.py as the main implementation.
- README explicitly calls out interoperability with Optax, so this layer likely smooths integration with external optimizer-style interfaces and older or alternate calling conventions.
- This helps Optimistix act both as a native solver library and as a bridge to adjacent JAX ecosystem tools.
8. State and data model
- The repository emphasizes use of PyTrees for solver state and problem data.
- That matters architecturally because it keeps everything compatible with JAX transformations like jit, vmap, and autodiff.
- Solutions are not just scalar outputs; the solution module indicates structured outputs that capture convergence status, residuals, and final iterates.
9. Runtime and technology constraints
- The project is built for Python 3.11+ and JAX.
- Its design targets compiled execution and accelerator support (CPU/GPU/TPU via JAX), which shapes how the solver core is written and why state is kept JAX-friendly.
- The emphasis on fast compilation/runtime suggests minimizing Python-side control flow in the hot path.
10. Tests as architecture validation
- tests/ contains focused tests per subsystem: autodiff, root finding, least squares, minimisation, fixed point, compatibility, best-so-far tracking, and specific solver behavior.
- This indicates the architecture is organized around stable public behaviors and solver contracts, not just numerical correctness in isolation.
- tests/helpers.py and tests/conftest.py likely support reusable solver fixtures and problem setups.
11. Benchmarks as performance gate
- benchmarks/ contains algorithm-focused performance comparisons such as Levenberg–Marquardt and vectorized/unrolled variants.
- This shows performance is a first-class concern and that solver selection is expected to affect compile time and runtime materially.
12. Docs and examples as the primary integration surface
- docs/ is extensive and includes API pages, FAQs, selection guides, and runnable notebook examples.
- The docs reflect the main conceptual boundaries: choose a problem type, choose a solver, understand solver/search interaction, then consume a solution object.
- The examples show end-to-end flows for root finding, ODE implicit steps, interactive use, and custom solvers.
13. Project lifecycle and delivery
- GitHub Actions workflows cover tests, docs building, and release.
- This suggests the package is maintained as a distributable library with CI enforcing solver correctness and documentation quality before publishing.
14. How to draw the architecture
- A good diagram would center on a public API layer feeding into problem-specific orchestration, which then drives a shared iteration/search engine, which in turn delegates to interchangeable solver implementations.
- Side branches should show the autodiff/adjoint integration, the compatibility layer, and the docs/tests/benchmarks as supporting subsystems around the core numerical engine.
Main entry points: _minimise.py Minimise · __init__.py Solvers · _root_find.py Root find · _least_squares.py Least squares
Components 25
Public API
User-facing solve entrypoints and solution surface
- optimistix · Top-level package exports for users
optimistix/__init__.py - Root find · Root-finding entrypoint and orchestration
optimistix/_root_find.py - Minimise · Minimisation entrypoint and orchestration
optimistix/_minimise.py - Least squares · Least-squares entrypoint and orchestration
optimistix/_least_squares.py - Fixed point · Fixed-point entrypoint and orchestration
optimistix/_fixed_point.py
Core Engine
Shared orchestration, iteration, and result handling
- Iterate · Shared iteration loop and stopping logic
optimistix/_iterate.py - Search · Shared search and candidate-evaluation machinery
optimistix/_search.py - Solution · Structured solver outputs and termination state
optimistix/_solution.py - Types · Shared JAX-friendly type definitions
optimistix/_custom_types.py - Misc · Common helpers used across solve paths
optimistix/_misc.py
Solver Plugins
Interchangeable numerical methods used by problem orchestration
- Solvers · Namespace and exports for interchangeable solver implementations
optimistix/_solver/__init__.py - Newton · Newton-style and chord methods
optimistix/_solver/newton_chord.py - Bisection · Bracketed root-finding method
optimistix/_solver/bisection.py - Quasi-Newton · Quasi-Newton update strategies
optimistix/_solver/quasi_newton.py - Gradient · Gradient-based descent variants
optimistix/_solver/gradient_methods.py - Nonlinear CG · Conjugate-gradient style nonlinear methods
optimistix/_solver/nonlinear_cg.py - Trust region · Trust-region framework and step control
optimistix/_solver/trust_region.py - LS solvers · Gauss-Newton, Levenberg-Marquardt, dogleg, and Cauchy point
optimistix/_solver/gauss_newton.py - FP solver · Fixed-point-specific solver implementation
optimistix/_solver/fixed_point.py
Differentiation
JAX autodiff and implicit differentiation boundary
Compatibility
Adapters for external calling conventions and ecosystem interop
- Compat · Compatibility layer for alternate interfaces and Optax interop
optimistix/compat/_impl.py
Support
Docs, tests, benchmarks, and delivery tooling
- Tests · Behavioral and solver-contract validation suite
tests - Benchmarks · Runtime and compile-time comparison harnesses
benchmarks - Docs · API docs, guides, examples, and selection help
docs/index.md
Connections 48
- optimistix → Root find: exports · Top-level package exposes root finding
- optimistix → Minimise: exports · Top-level package exposes minimisation
- optimistix → Least squares: exports · Top-level package exposes least squares
- optimistix → Fixed point: exports · Top-level package exposes fixed-point solving
- Root find → Iterate: uses · Problem orchestration runs through the shared iteration engine
- Minimise → Iterate: uses · Problem orchestration runs through the shared iteration engine
- Least squares → Iterate: uses · Problem orchestration runs through the shared iteration engine
- Fixed point → Iterate: uses · Problem orchestration runs through the shared iteration engine
- Root find → Search: uses · Root finding relies on shared search/evaluation machinery
- Minimise → Search: uses · Minimisation relies on shared search/evaluation machinery
- Least squares → Search: uses · Least squares relies on shared search/evaluation machinery
- Fixed point → Search: uses · Fixed-point solving relies on shared search/evaluation machinery
- Iterate → Solution: returns · Iteration packages results into structured solution objects
- Search → Solution: returns · Search and termination logic populate solution state
- Iterate → Types: typed by · Iteration state is PyTree-friendly and JAX-compatible
- Search → Types: typed by · Candidate and state objects use shared types
- Root find → Newton: delegates · Root finding can delegate step computation to Newton-style solvers
- Root find → Bisection: delegates · Root finding can delegate to bracketing solvers
- Minimise → Quasi-Newton: delegates · Minimisation commonly delegates to quasi-Newton methods
- Minimise → Gradient: delegates · Minimisation can use gradient-based methods
- Minimise → Nonlinear CG: delegates · Minimisation can use nonlinear conjugate-gradient methods
- Minimise → Trust region: delegates · Minimisation can use trust-region methods
- Least squares → LS solvers: delegates · Least-squares orchestration delegates to dedicated solvers
- Least squares → Trust region: delegates · Least-squares methods may route through trust-region control
- Fixed point → FP solver: delegates · Fixed-point orchestration delegates to fixed-point-specific methods
- Solvers → Newton: contains · Algorithm modules are organized under the solver namespace
- Solvers → Bisection: contains · Algorithm modules are organized under the solver namespace
- Solvers → Quasi-Newton: contains · Algorithm modules are organized under the solver namespace
- Solvers → Gradient: contains · Algorithm modules are organized under the solver namespace
- Solvers → Nonlinear CG: contains · Algorithm modules are organized under the solver namespace
- Solvers → Trust region: contains · Algorithm modules are organized under the solver namespace
- Solvers → LS solvers: contains · Algorithm modules are organized under the solver namespace
- Solvers → FP solver: contains · Algorithm modules are organized under the solver namespace
- Autodiff → Adjoint: supports · Autodiff layer connects to implicit differentiation logic
- Root find → Autodiff: integrates with · Solve APIs are designed to work under JAX transformations
- Minimise → Autodiff: integrates with · Solve APIs are designed to work under JAX transformations
- Least squares → Autodiff: integrates with · Solve APIs are designed to work under JAX transformations
- Fixed point → Autodiff: integrates with · Solve APIs are designed to work under JAX transformations
- Compat → optimistix: bridges · Compatibility layer offers alternate interfaces around the core API
- Compat → Gradient: bridges · Compatibility layer supports ecosystem optimizer-style integration
- Tests → Autodiff: verifies · Test suite covers differentiation behavior
- Tests → Root find: verifies · Test suite covers root-finding behavior
- Tests → Minimise: verifies · Test suite covers minimisation behavior
- Tests → Least squares: verifies · Test suite covers least-squares behavior
- Tests → Fixed point: verifies · Test suite covers fixed-point behavior
- Tests → Compat: verifies · Test suite covers compatibility behavior
- Benchmarks → LS solvers: profiles · Benchmarks compare solver performance and compilation tradeoffs
- Benchmarks → Gradient: profiles · Benchmarks exercise algorithmic variants