Skip to content

Commit 6682a71

Browse files
revert all u to x changes
1 parent 4f80de9 commit 6682a71

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

src/problems/optimization_problems.jl

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ Documentation Page: https://docs.sciml.ai/Optimization/stable/API/optimization_p
88
## Mathematical Specification of an Optimization Problem
99
1010
To define an optimization problem, you need the objective function ``f``
11-
which is minimized over the domain of ``x``, the collection of optimization variables:
11+
which is minimized over the domain of ``u``, the collection of optimization variables:
1212
1313
```math
14-
min_u f(x,p)
14+
min_u f(u,p)
1515
```
1616
17-
``x₀`` is an initial guess for the minimizer. `f` should be specified as `f(x,p)`
17+
``u₀`` is an initial guess for the minimizer. `f` should be specified as `f(u,p)`
1818
and `u₀` should be an `AbstractArray` whose geometry matches the
19-
desired geometry of `x`. Note that we are not limited to vectors
20-
for `x₀`; one is allowed to provide `x₀` as arbitrary matrices /
19+
desired geometry of `u`. Note that we are not limited to vectors
20+
for `u₀`; one is allowed to provide `u₀` as arbitrary matrices /
2121
higher-dimension tensors as well.
2222
2323
## Problem Type
2424
2525
### Constructors
2626
2727
```julia
28-
OptimizationProblem{iip}(f, x0, p = SciMLBase.NullParameters(),;
28+
OptimizationProblem{iip}(f, u0, p = SciMLBase.NullParameters(),;
2929
lb = nothing,
3030
ub = nothing,
3131
lcons = nothing,
@@ -44,12 +44,12 @@ will be used, which will throw nice errors if you try to index non-existent
4444
parameters.
4545
4646
`lb` and `ub` are the upper and lower bounds for box constraints on the
47-
optimization variables. They should be an `AbstractArray` matching the geometry of `x`,
48-
where `(lb[i],ub[i])` is the box constraint (lower and upper bounds) for `x[i]`.
47+
optimization variables. They should be an `AbstractArray` matching the geometry of `u`,
48+
where `(lb[i],ub[i])` is the box constraint (lower and upper bounds) for `u[i]`.
4949
5050
`lcons` and `ucons` are the upper and lower bounds in case of inequality constraints on the
5151
optimization and if they are set to be equal then it represents an equality constraint.
52-
They should be an `AbstractArray` matching the geometry of `x`, where `(lcons[i],ucons[i])`
52+
They should be an `AbstractArray` matching the geometry of `u`, where `(lcons[i],ucons[i])`
5353
are the lower and upper bounds for `cons[i]`.
5454
5555
The `f` in the `OptimizationProblem` should typically be an instance of [`OptimizationFunction`](https://docs.sciml.ai/Optimization/stable/API/optimization_function/#optfunction)
@@ -65,10 +65,10 @@ Any extra keyword arguments are captured to be sent to the optimizers.
6565
### Fields
6666
6767
* `f`: the function in the problem.
68-
* `x0`: the initial guess for the optimization variables.
68+
* `u0`: the initial guess for the optimization variables.
6969
* `p`: the constant parameters used for defining the problem. Defaults to `NullParameters`.
70-
* `lb`: the lower bounds for the optimization variables `x`.
71-
* `ub`: the upper bounds for the optimization variables `x`.
70+
* `lb`: the lower bounds for the optimization variables `u`.
71+
* `ub`: the upper bounds for the optimization variables `u`.
7272
* `int`: integrality indicator for `u`. If `int[i] == true`, then `u[i]` is an integer variable.
7373
Defaults to `nothing`, implying no integrality constraints.
7474
* `lcons`: the vector of lower bounds for the constraints passed to [OptimizationFunction](https://docs.sciml.ai/Optimization/stable/API/optimization_function/#optfunction).
@@ -81,12 +81,12 @@ Any extra keyword arguments are captured to be sent to the optimizers.
8181
## Inequality and Equality Constraints
8282
8383
Both inequality and equality constraints are defined by the `f.cons` function in the [`OptimizationFunction`](https://docs.sciml.ai/Optimization/stable/API/optimization_function/#optfunction)
84-
description of the problem structure. This `f.cons` is given as a function `f.cons(x,p)` which computes
85-
the value of the constraints at `x`. For example, take `f.cons(x,p) = x[1] - x[2]`.
84+
description of the problem structure. This `f.cons` is given as a function `f.cons(u,p)` which computes
85+
the value of the constraints at `u`. For example, take `f.cons(u,p) = u[1] - u[2]`.
8686
With these definitions, `lcons` and `ucons` define the bounds on the constraint that the solvers try to satisfy.
87-
If `lcons` and `ucons` are `nothing`, then there are no constraints bounds, meaning that the constraint is satisfied when `-Inf < f.cons < Inf` (which of course is always!). If `lcons[i] = ucons[i] = 0`, then the constraint is satisfied when `f.cons(x,p)[i] = 0`, and so this implies the equality constraint `u[1] = u[2]`. If `lcons[i] = ucons[i] = a`, then ``x[1] - x[2] = a`` is the equality constraint.
87+
If `lcons` and `ucons` are `nothing`, then there are no constraints bounds, meaning that the constraint is satisfied when `-Inf < f.cons < Inf` (which of course is always!). If `lcons[i] = ucons[i] = 0`, then the constraint is satisfied when `f.cons(u,p)[i] = 0`, and so this implies the equality constraint `u[1] = u[2]`. If `lcons[i] = ucons[i] = a`, then ``u[1] - u[2] = a`` is the equality constraint.
8888
89-
Inequality constraints are then given by making `lcons[i] != ucons[i]`. For example, `lcons[i] = -Inf` and `ucons[i] = 0` would imply the inequality constraint ``x[1] <= x[2]`` since any `f.cons[i] <= 0` satisfies the constraint. Similarly, `lcons[i] = -1` and `ucons[i] = 1` would imply that `-1 <= f.cons[i] <= 1` is required or ``-1 <= x[1] - x[2] <= 1``.
89+
Inequality constraints are then given by making `lcons[i] != ucons[i]`. For example, `lcons[i] = -Inf` and `ucons[i] = 0` would imply the inequality constraint ``u[1] <= u[2]`` since any `f.cons[i] <= 0` satisfies the constraint. Similarly, `lcons[i] = -1` and `ucons[i] = 1` would imply that `-1 <= f.cons[i] <= 1` is required or ``-1 <= u[1] - u[2] <= 1``.
9090
9191
Note that these vectors must be sized to match the number of constraints, with one set of conditions for each constraint.
9292
@@ -150,7 +150,3 @@ end
150150

151151
isinplace(f::OptimizationFunction{iip}) where {iip} = iip
152152
isinplace(f::OptimizationProblem{iip}) where {iip} = iip
153-
154-
function Base.getproperty(prob::OptimizationProblem, sym::Symbol)
155-
sym === :x0 ? getfield(prob, :u0) : getfield(prob, sym)
156-
end

src/scimlfunctions.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ $(TYPEDEF)
17801780
A representation of an objective function `f`, defined by:
17811781
17821782
```math
1783-
\\min_{u} f(x,p)
1783+
\\min_{u} f(u,p)
17841784
```
17851785
17861786
and all of its related functions, such as the gradient of `f`, its Hessian,
@@ -1807,7 +1807,7 @@ OptimizationFunction{iip}(f, adtype::AbstractADType = NoAD();
18071807
18081808
## Positional Arguments
18091809
1810-
- `f(x,p,args...)`: the function to optimize. `x` are the optimization variables and `p` are parameters used in definition of
1810+
- `f(u,p,args...)`: the function to optimize. `u` are the optimization variables and `p` are parameters used in definition of
18111811
the objective, even if no such parameters are used in the objective it should be an argument in the function. This can also take
18121812
any additional arguments that are relevant to the objective function, for example minibatches used in machine learning,
18131813
take a look at the minibatching tutorial [here](https://docs.sciml.ai/Optimization/stable/tutorials/minibatch/). This should return
@@ -1817,22 +1817,22 @@ function described in [Callback Functions](https://docs.sciml.ai/Optimization/st
18171817
18181818
## Keyword Arguments
18191819
1820-
- `grad(G,x,p)` or `G=grad(x,p)`: the gradient of `f` with respect to `x`. If `f` takes additional arguments
1821-
then `grad(G,x,p,args...)` or `G=grad(x,p,args...)` should be used.
1822-
- `hess(H,x,p)` or `H=hess(x,p)`: the Hessian of `f` with respect to `x`. If `f` takes additional arguments
1823-
then `hess(H,x,p,args...)` or `H=hess(x,p,args...)` should be used.
1824-
- `hv(Hv,x,v,p)` or `Hv=hv(x,v,p)`: the Hessian-vector product ``(d^2 f / dx^2) v``. If `f` takes additional arguments
1825-
then `hv(Hv,x,v,p,args...)` or `Hv=hv(x,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
1820+
- `grad(G,u,p)` or `G=grad(u,p)`: the gradient of `f` with respect to `u`. If `f` takes additional arguments
1821+
then `grad(G,u,p,args...)` or `G=grad(u,p,args...)` should be used.
1822+
- `hess(H,u,p)` or `H=hess(u,p)`: the Hessian of `f` with respect to `u`. If `f` takes additional arguments
1823+
then `hess(H,u,p,args...)` or `H=hess(u,p,args...)` should be used.
1824+
- `hv(Hv,u,v,p)` or `Hv=hv(u,v,p)`: the Hessian-vector product ``(d^2 f / dx^2) v``. If `f` takes additional arguments
1825+
then `hv(Hv,u,v,p,args...)` or `Hv=hv(u,v,p, args...)` should be used.
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,x,v,p)` or `Jv=cons_jvp(x,v,p)`: the Jacobian-vector product of the constraints.
1834-
- `cons_vjp(Jv,x,v,p)` or `Jv=cons_vjp(x,v,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)

test/remake_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ for prob in deepcopy(probs)
249249
function fakeloss!(p)
250250
prob2 = @inferred baseType remake(prob; p = [:a => p])
251251
@test eltype(prob2.p) <: ForwardDiff.Dual
252-
return prob2.p[:a]
252+
return prob2.ps[:a]
253253
end
254254
ForwardDiff.derivative(fakeloss!, 1.0)
255255
end

0 commit comments

Comments
 (0)