# meco-group/fatrop architecture

> Architecture diagram of the GitHub repository meco-group/fatrop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/meco-group/fatrop
- Repository: https://github.com/meco-group/fatrop

## Overview

#### Purpose and entry points
FATROP is a C++ constrained nonlinear optimization library centered on robust interior-point methods. It supports structured optimal control problems (OCP), small dense NLPs, and block-sparse graph NLPs. Public C++ entry points are the umbrella header `include/fatrop/fatrop.hpp` and problem-specific abstractions such as `include/fatrop/ocp/ocp_abstract.hpp`, `include/fatrop/dense/nlp_dense.hpp`, and `include/fatrop/graph/nlp_graph.hpp`.

#### Build and deliverables
CMake is the primary build boundary: `CMakeLists.txt` assembles the library, while `src/CMakeLists.txt` builds its implementation and `c_interface/CMakeLists.txt` exposes a C-facing integration. A Docker build is available in `Dockerfile`. Documentation publishes through GitHub Pages via `.github/workflows/gh-pages.yml`. Core implementation is C++ with a Python CasADi code-generation package under `fatropgen/`.

#### Shared interior-point engine
The reusable solver lifecycle is defined in `include/fatrop/ip_algorithm/ip_application.hpp` and `include/fatrop/ip_algorithm/ip_algorithm.hpp`, with construction/configuration in `include/fatrop/ip_algorithm/ip_alg_builder.hpp`. It owns iterative primal-dual state, initialization, search direction computation, line search/filter acceptance, barrier updates, convergence checks, and restoration for infeasible iterates. Shared algorithm mechanics live in `src/ip_algorithm/ip_filter.cpp` and `src/ip_algorithm/ip_mu_update.cpp`; each problem family supplies specialized solver stages.

#### OCP specialization
The OCP path accepts user model/cost/constraint callbacks through `include/fatrop/ocp/ocp_abstract.hpp`. `include/fatrop/ocp/nlp_ocp.hpp` adapts staged dynamics and constraints to the NLP algorithm, while dimensions, derivatives, and Hessian structure are represented by `include/fatrop/ocp/dims.hpp`, `include/fatrop/ocp/jacobian.hpp`, and `include/fatrop/ocp/hessian.hpp`. The OCP primal-dual/KKT solve is specialized in `src/ocp/aug_system_solver.cpp` and `src/ocp/pd_system_orig.cpp`, exploiting horizon structure through Riccati-style recursion rather than a generic dense factorization.

#### Dense NLP specialization
Dense nonlinear programs use the same interior-point concepts but a full dense KKT representation. The boundary is `include/fatrop/dense/nlp_dense.hpp`; problem metadata and derivative evaluation are in `include/fatrop/dense/problem_info.hpp` and `include/fatrop/dense/jacobian.hpp`. `src/dense/aug_system_solver.cpp` and `src/dense/pd_solver_orig.cpp` implement its linear-system path. This is the appropriate branch for compact, unstructured NLPs rather than staged dynamics.

#### Graph NLP specialization
Graph NLP models block variables and sparse Hessian adjacency through `include/fatrop/graph/graph_abstract.hpp` and `include/fatrop/graph/nlp_graph.hpp`. Sparse structure is established by `include/fatrop/graph/block_sparsity.hpp` and `include/fatrop/graph/symbolic_factorization.hpp`; runtime elimination and numerical linear solution occur in `src/graph/elimination_order.cpp`, `src/graph/symbolic_factorization.cpp`, and `src/graph/linear_solver.cpp`. This branch targets SLAM/bundle-adjustment-like objectives, with block-local inequalities and no equality constraints.

#### Numerical and integration boundaries
Linear algebra types and solver contracts are centralized in `include/fatrop/linear_algebra/linear_algebra.hpp` and `include/fatrop/linear_algebra/linear_solver.hpp`, with BLASFEO integration encapsulated by `include/fatrop/linear_algebra/blasfeo_wrapper.hpp`. The C API wraps staged OCP applications at `c_interface/include/fatrop/ocp/OCPCInterface.h` and `c_interface/src/OCPCInterface.cpp`. Python users can generate/runtime-bind CasADi models through `fatropgen/fatropgen/ocp_codegen.py`, `fatropgen/fatropgen/ocp_direct_solver.py`, and the generated C++ runtime interface `fatropgen/fatropgen/casadi_utils/ocp_direct_runtime.hpp`.

