Skip to content

Commit

Permalink
docs: add a README for SciMLJacobianOperators
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Sep 25, 2024
1 parent bdacb9c commit c2706b8
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions lib/SciMLJacobianOperators/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SciMLJacobianOperators.jl

SciMLJacobianOperators provides a convenient way to compute Jacobian-Vector Product (JVP)
and Vector-Jacobian Product (VJP) using
[SciMLOperators.jl](https://github.com/SciML/SciMLOperators.jl) and
[DifferentiationInterface.jl](https://github.com/gdalle/DifferentiationInterface.jl).

Currently we have interfaces for:

- `NonlinearProblem`
- `NonlinearLeastSquaresProblem`

and all autodiff backends supported by DifferentiationInterface.jl are supported.

## Example

```julia
using SciMLJacobianOperators, NonlinearSolve, Enzyme, ForwardDiff

# Define the problem
f(u, p) = u .* u .- p
u0 = ones(4)
p = 2.0
prob = NonlinearProblem(f, u0, p)
fu0 = f(u0, p)
v = ones(4) .* 2

# Construct the operator
jac_op = JacobianOperator(
prob, fu0, u0;
jvp_autodiff = AutoForwardDiff(),
vjp_autodiff = AutoEnzyme(; mode = Enzyme.Reverse)
)
sjac_op = StatefulJacobianOperator(jac_op, u0, p)

sjac_op * v # Computes the JVP
# 4-element Vector{Float64}:
# 4.0
# 4.0
# 4.0
# 4.0

sjac_op' * v # Computes the VJP
# 4-element Vector{Float64}:
# 4.0
# 4.0
# 4.0
# 4.0

# What if we multiply the VJP and JVP?
snormal_form = sjac_op' * sjac_op

snormal_form * v # Computes JᵀJ * v
# 4-element Vector{Float64}:
# 8.0
# 8.0
# 8.0
# 8.0
```

0 comments on commit c2706b8

Please sign in to comment.