Skip to content

Commit

Permalink
Discourage Finite Models (#151)
Browse files Browse the repository at this point in the history
* Fix bug and discourage finite models

* Update finite model warning location
  • Loading branch information
pulsipher committed Jun 21, 2021
1 parent d4f69c7 commit a275ada
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/src/guide/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ measures, objective, constraints, and all other data used in `InfiniteOpt`. This
differs from `JuMP` models which store such information in a `MathOptInterface`
model backend.

!!! note
`InfiniteOpt`'s `InfiniteModel`s are intended to be used for
infinite-dimensional optimization problems. Finite problems (e.g.,
directly modeling a discrete time model) should instead be modeled using
`Model`'s in [`JuMP`](https://jump.dev/JuMP.jl/stable/).

## Basic Usage
Infinite models can be initialized with no arguments by default:
```jldoctest
Expand Down
5 changes: 5 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ include:
- Measures (e.g., ``\int_{t \in \mathcal{D}_t}y(t,x) dt``, ``\mathbb{E}[y(\xi)]``)
- More

!!! note
`InfiniteOpt` is intended to be used for infinite-dimensional optimization
problems. Finite problems (e.g., directly modeling a discrete time model)
should instead be modeled using [`JuMP`](https://jump.dev/JuMP.jl/stable/).

Moreover, `InfiniteOpt` decouples the infinite-dimensional formulations from the
finite transformations typically used to solve them. This readily enables diverse
techniques be used to solve these types of problems. By default, we employ
Expand Down
2 changes: 1 addition & 1 deletion src/TranscriptionOpt/transcribe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ function build_transcription_model!(
set_parameter_supports(trans_model, inf_model)
# check that there isn't a crazy amount of supports from taking the product
supps = parameter_supports(trans_model)
num_supps = prod(length, supps)
num_supps = isempty(supps) ? 0 : prod(length, supps)
if check_support_dims && length(supps) > 1 && num_supps > 15000 # NOTE this is an arbitrary cutoff
@warn("Due to necessarily considering the combinatorics of independent " *
"parameter supports, the model will be transcripted over up to $(num_supps) " *
Expand Down
10 changes: 7 additions & 3 deletions src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,13 @@ true
```
"""
function build_optimizer_model!(model::InfiniteModel; kwargs...)
key = optimizer_model_key(model)
build_optimizer_model!(model, Val(key); kwargs...)
return
if num_parameters(model, InfiniteParameter) == 0
@warn("Finite models (i.e., `InfiniteModel`s with no infinite " *
"parameters) should be modeled directly via a `Model` in JuMP.jl.")
end
key = optimizer_model_key(model)
build_optimizer_model!(model, Val(key); kwargs...)
return
end

################################################################################
Expand Down
10 changes: 10 additions & 0 deletions test/TranscriptionOpt/transcribe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,14 @@ end
@test transcription_constraint(FixRef(y)) isa Vector{ConstraintRef}
@test transcription_constraint(BinaryRef(y)) isa Vector{ConstraintRef}
@test transcription_constraint(UpperBoundRef(d1)) == UpperBoundRef.(d1t)

# test a finite model
m = InfiniteModel()
@variable(m, y >= 0)
@objective(m, Min, y)
tm = transcription_model(m)
@test IOTO.build_transcription_model!(tm, m) isa Nothing
@test transcription_variable(y) isa VariableRef
@test lower_bound(transcription_variable(y)) == 0
@test objective_sense(tm) == MOI.MIN_SENSE
end
7 changes: 7 additions & 0 deletions test/optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
@test isa(build_optimizer_model!(m), Nothing)
@test optimizer_model_ready(m)
@test num_variables(optimizer_model(m)) == 14
# test finite model
m = InfiniteModel()
@variable(m, y >= 0)
@objective(m, Min, y)
warn = "Finite models (i.e., `InfiniteModel`s with no infinite " *
"parameters) should be modeled directly via a `Model` in JuMP.jl."
@test_logs (:warn, warn) build_optimizer_model!(m)
end

# Test optimizer model querying methods
Expand Down

0 comments on commit a275ada

Please sign in to comment.