Main entry points: [`include/fatrop/ip_algorithm/ip_application.hpp`](https://github.com/meco-group/fatrop/blob/main/include/fatrop/ip_algorithm/ip_application.hpp) (IP application), [`include/fatrop/ocp/nlp_ocp.hpp`](https://github.com/meco-group/fatrop/blob/main/include/fatrop/ocp/nlp_ocp.hpp) (OCP-to-NLP adapter), [`include/fatrop/linear_algebra/linear_solver.hpp`](https://github.com/meco-group/fatrop/blob/main/include/fatrop/linear_algebra/linear_solver.hpp) (Linear algebra contracts), [`include/fatrop/ip_algorithm/ip_algorithm.hpp`](https://github.com/meco-group/fatrop/blob/main/include/fatrop/ip_algorithm/ip_algorithm.hpp) (IP algorithm)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Interior-Point Core"]
  node_ip_builder["Algorithm builder<br/>configuration<br/>[ip_alg_builder.hpp]"]
  node_ip_application["IP application<br/>solver lifecycle<br/>[ip_application.hpp]"]
  node_ip_algorithm["IP algorithm<br/>algorithm contract<br/>[ip_algorithm.hpp]"]
  node_filter_barrier["Filter and barrier updates<br/>algorithm mechanics<br/>[ip_filter.cpp]"]
  node_linear_algebra["Linear algebra contracts<br/>numerical abstraction<br/>[linear_solver.hpp]"]
end

subgraph group_ocp["OCP Solver"]
  node_ocp_model["OCP model callbacks<br/>problem API<br/>[ocp_abstract.hpp]"]
  node_ocp_nlp["OCP-to-NLP adapter<br/>problem adapter<br/>[nlp_ocp.hpp]"]
  node_ocp_kkt["Riccati KKT solver<br/>structured linear solver"]
end

subgraph group_dense["Dense NLP Solver"]
  node_dense_model["Dense NLP boundary<br/>problem API<br/>[nlp_dense.hpp]"]
  node_dense_kkt["Dense KKT solver<br/>linear solver"]
end

subgraph group_graph["Graph NLP Solver"]
  node_graph_model["Graph NLP boundary<br/>problem API<br/>[nlp_graph.hpp]"]
  node_graph_structure["Sparse structure<br/>symbolic analysis"]
  node_graph_solver["Graph linear solver<br/>sparse linear solver<br/>[linear_solver.cpp]"]
end

subgraph group_integration["Integration"]
  node_public_api["Public C++ API<br/>header<br/>[fatrop.hpp]"]
  node_c_api["C OCP API<br/>C interface<br/>[OCPCInterface.h]"]
  node_python_codegen["CasADi code generation<br/>Python package<br/>[ocp_codegen.py]"]
  node_casadi_runtime["Generated OCP runtime<br/>C++ runtime interface"]
end

node_build["CMake build<br/>[CMakeLists.txt]"]

node_build -->|"packages"| node_public_api
node_build -->|"builds"| node_c_api
node_public_api -->|"exposes"| node_ip_builder
node_ip_builder -->|"constructs"| node_ip_application
node_ip_application -->|"runs"| node_ip_algorithm
node_ip_algorithm -->|"uses"| node_filter_barrier
node_ip_algorithm -->|"uses"| node_linear_algebra
node_ocp_model -->|"supplies callbacks"| node_ocp_nlp
node_ocp_nlp -->|"specializes"| node_ip_application
node_ocp_nlp -->|"forms KKT system for"| node_ocp_kkt
node_ocp_kkt -->|"implements contract"| node_linear_algebra
node_dense_model -->|"specializes"| node_ip_application
node_dense_model -->|"forms KKT system for"| node_dense_kkt
node_dense_kkt -->|"implements contract"| node_linear_algebra
node_graph_model -->|"specializes"| node_ip_application
node_graph_model -->|"defines adjacency for"| node_graph_structure
node_graph_structure -->|"drives elimination"| node_graph_solver
node_graph_solver -->|"implements contract"| node_linear_algebra
node_c_api -->|"wraps"| node_ocp_nlp
node_python_codegen -->|"generates bindings for"| node_casadi_runtime
node_casadi_runtime -->|"implements callbacks"| node_ocp_model

click node_build "https://github.com/meco-group/fatrop/blob/main/CMakeLists.txt"
click node_public_api "https://github.com/meco-group/fatrop/blob/main/include/fatrop/fatrop.hpp"
click node_ip_builder "https://github.com/meco-group/fatrop/blob/main/include/fatrop/ip_algorithm/ip_alg_builder.hpp"
click node_ip_application "https://github.com/meco-group/fatrop/blob/main/include/fatrop/ip_algorithm/ip_application.hpp"
click node_ip_algorithm "https://github.com/meco-group/fatrop/blob/main/include/fatrop/ip_algorithm/ip_algorithm.hpp"
click node_filter_barrier "https://github.com/meco-group/fatrop/blob/main/src/ip_algorithm/ip_filter.cpp"
click node_linear_algebra "https://github.com/meco-group/fatrop/blob/main/include/fatrop/linear_algebra/linear_solver.hpp"
click node_ocp_model "https://github.com/meco-group/fatrop/blob/main/include/fatrop/ocp/ocp_abstract.hpp"
click node_ocp_nlp "https://github.com/meco-group/fatrop/blob/main/include/fatrop/ocp/nlp_ocp.hpp"
click node_ocp_kkt "https://github.com/meco-group/fatrop/blob/main/src/ocp/aug_system_solver.cpp"
click node_dense_model "https://github.com/meco-group/fatrop/blob/main/include/fatrop/dense/nlp_dense.hpp"
click node_dense_kkt "https://github.com/meco-group/fatrop/blob/main/src/dense/aug_system_solver.cpp"
click node_graph_model "https://github.com/meco-group/fatrop/blob/main/include/fatrop/graph/nlp_graph.hpp"
click node_graph_structure "https://github.com/meco-group/fatrop/blob/main/include/fatrop/graph/symbolic_factorization.hpp"
click node_graph_solver "https://github.com/meco-group/fatrop/blob/main/src/graph/linear_solver.cpp"
click node_c_api "https://github.com/meco-group/fatrop/blob/main/c_interface/include/fatrop/ocp/OCPCInterface.h"
click node_python_codegen "https://github.com/meco-group/fatrop/blob/main/fatropgen/fatropgen/ocp_codegen.py"
click node_casadi_runtime "https://github.com/meco-group/fatrop/blob/main/fatropgen/fatropgen/casadi_utils/ocp_direct_runtime.hpp"

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_ip_builder,node_ip_application,node_ip_algorithm,node_filter_barrier,node_linear_algebra toneBlue
class node_ocp_model,node_ocp_nlp,node_ocp_kkt toneAmber
class node_dense_model,node_dense_kkt toneMint
class node_graph_model,node_graph_structure,node_graph_solver toneRose
class node_public_api,node_c_api,node_python_codegen,node_casadi_runtime toneIndigo
class node_build toneNeutral
```

## Components

### Interior-Point Core

Shared primal-dual solver lifecycle.

- [Algorithm builder](https://github.com/meco-group/fatrop/blob/main/include/fatrop/ip_algorithm/ip_alg_builder.hpp): configuration · Constructs and configures solver applications. · `include/fatrop/ip_algorithm/ip_alg_builder.hpp`
- [IP application](https://github.com/meco-group/fatrop/blob/main/include/fatrop/ip_algorithm/ip_application.hpp): solver lifecycle · Owns iterative primal-dual solver state. · `include/fatrop/ip_algorithm/ip_application.hpp`
- [IP algorithm](https://github.com/meco-group/fatrop/blob/main/include/fatrop/ip_algorithm/ip_algorithm.hpp): algorithm contract · `include/fatrop/ip_algorithm/ip_algorithm.hpp`
- [Filter and barrier updates](https://github.com/meco-group/fatrop/blob/main/src/ip_algorithm/ip_filter.cpp): algorithm mechanics · Line-search acceptance and barrier parameter updates. · `src/ip_algorithm/ip_filter.cpp`
- [Linear algebra contracts](https://github.com/meco-group/fatrop/blob/main/include/fatrop/linear_algebra/linear_solver.hpp): numerical abstraction · Centralizes matrix types, solver contracts, and BLASFEO wrapping. · `include/fatrop/linear_algebra/linear_solver.hpp`

### OCP Solver

Horizon-structured optimal control specialization.

- [OCP model callbacks](https://github.com/meco-group/fatrop/blob/main/include/fatrop/ocp/ocp_abstract.hpp): problem API · User staged dynamics, costs, and constraints. · `include/fatrop/ocp/ocp_abstract.hpp`
- [OCP-to-NLP adapter](https://github.com/meco-group/fatrop/blob/main/include/fatrop/ocp/nlp_ocp.hpp): problem adapter · Adapts staged OCP data to the NLP algorithm. · `include/fatrop/ocp/nlp_ocp.hpp`
- [Riccati KKT solver](https://github.com/meco-group/fatrop/blob/main/src/ocp/aug_system_solver.cpp): structured linear solver · Exploits horizon structure in the primal-dual solve. · `src/ocp/aug_system_solver.cpp`

### Dense NLP Solver

Full dense KKT specialization.

- [Dense NLP boundary](https://github.com/meco-group/fatrop/blob/main/include/fatrop/dense/nlp_dense.hpp): problem API · Boundary for compact unstructured nonlinear programs. · `include/fatrop/dense/nlp_dense.hpp`
- [Dense KKT solver](https://github.com/meco-group/fatrop/blob/main/src/dense/aug_system_solver.cpp): linear solver · Uses a full dense KKT representation. · `src/dense/aug_system_solver.cpp`

### Graph NLP Solver

Block-sparse graph optimization specialization.

- [Graph NLP boundary](https://github.com/meco-group/fatrop/blob/main/include/fatrop/graph/nlp_graph.hpp): problem API · Models block variables and sparse Hessian adjacency. · `include/fatrop/graph/nlp_graph.hpp`
- [Sparse structure](https://github.com/meco-group/fatrop/blob/main/include/fatrop/graph/symbolic_factorization.hpp): symbolic analysis · Establishes block sparsity and symbolic factorization. · `include/fatrop/graph/symbolic_factorization.hpp`
- [Graph linear solver](https://github.com/meco-group/fatrop/blob/main/src/graph/linear_solver.cpp): sparse linear solver · Performs runtime elimination and numerical solution. · `src/graph/linear_solver.cpp`

### Integration

Public, C, and Python-facing boundaries.

- [Public C++ API](https://github.com/meco-group/fatrop/blob/main/include/fatrop/fatrop.hpp): header · `include/fatrop/fatrop.hpp`
- [C OCP API](https://github.com/meco-group/fatrop/blob/main/c_interface/include/fatrop/ocp/OCPCInterface.h): C interface · Wraps staged OCP applications for C callers. · `c_interface/include/fatrop/ocp/OCPCInterface.h`
- [CasADi code generation](https://github.com/meco-group/fatrop/blob/main/fatropgen/fatropgen/ocp_codegen.py): Python package · Generates and runtime-binds CasADi OCP models. · `fatropgen/fatropgen/ocp_codegen.py`
- [Generated OCP runtime](https://github.com/meco-group/fatrop/blob/main/fatropgen/fatropgen/casadi_utils/ocp_direct_runtime.hpp): C++ runtime interface · `fatropgen/fatropgen/casadi_utils/ocp_direct_runtime.hpp`

### Other components

- [CMake build](https://github.com/meco-group/fatrop/blob/main/CMakeLists.txt): build · Builds the library and integrations. · `CMakeLists.txt`

## Connections

- CMake build → Public C++ API: packages
- CMake build → C OCP API: builds
- Public C++ API → Algorithm builder: exposes
- Algorithm builder → IP application: constructs
- IP application → IP algorithm: runs
- IP algorithm → Filter and barrier updates: uses
- IP algorithm → Linear algebra contracts: uses
- OCP model callbacks → OCP-to-NLP adapter: supplies callbacks
- OCP-to-NLP adapter → IP application: specializes
- OCP-to-NLP adapter → Riccati KKT solver: forms KKT system for
- Riccati KKT solver → Linear algebra contracts: implements contract
- Dense NLP boundary → IP application: specializes
- Dense NLP boundary → Dense KKT solver: forms KKT system for
- Dense KKT solver → Linear algebra contracts: implements contract
- Graph NLP boundary → IP application: specializes
- Graph NLP boundary → Sparse structure: defines adjacency for
- Sparse structure → Graph linear solver: drives elimination
- Graph linear solver → Linear algebra contracts: implements contract
- C OCP API → OCP-to-NLP adapter: wraps
- CasADi code generation → Generated OCP runtime: generates bindings for
- Generated OCP runtime → OCP model callbacks: implements callbacks
