Skip to content

Commit 0df7b81

Browse files
Merge pull request #772 from SciML/Vaibhavdixit02-patch-1
Change the order of args in `cons_vjp` and `cons_jvp`
2 parents 252625c + 0c8bb2f commit 0df7b81

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/scimlfunctions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,16 +1823,16 @@ function described in [Callback Functions](https://docs.sciml.ai/Optimization/st
18231823
then `hess(H,u,p,args...)` or `H=hess(u,p,args...)` should be used.
18241824
- `hv(Hv,u,v,p)` or `Hv=hv(u,v,p)`: the Hessian-vector product ``(d^2 f / du^2) v``. If `f` takes additional arguments
18251825
then `hv(Hv,u,v,p,args...)` or `Hv=hv(u,v,p, args...)` should be used.
1826-
- `cons(res,x,p)` or `res=cons(x,p)` : the constraints function, should mutate the passed `res` array
1826+
- `cons(res,u,p)` or `res=cons(u,p)` : the constraints function, should mutate the passed `res` array
18271827
with value of the `i`th constraint, evaluated at the current values of variables
18281828
inside the optimization routine. This takes just the function evaluations
18291829
and the equality or inequality assertion is applied by the solver based on the constraint
18301830
bounds passed as `lcons` and `ucons` to [`OptimizationProblem`](@ref), in case of equality
18311831
constraints `lcons` and `ucons` should be passed equal values.
1832-
- `cons_j(J,x,p)` or `J=cons_j(x,p)`: the Jacobian of the constraints.
1833-
- `cons_jvp(Jv,v,x,p)` or `Jv=cons_jvp(v,x,p)`: the Jacobian-vector product of the constraints.
1834-
- `cons_vjp(Jv,v,x,p)` or `Jv=cons_vjp(v,x,p)`: the Jacobian-vector product of the constraints.
1835-
- `cons_h(H,x,p)` or `H=cons_h(x,p)`: the Hessian of the constraints, provided as
1832+
- `cons_j(J,u,p)` or `J=cons_j(u,p)`: the Jacobian of the constraints.
1833+
- `cons_jvp(Jv,u,v,p)` or `Jv=cons_jvp(u,v,p)`: the Jacobian-vector product of the constraints.
1834+
- `cons_vjp(Jv,u,v,p)` or `Jv=cons_vjp(u,v,p)`: the Jacobian-vector product of the constraints.
1835+
- `cons_h(H,u,p)` or `H=cons_h(u,p)`: the Hessian of the constraints, provided as
18361836
an array of Hessians with `res[i]` being the Hessian with respect to the `i`th output on `cons`.
18371837
- `hess_prototype`: a prototype matrix matching the type that matches the Hessian. For example,
18381838
if the Hessian is tridiagonal, then an appropriately sized `Hessian` matrix can be used
@@ -1845,7 +1845,7 @@ function described in [Callback Functions](https://docs.sciml.ai/Optimization/st
18451845
This is defined as an array of matrices, where `hess[i]` is the Hessian w.r.t. the `i`th output.
18461846
For example, if the Hessian is sparse, then `hess` is a `Vector{SparseMatrixCSC}`.
18471847
The default is `nothing`, which means a dense constraint Hessian.
1848-
- `lag_h(res,x,sigma,mu,p)` or `res=lag_h(x,sigma,mu,p)`: the Hessian of the Lagrangian,
1848+
- `lag_h(res,u,sigma,mu,p)` or `res=lag_h(u,sigma,mu,p)`: the Hessian of the Lagrangian,
18491849
where `sigma` is a multiplier of the cost function and `mu` are the Lagrange multipliers
18501850
multiplying the constraints. This can be provided instead of `hess` and `cons_h`
18511851
to solvers that directly use the Hessian of the Lagrangian.

src/solutions/ode_solutions.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,14 @@ function sensitivity_solution(sol::ODESolution, u, t)
605605
return @set sol.interp = interp
606606
end
607607

608-
struct LazyInterpolationException <: Exception
608+
struct LazyInterpolationException <: Exception
609609
var::Symbol
610610
end
611611

612-
Base.showerror(io::IO, e::LazyInterpolationException) = print(io, "The algorithm", e.var, " uses lazy interpolation, which is incompatible with `strip_solution`.")
612+
function Base.showerror(io::IO, e::LazyInterpolationException)
613+
print(io, "The algorithm", e.var,
614+
" uses lazy interpolation, which is incompatible with `strip_solution`.")
615+
end
613616

614617
function strip_solution(sol::ODESolution)
615618
if has_lazy_interpolation(sol.alg)

src/solutions/optimization_solutions.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Representation of the solution to a non-linear optimization defined by an Optimi
5656
- `retcode`: the return code from the solver. Used to determine whether the solver solved
5757
successfully or whether it exited due to an error. For more details, see
5858
[the return code documentation](https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes).
59-
- `original`: if the solver is wrapped from an alternative solver ecosystem, such as
59+
- `original`: if the solver is wrapped from a external solver, e.g.
6060
Optim.jl, then this is the original return from said solver library.
6161
- `stats`: statistics of the solver, such as the number of function evaluations required.
6262
"""
@@ -211,6 +211,8 @@ Base.@propagate_inbounds function Base.getproperty(x::AbstractOptimizationSoluti
211211
Base.depwarn("`sol.minimizer` is deprecated. Use `sol.u` instead.",
212212
"sol.minimizer")
213213
return getfield(x, :u)
214+
elseif s === :x
215+
return getfield(x, :u)
214216
elseif s === :minimum
215217
Base.depwarn("`sol.minimum` is deprecated. Use `sol.objective` instead.",
216218
"sol.minimum")

0 commit comments

Comments
 (0)