SciMLJacobianOperators.jl
This is a subpackage on NonlinearSolve providing a general purpose JacVec and VecJac operator built on top on DifferentiationInterface.jl.
import Pkg
Pkg.add("SciMLJacobianOperators")
using SciMLJacobianOperators
Jacobian API
SciMLJacobianOperators.JacobianOperator
— TypeJacobianOperator{iip, T} <: AbstractJacobianOperator{T} <: AbstractSciMLOperator{T}
A Jacobian Operator Provides both JVP and VJP without materializing either (if possible).
Constructor
JacobianOperator(prob::AbstractNonlinearProblem, fu, u; jvp_autodiff = nothing,
vjp_autodiff = nothing, skip_vjp::Val = Val(false), skip_jvp::Val = Val(false))
By default, the JacobianOperator
will compute JVP
. Use Base.adjoint
or Base.transpose
to switch to VJP
.
Computing the VJP
Computing the VJP is done according to the following rules:
- If
f
has avjp
method, then we use that. - If
f
has ajac
method and novjp_autodiff
is provided, then we usejac * v
. - If
vjp_autodiff
is provided we using DifferentiationInterface.jl to compute the VJP.
Computing the JVP
Computing the JVP is done according to the following rules:
- If
f
has ajvp
method, then we use that. - If
f
has ajac
method and nojvp_autodiff
is provided, then we usev * jac
. - If
jvp_autodiff
is provided we using DifferentiationInterface.jl to compute the JVP.
Special Case (Number)
For Number inputs, VJP and JVP are not distinct. Hence, if either vjp
or jvp
is provided, then we use that. If neither is provided, then we use v * jac
if jac
is provided. Finally, we use the respective autodiff methods to compute the derivative using DifferentiationInterface.jl and multiply by v
.
Methods Provided
Currently it is expected that p
during problem construction is same as p
during operator evaluation. This restriction will be lifted in the future.
(op::JacobianOperator)(v, u, p)
: Computes∂f(u, p)/∂u * v
or∂f(u, p)/∂uᵀ * v
.(op::JacobianOperator)(res, v, u, p)
: Computes∂f(u, p)/∂u * v
or∂f(u, p)/∂uᵀ * v
and stores the result inres
.
See also VecJacOperator
and JacVecOperator
.
SciMLJacobianOperators.VecJacOperator
— FunctionVecJacOperator(args...; autodiff = nothing, kwargs...)
Constructs a JacobianOperator
which only provides the VJP using the vjp_autodiff = autodiff
.
SciMLJacobianOperators.JacVecOperator
— FunctionJacVecOperator(args...; autodiff = nothing, kwargs...)
Constructs a JacobianOperator
which only provides the JVP using the jvp_autodiff = autodiff
.
Stateful Operators
SciMLJacobianOperators.StatefulJacobianOperator
— TypeStatefulJacobianOperator(jac_op::JacobianOperator, u, p)
Wrapper over a JacobianOperator
which stores the input u
and p
and defines mul!
and *
for computing VJPs and JVPs.
SciMLJacobianOperators.StatefulJacobianNormalFormOperator
— TypeStatefulJacobianNormalFormOperator(vjp_operator, jvp_operator, cache)
This constructs a Normal Form Jacobian Operator, i.e. it constructs the operator corresponding to JᵀJ
where J
is the Jacobian Operator. This is not meant to be directly constructed, rather it is constructed with *
on two StatefulJacobianOperator
s.