Skip to content

Add oximo-autodiff crate#38

Merged
GermanHeim merged 11 commits into
mainfrom
oximo-autodiff
Jul 12, 2026
Merged

Add oximo-autodiff crate#38
GermanHeim merged 11 commits into
mainfrom
oximo-autodiff

Conversation

@GermanHeim

Copy link
Copy Markdown
Collaborator

Description

This PR adds support for automatic differentiation of oximo models through std::autodiff (nightly only).

Checklist

  • I have updated the documentation accordingly
  • I have added tests that cover my changes
  • I have run cargo fmt and cargo clippy to ensure code quality
  • All default tests pass (cargo test)
  • cargo test --features gams passes (requires GAMS)
  • cargo test --features gurobi passes (requires Gurobi)
  • cargo test --features baron passes (requires BARON)

Related Issues

Closes #12

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@GermanHeim, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ec81ec88-2382-4b9a-9c3e-7a6eb4caed5a

📥 Commits

Reviewing files that changed from the base of the PR and between 6bd76ba and c8e5b85.

📒 Files selected for processing (3)
  • .github/workflows/autodiff.yml
  • .github/workflows/ci.yml
  • README.md
📝 Walkthrough

Walkthrough

Adds the oximo-autodiff crate with tape-based expression differentiation, closed-form linear/quadratic paths, sparse Jacobian and Hessian structures, Enzyme gradient/HVP execution, an NlpEvaluator API, tests, documentation, and nightly CI.

Changes

Autodiff implementation

Layer / File(s) Summary
Workspace integration and public API
Cargo.toml, crates/oximo-autodiff/Cargo.toml, crates/oximo-autodiff/README.md, crates/oximo-autodiff/src/lib.rs, crates/oximo-autodiff/src/error.rs, crates/oximo-autodiff/src/linearize.rs
Adds the crate, Enzyme feature/profile configuration, public exports, derivation errors, direct gradient evaluation, and usage documentation.
Tape compilation and function classification
crates/oximo-autodiff/src/tape.rs, crates/oximo-autodiff/src/slot.rs, crates/oximo-autodiff/tests/tape.rs
Compiles expression DAGs into reusable tapes, interprets tape operations, snapshots parameters, classifies linear/quadratic/nonlinear functions, and tests evaluation and closed-form derivatives.
Sparse Hessian structures and coloring
crates/oximo-autodiff/src/sparsity.rs, crates/oximo-autodiff/tests/sparsity.rs
Computes structural supports and Hessian patterns, builds Jacobian and Lagrangian-Hessian structures, and validates star-coloring HVP recovery across deterministic and graph-derived patterns.
Enzyme gradient and HVP wrappers
crates/oximo-autodiff/src/enzyme.rs
Adds reverse-mode gradient and forward-over-reverse Hessian-vector-product wrappers around the tape interpreter.
NLP evaluator orchestration and validation
crates/oximo-autodiff/src/evaluator.rs, crates/oximo-autodiff/tests/derivatives.rs, .github/workflows/autodiff.yml
Adds cached model classification, parameter refresh, objective/constraint/Jacobian/Hessian evaluation, serial and parallel paths, numerical validation, and nightly Enzyme CI.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Model
  participant NlpEvaluator
  participant Tape
  participant Enzyme
  Model->>NlpEvaluator: construct slots and sparsity structures
  NlpEvaluator->>Tape: compile nonlinear expressions
  NlpEvaluator->>Enzyme: evaluate gradient or compressed HVP seeds
  Enzyme-->>NlpEvaluator: return derivative buffers
  NlpEvaluator-->>Model: provide objective, Jacobian, and Hessian values
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately names the main change: adding the oximo-autodiff crate.
Description check ✅ Passed It covers the required Description, Checklist, and Related Issues sections, but the template's Changes Made section is omitted.
Linked Issues check ✅ Passed The PR implements autodiff support with gradients, Jacobians, and Hessians via nightly Enzyme, matching issue #12's requirements.
Out of Scope Changes check ✅ Passed The changes stay focused on autodiff support, docs, tests, CI, and workspace wiring, with no clear unrelated additions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/autodiff.yml:
- Line 22: Update the actions/checkout@v6 step in the workflow to disable
credential persistence by configuring its persist-credentials option to false,
ensuring the checkout token is unavailable to subsequent steps.

In `@crates/oximo-autodiff/src/evaluator.rs`:
- Around line 244-259: Reject parameter refreshes when any objective or
constraint slot changes its is_nonlinear() state, since cached lagrangian,
nl_sources, and seeds would otherwise become invalid. Update refresh_params and
the corresponding try_refresh path to compare each slot’s pre-refresh and
post-refresh nonlinear membership, returning the existing refresh error/result
type on mismatch; otherwise preserve the current reclassification and cache
rebuild behavior.
- Around line 273-283: Update Evaluator::try_refresh to include arena/model
identity in its refresh validation instead of relying only on ExprId values,
which are local to each arena. Reject refresh when the supplied model uses a
different arena, ensuring the stale nonlinear tape is not reused; retain the
existing variable, objective, and constraint checks for the same arena.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 528fbd19-be1d-4c22-ad93-194a98212665

📥 Commits

Reviewing files that changed from the base of the PR and between 0a9ce89 and 6bd76ba.

📒 Files selected for processing (15)
  • .github/workflows/autodiff.yml
  • Cargo.toml
  • crates/oximo-autodiff/Cargo.toml
  • crates/oximo-autodiff/README.md
  • crates/oximo-autodiff/src/enzyme.rs
  • crates/oximo-autodiff/src/error.rs
  • crates/oximo-autodiff/src/evaluator.rs
  • crates/oximo-autodiff/src/lib.rs
  • crates/oximo-autodiff/src/linearize.rs
  • crates/oximo-autodiff/src/slot.rs
  • crates/oximo-autodiff/src/sparsity.rs
  • crates/oximo-autodiff/src/tape.rs
  • crates/oximo-autodiff/tests/derivatives.rs
  • crates/oximo-autodiff/tests/sparsity.rs
  • crates/oximo-autodiff/tests/tape.rs

Comment thread .github/workflows/autodiff.yml
Comment thread crates/oximo-autodiff/src/evaluator.rs
Comment thread crates/oximo-autodiff/src/evaluator.rs
@GermanHeim GermanHeim merged commit e51badc into main Jul 12, 2026
5 checks passed
@GermanHeim GermanHeim deleted the oximo-autodiff branch July 12, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Add autodiff

1 participant