# patrick-kidger/optimistix architecture

> Architecture diagram of the GitHub repository patrick-kidger/optimistix, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/patrick-kidger/optimistix
- Repository: https://github.com/patrick-kidger/optimistix

## Overview

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: [`optimistix/_minimise.py`](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_minimise.py) (Minimise), [`optimistix/_solver/__init__.py`](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/__init__.py) (Solvers), [`optimistix/_root_find.py`](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_root_find.py) (Root find), [`optimistix/_least_squares.py`](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_least_squares.py) (Least squares)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_public["Public API"]
  node_optimistix_init["optimistix<br/>public API<br/>[__init__.py]"]
  node_root_find["Root find<br/>solve API<br/>[_root_find.py]"]
  node_minimise["Minimise<br/>solve API<br/>[_minimise.py]"]
  node_least_squares["Least squares<br/>solve API<br/>[_least_squares.py]"]
  node_fixed_point["Fixed point<br/>solve API<br/>[_fixed_point.py]"]
end

subgraph group_group_core["Core Engine"]
  node_iterate["Iterate<br/>engine<br/>[_iterate.py]"]
  node_search["Search<br/>engine<br/>[_search.py]"]
  node_solution["Solution<br/>result model<br/>[_solution.py]"]
  node_custom_types["Types<br/>pytrees<br/>[_custom_types.py]"]
  node_misc["Misc<br/>shared utils<br/>[_misc.py]"]
end

subgraph group_group_solvers["Solver Plugins"]
  node_solver_pkg["Solvers<br/>registry<br/>[__init__.py]"]
  node_newton_chord["Newton<br/>solver<br/>[newton_chord.py]"]
  node_bisection["Bisection<br/>solver<br/>[bisection.py]"]
  node_quasi_newton["Quasi-Newton<br/>solver<br/>[quasi_newton.py]"]
  node_gradient_methods["Gradient<br/>solver"]
  node_nonlinear_cg["Nonlinear CG<br/>solver<br/>[nonlinear_cg.py]"]
  node_trust_region["Trust region<br/>solver<br/>[trust_region.py]"]
  node_least_squares_solvers["LS solvers<br/>solver suite<br/>[gauss_newton.py]"]
  node_fixed_point_solver["FP solver<br/>[fixed_point.py]"]
end

subgraph group_group_diff["Differentiation"]
  node_ad["Autodiff<br/>diff layer<br/>[_ad.py]"]
  node_adjoint["Adjoint<br/>implicit diff<br/>[_adjoint.py]"]
end

subgraph group_group_compat["Compatibility"]
  node_compat["Compat<br/>adapter<br/>[_impl.py]"]
end

subgraph group_group_support["Support"]
  node_tests["Tests<br/>validation"]
  node_benchmarks["Benchmarks<br/>performance"]
  node_docs["Docs<br/>documentation<br/>[index.md]"]
end

node_optimistix_init -->|"exports"| node_root_find
node_optimistix_init -->|"exports"| node_minimise
node_optimistix_init -->|"exports"| node_least_squares
node_optimistix_init -->|"exports"| node_fixed_point
node_root_find -->|"uses"| node_iterate
node_minimise -->|"uses"| node_iterate
node_least_squares -->|"uses"| node_iterate
node_fixed_point -->|"uses"| node_iterate
node_root_find -->|"uses"| node_search
node_minimise -->|"uses"| node_search
node_least_squares -->|"uses"| node_search
node_fixed_point -->|"uses"| node_search
node_iterate -->|"returns"| node_solution
node_search -->|"returns"| node_solution
node_iterate -->|"typed by"| node_custom_types
node_search -->|"typed by"| node_custom_types
node_root_find -->|"delegates"| node_newton_chord
node_root_find -->|"delegates"| node_bisection
node_minimise -->|"delegates"| node_quasi_newton
node_minimise -->|"delegates"| node_gradient_methods
node_minimise -->|"delegates"| node_nonlinear_cg
node_minimise -->|"delegates"| node_trust_region
node_least_squares -->|"delegates"| node_least_squares_solvers
node_least_squares -->|"delegates"| node_trust_region
node_fixed_point -->|"delegates"| node_fixed_point_solver
node_solver_pkg -->|"contains"| node_newton_chord
node_solver_pkg -->|"contains"| node_bisection
node_solver_pkg -->|"contains"| node_quasi_newton
node_solver_pkg -->|"contains"| node_gradient_methods
node_solver_pkg -->|"contains"| node_nonlinear_cg
node_solver_pkg -->|"contains"| node_trust_region
node_solver_pkg -->|"contains"| node_least_squares_solvers
node_solver_pkg -->|"contains"| node_fixed_point_solver
node_ad -->|"supports"| node_adjoint
node_root_find -->|"integrates with"| node_ad
node_minimise -->|"integrates with"| node_ad
node_least_squares -->|"integrates with"| node_ad
node_fixed_point -->|"integrates with"| node_ad
node_compat -->|"bridges"| node_optimistix_init
node_compat -->|"bridges"| node_gradient_methods
node_tests -->|"verifies"| node_ad
node_tests -->|"verifies"| node_root_find
node_tests -->|"verifies"| node_minimise
node_tests -->|"verifies"| node_least_squares
node_tests -->|"verifies"| node_fixed_point
node_tests -->|"verifies"| node_compat
node_benchmarks -->|"profiles"| node_least_squares_solvers
node_benchmarks -->|"profiles"| node_gradient_methods

