Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to JuMP v0.22 #177

Merged
merged 3 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "InfiniteOpt"
uuid = "20393b10-9daf-11e9-18c9-8db751c92c57"
authors = ["Joshua Pulsipher and Weiqi Zhang"]
version = "0.5.0"
version = "0.5.1"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand All @@ -20,9 +20,9 @@ AbstractTrees = "0.3"
DataStructures = "^0.14.2, 0.15, 0.16, 0.17, 0.18"
Distributions = "0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25"
FastGaussQuadrature = "^0.3.2, 0.4"
JuMP = "0.21.10"
JuMP = "0.22"
LeftChildRightSiblingTrees = "0.1"
MutableArithmetics = "0.2"
MutableArithmetics = "0.3"
Reexport = "0.2, 1"
SpecialFunctions = "0.8, 0.9, 0.10, 1"
julia = "1"
Expand Down
8 changes: 4 additions & 4 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Clp = "0.8"
Clp = "0.9"
Distributions = "0.25"
Documenter = "0.27"
InfiniteOpt = "0.5"
Ipopt = "0.7"
Literate = "2.8"
Ipopt = "0.8"
Literate = "2.9"
Plots = "1"
SpecialFunctions = "1.7"
SpecialFunctions = "1.8"
julia = "1.6"
4 changes: 2 additions & 2 deletions docs/src/develop/start_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ through step by step how this should be done.
browsing what open issues are (especially ones with the tag `good first issue`).
Note that if your proposed contribution corresponds to an existing issue please
do not make a new issue. A guide to using issues in GitHub is located
[here](https://guides.github.com/features/issues/).
[here](https://docs.github.com/issues/tracking-your-work-with-issues/about-issues).
3. Fork the `InfiniteOpt` repository to your GitHub account. Only core
developers have permissions to modify `InfiniteOpt` directly, thus others need
to fork it which essentially amounts to creating their own linked copy. This is
Expand Down Expand Up @@ -67,7 +67,7 @@ through step by step how this should be done.
8. Create a pull request. Go [here](https://github.com/pulsipher/InfiniteOpt.jl)
to `InfiniteOpt`'s main page and create a pull request drawing from your forked
repository. A step by step explanation is provided
[here](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).
[here](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).
9. Make necessary changes if the tests fail and/or we ask you to make specific
changes. The Codecov tests will ensure every new line of code is tested at least
once with the new test functions and the GitHub Actions CI will ensure that
Expand Down
2 changes: 1 addition & 1 deletion docs/src/develop/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Here we detail the programmatic style used with `InfiniteOpt`. This is done in a
effort to make this package intuitive for new-comers and to ease development. This
style closely follows that of `JuMP.jl` with similar deviations from typical Julia
styles. Please refer to the
[`JuMP` style guide](https://jump.dev/JuMP.jl/v0.21.10/developers/style/) as this
[`JuMP` style guide](https://jump.dev/JuMP.jl/v0.22/developers/style/) as this
is the style used by `InfiniteOpt`.

In addition, we adopt the following practices:
Expand Down
42 changes: 14 additions & 28 deletions docs/src/guide/constraint.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ implement these types of constraints in `InfiniteOpt`.

## Basic Usage
Principally, the
[`@constraint`](https://jump.dev/JuMP.jl/v0.21.10/reference/constraints/#JuMP.@constraint)
[`@constraint`](https://jump.dev/JuMP.jl/v0.22/reference/constraints/#JuMP.@constraint)
macro is used to define constraints. First, let's setup an infinite model with
variables that we can add constraints to:
```jldoctest constrs; setup = :(using InfiniteOpt)
Expand All @@ -40,7 +40,7 @@ julia> @variable(model, z[1:2]);
!!! note
Unlike previous versions, `InfiniteOpt` now supports all of the constraints
offered by `JuMP`, including vector and semi-definite constraints! Please
see [JuMP's constraint documentation](https://jump.dev/JuMP.jl/v0.21.10/manual/constraints/#Constraints)
see [JuMP's constraint documentation](https://jump.dev/JuMP.jl/v0.22/manual/constraints/#Constraints)
for a thorough explanation of the supported types and syntax.

!!! note
Expand All @@ -67,7 +67,7 @@ the allowed constraint operators are `==`, `<=`, `≤`, `>=`, and `≥`.
Linear algebra constraints can also be used when defining constraints
when `.` is added in front of the constraint operators (e.g., `.<=`). This
behavior is further explained in
[`JuMP`'s constraint documentation](https://jump.dev/JuMP.jl/v0.21.10/manual/constraints/#Vectorized-constraints).
[`JuMP`'s constraint documentation](https://jump.dev/JuMP.jl/v0.22/manual/constraints/#Vectorized-constraints).

Similarly, we can define an array of constraints with varied indexes by including
an additional argument before the constraint expression. For example,
Expand All @@ -81,7 +81,7 @@ julia> @constraint(model, c2[i = 1:2], 3z[i] - 14 == 0)
Thus, we added two constraints to `model` and stored a vector of the corresponding
constraint references to the `Julia` variable `c2`. To learn more about building
containers of constraints please see
[`JuMP`'s constraint container documentation](https://jump.dev/JuMP.jl/v0.21.10/manual/constraints/#Constraint-containers).
[`JuMP`'s constraint container documentation](https://jump.dev/JuMP.jl/v0.22/manual/constraints/#Constraint-containers).

### Multi-Dimensional Constraints
Building upon `JuMP` we support a variety of multi-dimensional constraint types.
Expand All @@ -100,7 +100,7 @@ julia> b = [5, 6]
julia> @constraint(model, A * z - b in MOI.Nonnegatives(2))
[z[1] + 2 z[2] - 5, 3 z[1] + 4 z[2] - 6] ∈ MathOptInterface.Nonnegatives(2)
```
See [`JuMP`'s constraint documentation](https://jump.dev/JuMP.jl/v0.21.10/manual/constraints/)
See [`JuMP`'s constraint documentation](https://jump.dev/JuMP.jl/v0.22/manual/constraints/)
for a thorough tutorial on the accepted syntax and constraint types.

### Restricted Constraints
Expand All @@ -109,18 +109,6 @@ parameters they explicitly/implicitly depend on) that is restricted to a certain
sub-domain. Such constraints are common for enforcing initial/boundary conditions
and for enforcing path constraints over a certain sub-domain.

!!! warning
Previous versions of `InfiniteOpt` referred to restricted constraints as
"bounded constraints" and used `@BDconstraint` to define them. This has been
deprecated in favor of the more intuitive domain restricted nomenclature.
```julia
# Old syntax
@BDconstraint(model, name_expr(restricts...), constr_expr)

# New syntax
@constraint(model, name_expr, constr_expr, DomainRestrictions(restricts...))
```

These types of constraints are defined adding [`DomainRestrictions`](@ref). For
example, let's add the initial condition ``y_b(0) = 0``:
```jldoctest constrs
Expand Down Expand Up @@ -162,8 +150,8 @@ set. This leads to the following data structures:
| Matrix | `Matrix{<:JuMP.AbstractJuMPScalar}` | `MOI.AbstractVectorSet` [via vectorization](https://jump.dev/MathOptInterface.jl/v0.9.22/reference/standard_form/#Matrix-sets) |

The above combos are then stored in
[`JuMP.ScalarConstraint`](https://jump.dev/JuMP.jl/v0.21.10/reference/constraints/#JuMP.ScalarConstraint)s
and [`JuMP.VectorConstraint](https://jump.dev/JuMP.jl/v0.21.10/reference/constraints/#JuMP.VectorConstraint)s.
[`JuMP.ScalarConstraint`](https://jump.dev/JuMP.jl/v0.22/reference/constraints/#JuMP.ScalarConstraint)s
and [`JuMP.VectorConstraint](https://jump.dev/JuMP.jl/v0.22/reference/constraints/#JuMP.VectorConstraint)s.

Restricted constraints are built upon this data structure where the underlying
constraint is created in the same manner. Then the specified
Expand Down Expand Up @@ -208,13 +196,12 @@ c3 : -yb(t)² + 3 ya(t, x) ≤ 0.0, ∀ t ∈ [0, 10], x[1] ∈ [-2, 2], x[2]
Thus, we have made our constraint and added it `model` and now have a constraint
reference `cref` that we can use to access it.

The [`@constraint`](https://jump.dev/JuMP.jl/v0.21.10/reference/constraints/#JuMP.@constraint)
and [`@SDconstraint`](https://jump.dev/JuMP.jl/v0.21.10/reference/constraints/#JuMP.@SDconstraint)
macros automate the above steps.
The [`@constraint`](https://jump.dev/JuMP.jl/v0.22/reference/constraints/#JuMP.@constraint)
macro automate the above steps.

### Macro Definition
As mentioned above in the Basic Usage section, the
[`@constraint`](https://jump.dev/JuMP.jl/v0.21.10/reference/constraints/#JuMP.@constraint)
[`@constraint`](https://jump.dev/JuMP.jl/v0.22/reference/constraints/#JuMP.@constraint)
macro should be used to define constraints with the syntax:
`@constraint(model::InfiniteModel, [container/name_expr], constr_expr, [rs::DomainRestrictions])`.

Expand All @@ -241,7 +228,7 @@ julia> crefs
2 z[2] - yb(t) = 0.0, ∀ t ∈ [0, 10]
```
Please refer to
[`JuMP`'s constraint container documentation](https://jump.dev/JuMP.jl/v0.21.10/manual/constraints/#Constraint-containers)
[`JuMP`'s constraint container documentation](https://jump.dev/JuMP.jl/v0.22/manual/constraints/#Constraint-containers)
for a thorough tutorial on creating containers of constraints.

Any constraint type supported by `JuMP` can be specified in the `constr_expr`
Expand All @@ -252,14 +239,13 @@ argument. This includes a wealth of constraint types including:
- Conic constraints
- Indicator constraints
- Semi-definite constraints
For example, we could define the following semi-definite constraint using
`@SDconstraint`:
For example, we could define the following semi-definite constraint:
```jldoctest constrs
julia> @SDconstraint(model, [yb 2yb; 3yb 4yb] >= ones(2, 2))
julia> @constraint(model, [yb 2yb; 3yb 4yb] >= ones(2, 2), PSDCone())
[yb(t) - 1 2 yb(t) - 1;
3 yb(t) - 1 4 yb(t) - 1] ∈ PSDCone(), ∀ t ∈ [0, 10]
```
See [`JuMP`'s constraint documentation](https://jump.dev/JuMP.jl/v0.21.10/manual/constraints/)
See [`JuMP`'s constraint documentation](https://jump.dev/JuMP.jl/v0.22/manual/constraints/)
for a thorough tutorial on the accepted syntax and constraint types.

Finally, restrictions on the inherent infinite domain of a constraint can be
Expand Down
2 changes: 1 addition & 1 deletion docs/src/guide/derivative.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ process.

### Macro Definition
There are two macros we provide for defining derivatives:
[`@variable`](https://jump.dev/JuMP.jl/v0.21.10/reference/variables/#JuMP.@variable)
[`@variable`](https://jump.dev/JuMP.jl/v0.22/reference/variables/#JuMP.@variable)
that uses the [`Deriv`](@ref) variable type and [`@deriv`](@ref).

!!! warning
Expand Down
8 changes: 4 additions & 4 deletions docs/src/guide/expression.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ object for storing affine expressions.

!!! note
Where possible, it is preferable to use
[`@expression`](https://jump.dev/JuMP.jl/v0.21.10/reference/expressions/#JuMP.@expression)
[`@expression`](https://jump.dev/JuMP.jl/v0.22/reference/expressions/#JuMP.@expression)
for defining expressions as it is much more efficient than explicitly using
the standard operators.

Expand All @@ -188,7 +188,7 @@ Notice that the ordered dictionary preserves the order in which the variables
appear in the expression.

More information can be found in the documentation for affine expressions in
[`JuMP`](https://jump.dev/JuMP.jl/v0.21.10/reference/expressions/#Affine-expressions).
[`JuMP`](https://jump.dev/JuMP.jl/v0.22/reference/expressions/#Affine-expressions).

## Quadratic Expressions
A quadratic function pertains to a mathematical function of the form:
Expand Down Expand Up @@ -258,7 +258,7 @@ Notice again that the ordered dictionary preserves the order.
```

More information can be found in the documentation for quadratic expressions in
[`JuMP`](https://jump.dev/JuMP.jl/v0.21.10/reference/expressions/#Quadratic-expressions).
[`JuMP`](https://jump.dev/JuMP.jl/v0.22/reference/expressions/#Quadratic-expressions).

## [Nonlinear Expressions](@id nlp_guide)
General nonlinear expressions as generated via `JuMP.@NLexpression`,
Expand Down Expand Up @@ -635,5 +635,5 @@ julia> map_nlp_to_ast(v -> y_jump, expr)
:(exp(y_jump ^ 2.3) * y_jump - 42)
```
This is useful for converting `NLPExpr`s into ASTs that can be used in `JuMP`
via its [`add_NL_expression`](https://jump.dev/JuMP.jl/v0.21.10/manual/nlp/#Raw-expression-input)
via its [`add_NL_expression`](https://jump.dev/JuMP.jl/v0.22/manual/nlp/#Raw-expression-input)
API.
15 changes: 7 additions & 8 deletions docs/src/guide/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ respective [technical manual](@ref infinite_model_manual) for more details.
## Overview
Infinite models are expressed via the [`InfiniteModel`](@ref) datatype which is at the
core of `InfiniteOpt`. These model objects are designed to emulate the behavior
of [`Model`](https://jump.dev/JuMP.jl/v0.21.10/reference/models/#JuMP.Model)
of [`Model`](https://jump.dev/JuMP.jl/v0.22/reference/models/#JuMP.Model)
objects in `JuMP`. These data objects store the parameters, variables,
measures, objective, constraints, and all other data used in `InfiniteOpt`. This
differs from `JuMP` models which store such information in a `MathOptInterface`
Expand Down Expand Up @@ -59,7 +59,7 @@ supported for use in `InfiniteOpt`. For completeness, the table of currently
supported optimizers is provided below in [Supported Optimizers](@ref).

We can also specify optimizer attributes via
[`optimizer_with_attributes`](https://jump.dev/JuMP.jl/v0.21.10/reference/models/#JuMP.optimizer_with_attributes)
[`optimizer_with_attributes`](https://jump.dev/JuMP.jl/v0.22/reference/models/#JuMP.optimizer_with_attributes)
which allows us to append as many attributes as we like, for example:
```jldoctest
julia> using InfiniteOpt, Ipopt
Expand Down Expand Up @@ -98,13 +98,13 @@ All the arguments used with the `InfiniteModel` constructor (e.g., the optimizer
are simply passed on and stored in the optimizer model backend. Thus, any
argument supported by `JuMP.Model` can be passed on to the optimizer
model by including it in the `InfiniteModel` constructor. For example, we can
specify the `caching_mode` keyword argument in the `InfiniteModel` call to use
specify the `add_bridges` keyword argument in the `InfiniteModel` call to use
in the definition of the optimizer model:
```jldoctest
julia> using InfiniteOpt, Ipopt

julia> model = InfiniteModel(Ipopt.Optimizer,
caching_mode = MOIU.MANUAL)
add_bridges = false)
An InfiniteOpt Model
Feasibility problem with:
Finite Parameters: 0
Expand All @@ -113,11 +113,10 @@ Variables: 0
Derivatives: 0
Measures: 0
Optimizer model backend information:
Model mode: MANUAL
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Ipopt
```
Notice that the model mode of the optimizer model is now `MANUAL`.

Moreover, alternative optimizer model types (i.e., not a `TranscriptionModel`) can be
specified via the `OptimizerModel` keyword argument when initializing the
Expand All @@ -144,7 +143,7 @@ Extensions page.
## Supported Optimizers
`InfiniteOpt` can use any optimizer that is supported by `JuMP v0.19.0` or newer
(i.e., has a `MathOptInterface` implementation). Please refer to `JuMP`'s current
[solver documentation](https://jump.dev/JuMP.jl/v0.21.10/installation/#Supported-solvers)
[solver documentation](https://jump.dev/JuMP.jl/v0.22/installation/#Supported-solvers)
to learn what solvers are supported and how to install them.

## Object Dictionaries
Expand All @@ -170,5 +169,5 @@ y(t)
Note that when macro defined objects are deleted from an `InfiniteModel` that the
corresponding symbols in the object dictionary are not removed by default. This
can be accomplished by use of
[`JuMP.unregister`](https://jump.dev/JuMP.jl/v0.21.10/reference/models/#JuMP.unregister)
[`JuMP.unregister`](https://jump.dev/JuMP.jl/v0.22/reference/models/#JuMP.unregister)
(please click on its link for usage information).
4 changes: 2 additions & 2 deletions docs/src/guide/objective.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ measure to be included (e.g., evaluate the expectation of a random variable).

## [Basic Usage] (@id obj_basic)
Principally, the objective function is specified via
[`@objective`](https://jump.dev/JuMP.jl/v0.21.10/reference/objectives/#JuMP.@objective)
[`@objective`](https://jump.dev/JuMP.jl/v0.22/reference/objectives/#JuMP.@objective)
as is done in `JuMP`. For example, let's define the stochastic objective to
minimize ``0.5 x_1 + 0.5 x_2 + \mathbb{E}_\xi [y^2 - y]``:
```jldoctest obj; setup = :(using InfiniteOpt, Distributions; model = InfiniteModel())
Expand Down Expand Up @@ -138,6 +138,6 @@ more efficient at parsing expressions.

!!! note
When possible, the
[`@objective`](https://jump.dev/JuMP.jl/v0.21.10/reference/objectives/#JuMP.@objective)
[`@objective`](https://jump.dev/JuMP.jl/v0.22/reference/objectives/#JuMP.@objective)
since it is more stable and efficient than the `set_objective_[aspect]`
methods due to its enhanced methodology for parsing expressions.
6 changes: 1 addition & 5 deletions docs/src/guide/optimize.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ We can also query the expressions via
[`optimizer_model_expression`](@ref optimizer_model_expression(::JuMP.AbstractJuMPScalar)):
```jldoctest optimize
julia> optimizer_model_expression(z - y^2 + 3) # infinite expression
10-element Vector{Any}:
10-element Vector{AbstractJuMPScalar}:
-y(support: 1)² + z + 3
-y(support: 2)² + z + 3
-y(support: 3)² + z + 3
Expand Down Expand Up @@ -198,18 +198,15 @@ optimizer verbose output. This is accomplished via
exemplified below:
```jldoctest optimize
julia> set_silent(model)
true

julia> unset_silent(model)
false
```

We can also adjust the time limit in a solver independent fashion via
[`set_time_limit_sec`](@ref), [`unset_time_limit_sec`](@ref), and
[`time_limit_sec`](@ref). These methods are illustrated below:
```jldoctest optimize
julia> set_time_limit_sec(model, 100)
100

julia> time_limit_sec(model)
100.0
Expand All @@ -222,7 +219,6 @@ Other optimizer specific settings can be set via
for Ipopt:
```jldoctest optimize
julia> set_optimizer_attribute(model, "max_cpu_time", 60.)
60.0
```
Multiple settings can be specified via [`set_optimizer_attributes`](@ref). For
example, let's specify the tolerance and the maximum number of iterations:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/guide/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ And data, a 2-element Vector{GeneralVariableRef}:
```

See
[`JuMP`'s documentation on containers](https://jump.dev/JuMP.jl/v0.21.10/manual/containers/)
[`JuMP`'s documentation on containers](https://jump.dev/JuMP.jl/v0.22/manual/containers/)
for more information.

## Supports
Expand Down
6 changes: 3 additions & 3 deletions docs/src/guide/result.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Now that the model has been optimized, let's find out what happened. To determin
why the optimizer stopped, we can use
[`termination_status`](@ref) to report the corresponding `MathOptInterface`
termination code (possible codes are explained
[here](https://jump.dev/JuMP.jl/v0.21.10/reference/solutions/#MathOptInterface.TerminationStatusCode).
[here](https://jump.dev/JuMP.jl/v0.22/reference/solutions/#MathOptInterface.TerminationStatusCode).
```jldoctest results
julia> termination_status(model)
LOCALLY_SOLVED::TerminationStatusCode = 4
Expand All @@ -67,7 +67,7 @@ FEASIBLE_POINT::ResultStatusCode = 1
julia> dual_status(model)
FEASIBLE_POINT::ResultStatusCode = 1
```
The possible statuses are detailed [here](https://jump.dev/JuMP.jl/v0.21.10/reference/solutions/#MathOptInterface.ResultStatusCode).
The possible statuses are detailed [here](https://jump.dev/JuMP.jl/v0.22/reference/solutions/#MathOptInterface.ResultStatusCode).
These results are useful in knowing if information can be drawn from the primal
and/or dual and what it means. We can also verify that we indeed have answers
via [`has_values`](@ref) which indicates if our model has optimized variable
Expand Down Expand Up @@ -416,7 +416,7 @@ will generate a [`InfOptSensitivityReport`](@ref) which contains mapping to the
ranges indicating how much a constraint RHS constant or a objective
coefficient can be changed without violating the feasibility of the solution.
This is further explained in the JuMP documentation
[here](https://jump.dev/JuMP.jl/v0.21.10/manual/solutions/#Sensitivity-analysis-for-LP).
[here](https://jump.dev/JuMP.jl/v0.22/manual/solutions/#Sensitivity-analysis-for-LP).
Furthermore, these analysis can only be employed for a solver that implements
`MOI.ConstraintBasisStatus`. In our running example up above, `Ipopt.jl` does not
support this A solver like `Gurobi.jl` does.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/guide/transcribe.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ julia> supports(meas)
()

julia> transcription_expression(y^2 + z - 42)
3-element Vector{Any}:
3-element Vector{AbstractJuMPScalar}:
y(support: 1)² + z - 42
y(support: 2)² + z - 42
y(support: 3)² + z - 42
Expand Down
Loading