Skip to content

Commit df08a2f

Browse files
authored
Add CLAUDE.md for Claude Code guidance (#84)
AI-assistant: Claude Code
1 parent 2c92062 commit df08a2f

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

CLAUDE.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
clarabel4j is a Java wrapper around the native [Clarabel](https://clarabel.org) mathematical programming solver, using Java's Foreign Function and Memory (FFM) API. It requires JDK 25+.
8+
9+
## Build Commands
10+
11+
```bash
12+
# Build and run all tests
13+
mvn clean verify
14+
15+
# Build with code coverage (excludes bindings package)
16+
mvn clean verify -P coverage
17+
18+
# Build without tests
19+
mvn clean verify -DskipTests
20+
21+
# Run a single test class
22+
mvn test -Dtest=ModelTest
23+
24+
# Run a single test method
25+
mvn test -Dtest=ModelTest#solveLinearProgramReturnsExpectedSolution
26+
```
27+
28+
There is no separate lint command. The project uses Lombok for annotation processing (configured in `lombok.config`).
29+
30+
## Architecture
31+
32+
### Layered Design
33+
34+
```
35+
High-Level API (Model, Parameters, Cone, Matrix, Status, Output)
36+
37+
FFM Bindings (com.ustermetrics.clarabel4j.bindings — auto-generated via jextract)
38+
39+
Native Clarabel C Library (clarabel_c — loaded at runtime via NativeLoader)
40+
```
41+
42+
### Key Classes (all in `com.ustermetrics.clarabel4j`)
43+
44+
- **Model** — Main orchestrator. Implements `AutoCloseable`. Has three lifecycle stages: `NEW → SETUP → OPTIMIZED`. Manages native memory via `Arena` (confined by default, or caller-provided). Methods: `setParameters()`, `setup()`, `optimize()`, `x()/z()/s()` for results.
45+
- **Parameters** — Lombok `@Builder` record with ~35 nullable solver settings. Only non-null values override Clarabel defaults.
46+
- **Matrix** — Record for CSC (Compressed Sparse Column) format sparse matrices. Validates column pointer monotonicity and row index ordering.
47+
- **Cone** — Abstract sealed class. Subtypes: `ZeroCone`, `NonnegativeCone`, `SecondOrderCone`, `ExponentialCone`, `PowerCone`, `GenPowerCone`. Each has a `getTag()` (native enum value) and `getDimension()`.
48+
- **Status** — Enum mapping native solver status codes (SOLVED, PRIMAL_INFEASIBLE, etc.).
49+
- **Output** — Sealed interface with `StdOutOutput`, `StringOutput`, `FileOutput` implementations.
50+
51+
### Bindings Package
52+
53+
The `bindings/` directory contains `generate.sh` which uses [jextract](https://jdk.java.net/jextract/) to generate FFM bindings from Clarabel C headers. After generation, `NativeLoader.loadLibrary("clarabel_c")` must be manually added to `Clarabel_h`'s static initializer, and platform-specific binding code must be removed. The bindings are checked into source control and should not be manually edited.
54+
55+
### Native Library
56+
57+
The native library (`clarabel4j-native`) is a test-scoped dependency with platform-specific classifiers (`linux_64`, `windows_64`, `osx_arm64`) activated via Maven OS profiles.
58+
59+
### Conventions
60+
61+
- Guava `Preconditions` for input validation (`checkArgument`, `checkState`)
62+
- Lombok `@NonNull`, `@Getter`, `@Builder`, `val` throughout
63+
- Java sealed types for Cone and Output hierarchies
64+
- Java records for immutable data (Matrix, Parameters)
65+
- Tests verify against known Clarabel C++ example results with 1e-8 tolerance

0 commit comments

Comments
 (0)