Skip to content

Commit ed532b7

Browse files
authored
Improve Parameter Support (#394)
* overall parameter handling * updates * Fixes * fix tests * minor doc update
1 parent e6b573a commit ed532b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1261
-746
lines changed

docs/src/develop/extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ extended using the following steps:
789789
10. Extend [`InfiniteOpt.add_point_variable`](@ref) and
790790
[`InfiniteOpt.add_semi_infinite_variable`](@ref) to use
791791
[`expand_measure`](@ref) without modifying the infinite model.
792+
11. Extend [`InfiniteOpt.update_parameter_value`](@ref) to enable incremental parameter updates.
792793

793794
This may seem like a lot a work, but the majority of the above steps can be
794795
skipped for [`JuMPBackend`](@ref)s as exemplified below. A complete extension,

docs/src/guide/expression.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ f(t)
4242
Here, we created a parameter function object, added it to `model`, and
4343
then created a Julia variable `f` that serves as a `GeneralVariableRef` that points
4444
to it. From here we can treat `f` as a normal infinite variable and use it with
45-
measures, derivatives, and constraints. For example, we can do the following:
45+
measures, and constraints. For example, we can do the following:
4646
```jldoctest param_func
4747
julia> @variable(model, y, Infinite(t));
4848
49-
julia> df = deriv(f, t)
50-
∂/∂t[f(t)]
49+
julia> f(0)
50+
f(0)
5151
5252
julia> meas = integral(y - f, t)
5353
∫{t ∈ [0, 10]}[y(t) - f(t)]
@@ -89,6 +89,14 @@ setpoint(t)
8989
Please consult the following links for more information about defining parameter
9090
functions: [`@parameter_function`](@ref) and [`parameter_function`](@ref).
9191

92+
We can also update the underlying function as often required for repeated solves.
93+
This is accomplished via
94+
[`set_parameter_value`](@ref JuMP.set_parameter_value(::ParameterFunctionRef, ::Function)):
95+
```jldoctest param_func
96+
julia> set_parameter_value(setpoint, t -> 5)
97+
98+
```
99+
92100
Beyond this, there are a number of query and modification methods that can be
93101
employed for parameter functions and these are detailed in the
94102
[technical manual](@ref par_func_manual).

docs/src/guide/finite_parameter.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,15 @@ corresponding `GeneralVariableRef` can be used in expressions, objectives, measu
5454
and constraints just like infinite parameters.
5555

5656
The value of a finite parameter can be checked using
57-
[`parameter_value`](@ref parameter_value(::FiniteParameterRef)) and can modified using
58-
[`set_value`](@ref JuMP.set_value(::FiniteParameterRef, ::Real)). For example,
57+
[`parameter_value`](@ref JuMP.parameter_value(::FiniteParameterRef)) and can modified using
58+
[`set_parameter_value`](@ref JuMP.set_parameter_value(::FiniteParameterRef, ::Real)). For example,
5959
let's update the value of `max_cost` to be now be `10.2`:
6060
```jldoctest fpar
6161
julia> parameter_value(max_cost)
6262
42.0
6363
64-
julia> set_value(max_cost, 10.2)
64+
julia> set_parameter_value(max_cost, 10.2)
6565
6666
julia> parameter_value(max_cost)
6767
10.2
6868
```
69-
70-
## Advanced Details
71-
The ability to implement finite parameters stems from its ability to support
72-
mixed variable types using by using the `GeneralVariableRef` buffer. As such,
73-
finite parameters will be treated as variables until the model is transcribed.
74-
For example, this means that the expression `max_cost * x` will be treated as a
75-
quadratic expression when it is expressed in its `InfiniteOpt` form, however it is
76-
converted into the appropriate affine expression when transcribed.
77-
78-
!!! note
79-
In previous versions finite parameters were just special cases of infinite
80-
parameters. However, they now have their own distinct underlying data structure.
81-
82-
!!! warning
83-
`InfiniteOpt`'s implementation of finite parameters should not be a reason to
84-
use `InfiniteOpt` to model non-infinite-dimensional problems, since the added
85-
overhead will make it slower than just iteratively building `JuMP` models. For
86-
this behavior, we recommend looking into using `ParametricOptInterface`.

docs/src/guide/transcribe.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,16 @@ behind infinite model transformation and is what encapsulates all the methods to
384384
transcribe measures, variables, derivatives, and constraints. This is also the
385385
method that enables the use of [`optimize!`](@ref JuMP.optimize!(::InfiniteModel)).
386386

387+
!!! note
388+
To support incremental updates of parameter functions for efficient resolves,
389+
set `update_parameter_functions = true` when defining the backend:
390+
```julia
391+
backend = TranscriptionBackend(Ipopt.Optimizer, update_parameter_functions = true)
392+
model = InfiniteModel(backend)
393+
```
394+
This setting has parameters functions mapped with JuMP parameters rather than
395+
just numerical values.
396+
387397
### Queries
388398
In this section we highlight a number of query methods that pertain to
389399
`TranscriptionBackend`s and their mappings. First, we can retrieve the JuMP `Model`

docs/src/guide/variable.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,23 @@ julia> semi = y(0, x) # make semi-infinite variable y(0, x)
636636
y(0, [x[1], x[2]])
637637
```
638638

639+
## Parameters
640+
Like JuMP, InfiniteOpt supports the use of `MOI.Parameter`. For instance,
641+
consider making a finite variable as a parameter:
642+
```jldoctest restrict_vars
643+
julia> @variable(model, param in Parameter(42))
644+
param
645+
```
646+
which simply produces a finite parameter (i.e., is equivalent to
647+
`@finite_parameter(model, param == 42)`). For infinite variables, the use
648+
of `MOI.Parameter` simply produces a parameter function:
649+
```jldoctest restrict_vars
650+
julia> @variable(model, pfunc in Parameter(sin), Infinite(t))
651+
pfunc(t)
652+
```
653+
which is equivalent to `@parameter_function(model, pfunc == sin(t))`. All
654+
parameters can be updated via [`set_parameter_value`](@ref), see [Finite Parameters](@ref finite_param_docs) and [Parameter Function](@ref par_func_docs) to learn more.
655+
639656
## Queries
640657
`InfiniteOpt` contains a large suite of methods to query information about
641658
variables. This suite comprises extensions to all current `JuMP` query

docs/src/manual/backend.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ expression_supports(::Any, ::AbstractTransformationBackend)
7272
constraint_supports(::InfOptConstraintRef, ::AbstractTransformationBackend)
7373
transformation_backend_ready
7474
set_transformation_backend_ready
75+
update_parameter_value(::AbstractTransformationBackend, ::Any, ::Any)
7576
```

docs/src/manual/expression.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,25 @@ ParameterFunctionRef
1919
```@docs
2020
JuMP.name(::ParameterFunctionRef)
2121
raw_function(::ParameterFunctionRef)
22+
JuMP.parameter_value(::ParameterFunctionRef)
2223
call_function
2324
parameter_refs(::ParameterFunctionRef)
2425
parameter_list(::ParameterFunctionRef)
2526
raw_parameter_refs(::ParameterFunctionRef)
2627
is_used(::ParameterFunctionRef)
2728
used_by_semi_infinite_variable(::ParameterFunctionRef)
28-
used_by_derivative(::ParameterFunctionRef)
29+
used_by_point_variable(::ParameterFunctionRef)
2930
used_by_measure(::ParameterFunctionRef)
3031
used_by_constraint(::ParameterFunctionRef)
3132
parameter_group_int_indices(::ParameterFunctionRef)
33+
num_parameter_functions
34+
all_parameter_functions
3235
```
3336

3437
### Modification
3538
```@docs
3639
JuMP.set_name(::ParameterFunctionRef, ::String)
40+
JuMP.set_parameter_value(::ParameterFunctionRef, ::Function)
3741
JuMP.delete(::InfiniteModel, ::ParameterFunctionRef)
3842
```
3943

@@ -87,8 +91,8 @@ used_by_objective(::GeneralVariableRef)
8791
used_by_constraint(::GeneralVariableRef)
8892
is_used(::GeneralVariableRef)
8993
has_derivative_constraints(::GeneralVariableRef)
90-
parameter_value(::GeneralVariableRef)
91-
JuMP.set_value(::GeneralVariableRef, ::Real)
94+
JuMP.parameter_value(::GeneralVariableRef)
95+
JuMP.set_parameter_value(::GeneralVariableRef, ::Any)
9296
infinite_domain(::GeneralVariableRef)
9397
infinite_domain(::Array{<:GeneralVariableRef})
9498
set_infinite_domain(::GeneralVariableRef, ::InfiniteScalarDomain)

docs/src/manual/finite_parameter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ parameter [technical manual](@ref inf_par_manual) for the remainder of the
1919
methods available for finite parameters (i.e., any method typed for
2020
`ScalarParameterRef`s)
2121
```@docs
22-
parameter_value(::FiniteParameterRef)
23-
JuMP.set_value(::FiniteParameterRef, ::Real)
22+
JuMP.parameter_value(::FiniteParameterRef)
23+
JuMP.set_parameter_value(::FiniteParameterRef, ::Real)
2424
used_by_objective(::FiniteParameterRef)
2525
core_object(::FiniteParameterRef)
2626
```

docs/src/manual/transcribe.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ InfiniteOpt.constraint_supports(::InfiniteOpt.InfOptConstraintRef,::InfiniteOpt.
4545
InfiniteOpt.TranscriptionOpt.parameter_supports(::InfiniteOpt.TranscriptionOpt.TranscriptionBackend)
4646
```
4747

48+
## Updates
49+
```@docs
50+
InfiniteOpt.update_parameter_value(::InfiniteOpt.TranscriptionOpt.TranscriptionBackend, ::InfiniteOpt.FiniteParameterRef, ::Real)
51+
InfiniteOpt.update_parameter_value(::InfiniteOpt.TranscriptionOpt.TranscriptionBackend, ::InfiniteOpt.ParameterFunctionRef, ::Function)
52+
```
53+
4854
## Utilities
4955
```@docs
5056
InfiniteOpt.TranscriptionOpt.support_index_iterator

src/InfiniteOpt.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ include("point_variables.jl")
3333
include("finite_variables.jl")
3434
include("nlp.jl")
3535
include("macros.jl")
36+
include("parameter_function.jl")
3637
include("expressions.jl")
3738
include("measures.jl")
3839

@@ -66,6 +67,7 @@ Base.@deprecate optimizer_model_variable(v; kwargs...) transformation_variable(v
6667
Base.@deprecate optimizer_model_expression(e; kwargs...) transformation_expression(e; kwargs...)
6768
Base.@deprecate optimizer_model_constraint(c; kwargs...) transformation_constraint(c; kwargs...)
6869
Base.@deprecate optimizer_model(m) transformation_model(m)
70+
Base.@deprecate set_value(v::GeneralVariableRef, val) set_parameter_value(v, val)
6971

7072
# Define additional stuff that should not be exported
7173
const _EXCLUDE_SYMBOLS = [

0 commit comments

Comments
 (0)