click node_optimistix_init "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/__init__.py"
click node_root_find "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_root_find.py"
click node_minimise "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_minimise.py"
click node_least_squares "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_least_squares.py"
click node_fixed_point "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_fixed_point.py"
click node_iterate "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_iterate.py"
click node_search "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_search.py"
click node_solution "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solution.py"
click node_custom_types "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_custom_types.py"
click node_misc "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_misc.py"
click node_solver_pkg "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/__init__.py"
click node_newton_chord "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/newton_chord.py"
click node_bisection "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/bisection.py"
click node_quasi_newton "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/quasi_newton.py"
click node_gradient_methods "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/gradient_methods.py"
click node_nonlinear_cg "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/nonlinear_cg.py"
click node_trust_region "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/trust_region.py"
click node_least_squares_solvers "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/gauss_newton.py"
click node_fixed_point_solver "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/fixed_point.py"
click node_ad "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_ad.py"
click node_adjoint "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_adjoint.py"
click node_compat "https://github.com/patrick-kidger/optimistix/blob/main/optimistix/compat/_impl.py"
click node_tests "https://github.com/patrick-kidger/optimistix/tree/main/tests"
click node_benchmarks "https://github.com/patrick-kidger/optimistix/tree/main/benchmarks"
click node_docs "https://github.com/patrick-kidger/optimistix/blob/main/docs/index.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_optimistix_init,node_root_find,node_minimise,node_least_squares,node_fixed_point toneBlue
class node_iterate,node_search,node_solution,node_custom_types,node_misc toneAmber
class node_solver_pkg,node_newton_chord,node_bisection,node_quasi_newton,node_gradient_methods,node_nonlinear_cg,node_trust_region,node_least_squares_solvers,node_fixed_point_solver toneMint
class node_ad,node_adjoint toneRose
class node_compat toneIndigo
class node_tests,node_benchmarks,node_docs toneTeal
```

## Components

### Public API

User-facing solve entrypoints and solution surface

- [optimistix](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/__init__.py): public API · Top-level package exports for users · `optimistix/__init__.py`
- [Root find](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_root_find.py): solve API · Root-finding entrypoint and orchestration · `optimistix/_root_find.py`
- [Minimise](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_minimise.py): solve API · Minimisation entrypoint and orchestration · `optimistix/_minimise.py`
- [Least squares](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_least_squares.py): solve API · Least-squares entrypoint and orchestration · `optimistix/_least_squares.py`
- [Fixed point](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_fixed_point.py): solve API · Fixed-point entrypoint and orchestration · `optimistix/_fixed_point.py`

### Core Engine

Shared orchestration, iteration, and result handling

- [Iterate](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_iterate.py): engine · Shared iteration loop and stopping logic · `optimistix/_iterate.py`
- [Search](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_search.py): engine · Shared search and candidate-evaluation machinery · `optimistix/_search.py`
- [Solution](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solution.py): result model · Structured solver outputs and termination state · `optimistix/_solution.py`
- [Types](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_custom_types.py): pytrees · Shared JAX-friendly type definitions · `optimistix/_custom_types.py`
- [Misc](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_misc.py): shared utils · Common helpers used across solve paths · `optimistix/_misc.py`

### Solver Plugins

Interchangeable numerical methods used by problem orchestration

- [Solvers](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/__init__.py): registry · Namespace and exports for interchangeable solver implementations · `optimistix/_solver/__init__.py`
- [Newton](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/newton_chord.py): solver · Newton-style and chord methods · `optimistix/_solver/newton_chord.py`
- [Bisection](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/bisection.py): solver · Bracketed root-finding method · `optimistix/_solver/bisection.py`
- [Quasi-Newton](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/quasi_newton.py): solver · Quasi-Newton update strategies · `optimistix/_solver/quasi_newton.py`
- [Gradient](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/gradient_methods.py): solver · Gradient-based descent variants · `optimistix/_solver/gradient_methods.py`
- [Nonlinear CG](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/nonlinear_cg.py): solver · Conjugate-gradient style nonlinear methods · `optimistix/_solver/nonlinear_cg.py`
- [Trust region](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/trust_region.py): solver · Trust-region framework and step control · `optimistix/_solver/trust_region.py`
- [LS solvers](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/gauss_newton.py): solver suite · Gauss-Newton, Levenberg-Marquardt, dogleg, and Cauchy point · `optimistix/_solver/gauss_newton.py`
- [FP solver](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_solver/fixed_point.py): solver · Fixed-point-specific solver implementation · `optimistix/_solver/fixed_point.py`

### Differentiation

JAX autodiff and implicit differentiation boundary

- [Autodiff](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_ad.py): diff layer · JAX transformation integration for solver calls · `optimistix/_ad.py`
- [Adjoint](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/_adjoint.py): implicit diff · Implicit differentiation and adjoint solve plumbing · `optimistix/_adjoint.py`

### Compatibility

Adapters for external calling conventions and ecosystem interop

- [Compat](https://github.com/patrick-kidger/optimistix/blob/main/optimistix/compat/_impl.py): adapter · Compatibility layer for alternate interfaces and Optax interop · `optimistix/compat/_impl.py`

### Support

Docs, tests, benchmarks, and delivery tooling

- [Tests](https://github.com/patrick-kidger/optimistix/tree/main/tests): validation · Behavioral and solver-contract validation suite · `tests`
- [Benchmarks](https://github.com/patrick-kidger/optimistix/tree/main/benchmarks): performance · Runtime and compile-time comparison harnesses · `benchmarks`
- [Docs](https://github.com/patrick-kidger/optimistix/blob/main/docs/index.md): documentation · API docs, guides, examples, and selection help · `docs/index.md`

## Connections

- 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
