Skip to content

Commit b8b4627

Browse files
odowpulsipher
andauthored
Fix printing test for JuMP v1.23.0 (infiniteopt#361)
* Fix printing test for JuMP v1.23.0 * More updates for printing in JuMP v1.23 * minor fixes * Typo fix --------- Co-authored-by: pulsipher <[email protected]>
1 parent 9f146c9 commit b8b4627

File tree

13 files changed

+218
-194
lines changed

13 files changed

+218
-194
lines changed

docs/Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ InfiniteOpt = "0.5"
1919
Ipopt = "1.6"
2020
HiGHS = "1"
2121
julia = "1.6"
22-
JuMP = "1.22"
22+
JuMP = "1.23"
2323
Literate = "2.18"
2424
Plots = "1"
2525
SpecialFunctions = "2"

docs/src/guide/measure.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ tmodel = transformation_model(model);
342342
343343
# output
344344
A JuMP Model
345-
Minimization problem with:
346-
Variables: 3
347-
Objective function type: QuadExpr
348-
Model mode: AUTOMATIC
349-
CachingOptimizer state: NO_OPTIMIZER
350-
Solver name: No optimizer attached.
345+
├ solver: none
346+
├ objective_sense: MIN_SENSE
347+
│ └ objective_function_type: QuadExpr
348+
├ num_variables: 3
349+
├ num_constraints: 0
350+
└ Names registered in the model: none
351351
352352
```
353353

@@ -384,12 +384,12 @@ trans_m = transformation_model(model);
384384
385385
# output
386386
A JuMP Model
387-
Minimization problem with:
388-
Variables: 5
389-
Objective function type: QuadExpr
390-
Model mode: AUTOMATIC
391-
CachingOptimizer state: NO_OPTIMIZER
392-
Solver name: No optimizer attached.
387+
├ solver: none
388+
├ objective_sense: MIN_SENSE
389+
│ └ objective_function_type: QuadExpr
390+
├ num_variables: 5
391+
├ num_constraints: 0
392+
└ Names registered in the model: none
393393
394394
```
395395
Now let's look again at the number of supports, the transcription of `u`, and the
@@ -442,12 +442,12 @@ tmodel = transformation_model(model);
442442
443443
# output
444444
A JuMP Model
445-
Minimization problem with:
446-
Variables: 2
447-
Objective function type: QuadExpr
448-
Model mode: AUTOMATIC
449-
CachingOptimizer state: NO_OPTIMIZER
450-
Solver name: No optimizer attached.
445+
├ solver: none
446+
├ objective_sense: MIN_SENSE
447+
│ └ objective_function_type: QuadExpr
448+
├ num_variables: 2
449+
├ num_constraints: 0
450+
└ Names registered in the model: none
451451
452452
```
453453
Then we get the supports are consistent for `u` and the integral:

docs/src/guide/model.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Feasibility problem with:
3232
Measures: 0
3333
Transformation backend information:
3434
Backend type: TranscriptionBackend
35-
Solver name: No optimizer attached.
35+
Solver: none
3636
Transformation built and up-to-date: false
3737
```
3838
Ultimately, `model` will be solved via a transformation backend. By default,
@@ -52,7 +52,7 @@ Feasibility problem with:
5252
Measures: 0
5353
Transformation backend information:
5454
Backend type: TranscriptionBackend
55-
Solver name: No optimizer attached.
55+
Solver: none
5656
Transformation built and up-to-date: false
5757
```
5858

@@ -72,7 +72,7 @@ Feasibility problem with:
7272
Measures: 0
7373
Transformation backend information:
7474
Backend type: TranscriptionBackend
75-
Solver name: Ipopt
75+
Solver: Ipopt
7676
Transformation built and up-to-date: false
7777
```
7878
For completeness, the table of currently supported JuMP compatible optimizers
@@ -96,7 +96,7 @@ Feasibility problem with:
9696
Measures: 0
9797
Transformation backend information:
9898
Backend type: TranscriptionBackend
99-
Solver name: Ipopt
99+
Solver: Ipopt
100100
Transformation built and up-to-date: false
101101
```
102102

@@ -120,11 +120,11 @@ julia> using InfiniteOpt, Ipopt
120120
julia> backend = TranscriptionBackend(Ipopt.Optimizer)
121121
A TranscriptionBackend that uses a
122122
A JuMP Model
123-
Feasibility problem with:
124-
Variables: 0
125-
Model mode: AUTOMATIC
126-
CachingOptimizer state: EMPTY_OPTIMIZER
127-
Solver name: Ipopt
123+
├ solver: Ipopt
124+
├ objective_sense: FEASIBILITY_SENSE
125+
├ num_variables: 0
126+
├ num_constraints: 0
127+
└ Names registered in the model: none
128128
```
129129

130130
We query the underlying transformation backend, transformation model, and transformation
@@ -137,19 +137,19 @@ julia> using InfiniteOpt; model = InfiniteModel();
137137
julia> tbackend = transformation_backend(model)
138138
A TranscriptionBackend that uses a
139139
A JuMP Model
140-
Feasibility problem with:
141-
Variables: 0
142-
Model mode: AUTOMATIC
143-
CachingOptimizer state: NO_OPTIMIZER
144-
Solver name: No optimizer attached.
140+
├ solver: none
141+
├ objective_sense: FEASIBILITY_SENSE
142+
├ num_variables: 0
143+
├ num_constraints: 0
144+
└ Names registered in the model: none
145145
146146
julia> tmodel = transformation_model(model)
147147
A JuMP Model
148-
Feasibility problem with:
149-
Variables: 0
150-
Model mode: AUTOMATIC
151-
CachingOptimizer state: NO_OPTIMIZER
152-
Solver name: No optimizer attached.
148+
├ solver: none
149+
├ objective_sense: FEASIBILITY_SENSE
150+
├ num_variables: 0
151+
├ num_constraints: 0
152+
└ Names registered in the model: none
153153
154154
julia> data = transformation_data(model);
155155
```
@@ -163,11 +163,11 @@ julia> set_transformation_backend(model, TranscriptionBackend(Ipopt.Optimizer))
163163
julia> tbackend = transformation_backend(model)
164164
A TranscriptionBackend that uses a
165165
A JuMP Model
166-
Feasibility problem with:
167-
Variables: 0
168-
Model mode: AUTOMATIC
169-
CachingOptimizer state: EMPTY_OPTIMIZER
170-
Solver name: Ipopt
166+
├ solver: Ipopt
167+
├ objective_sense: FEASIBILITY_SENSE
168+
├ num_variables: 0
169+
├ num_constraints: 0
170+
└ Names registered in the model: none
171171
```
172172
Again, since `TranscriptionBackend` is the default, the following models are equivalent:
173173
```jldoctest
@@ -187,7 +187,7 @@ Feasibility problem with:
187187
Measures: 0
188188
Transformation backend information:
189189
Backend type: TranscriptionBackend
190-
Solver name: Ipopt
190+
Solver: Ipopt
191191
Transformation built and up-to-date: false
192192
```
193193

docs/src/guide/optimize.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,27 @@ let's extract the transformation backend from the example above in the basic usa
9797
julia> backend = transformation_backend(model)
9898
A TranscriptionBackend that uses a
9999
A JuMP Model
100-
Minimization problem with:
101-
Variables: 11
102-
Objective function type: AffExpr
103-
`AffExpr`-in-`MathOptInterface.EqualTo{Float64}`: 1 constraint
104-
`AffExpr`-in-`MathOptInterface.GreaterThan{Float64}`: 10 constraints
105-
`VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 11 constraints
106-
Model mode: AUTOMATIC
107-
CachingOptimizer state: ATTACHED_OPTIMIZER
108-
Solver name: Ipopt
100+
├ solver: Ipopt
101+
├ objective_sense: MIN_SENSE
102+
│ └ objective_function_type: AffExpr
103+
├ num_variables: 11
104+
├ num_constraints: 22
105+
│ ├ AffExpr in MOI.EqualTo{Float64}: 1
106+
│ ├ AffExpr in MOI.GreaterThan{Float64}: 10
107+
│ └ VariableRef in MOI.GreaterThan{Float64}: 11
108+
└ Names registered in the model: none
109109
110110
julia> tmodel = transformation_model(model)
111111
A JuMP Model
112-
Minimization problem with:
113-
Variables: 11
114-
Objective function type: AffExpr
115-
`AffExpr`-in-`MathOptInterface.EqualTo{Float64}`: 1 constraint
116-
`AffExpr`-in-`MathOptInterface.GreaterThan{Float64}`: 10 constraints
117-
`VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 11 constraints
118-
Model mode: AUTOMATIC
119-
CachingOptimizer state: ATTACHED_OPTIMIZER
120-
Solver name: Ipopt
112+
├ solver: Ipopt
113+
├ objective_sense: MIN_SENSE
114+
│ └ objective_function_type: AffExpr
115+
├ num_variables: 11
116+
├ num_constraints: 22
117+
│ ├ AffExpr in MOI.EqualTo{Float64}: 1
118+
│ ├ AffExpr in MOI.GreaterThan{Float64}: 10
119+
│ └ VariableRef in MOI.GreaterThan{Float64}: 11
120+
└ Names registered in the model: none
121121
```
122122

123123
The `JuMP` variable(s) stored in the transformation backend that correspond to a

docs/src/guide/transcribe.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ julia> build_transformation_backend!(inf_model)
6868
6969
julia> trans_model = transformation_model(inf_model)
7070
A JuMP Model
71-
Minimization problem with:
72-
Variables: 4
73-
Objective function type: AffExpr
74-
`AffExpr`-in-`MathOptInterface.EqualTo{Float64}`: 1 constraint
75-
`QuadExpr`-in-`MathOptInterface.LessThan{Float64}`: 3 constraints
76-
`VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 3 constraints
77-
`VariableRef`-in-`MathOptInterface.ZeroOne`: 1 constraint
78-
Model mode: AUTOMATIC
79-
CachingOptimizer state: NO_OPTIMIZER
80-
Solver name: No optimizer attached.
71+
├ solver: none
72+
├ objective_sense: MIN_SENSE
73+
│ └ objective_function_type: AffExpr
74+
├ num_variables: 4
75+
├ num_constraints: 8
76+
│ ├ AffExpr in MOI.EqualTo{Float64}: 1
77+
│ ├ QuadExpr in MOI.LessThan{Float64}: 3
78+
│ ├ VariableRef in MOI.GreaterThan{Float64}: 3
79+
│ └ VariableRef in MOI.ZeroOne: 1
80+
└ Names registered in the model: none
8181
8282
julia> print(trans_model)
8383
Min 2 z + y(0.0) + y(5.0) + y(10.0)
@@ -357,27 +357,27 @@ which wraps [`build_transcription_backend!`](@ref InfiniteOpt.TranscriptionOpt.b
357357
julia> backend1 = TranscriptionBackend() # make an empty backend
358358
A TranscriptionBackend that uses a
359359
A JuMP Model
360-
Feasibility problem with:
361-
Variables: 0
362-
Model mode: AUTOMATIC
363-
CachingOptimizer state: NO_OPTIMIZER
364-
Solver name: No optimizer attached.
360+
├ solver: none
361+
├ objective_sense: FEASIBILITY_SENSE
362+
├ num_variables: 0
363+
├ num_constraints: 0
364+
└ Names registered in the model: none
365365
366366
julia> build_transformation_backend!(inf_model);
367367
368368
julia> backend2 = transformation_backend(inf_model) # generate from an InfiniteModel
369369
A TranscriptionBackend that uses a
370370
A JuMP Model
371-
Minimization problem with:
372-
Variables: 4
373-
Objective function type: AffExpr
374-
`AffExpr`-in-`MathOptInterface.EqualTo{Float64}`: 1 constraint
375-
`QuadExpr`-in-`MathOptInterface.LessThan{Float64}`: 3 constraints
376-
`VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 3 constraints
377-
`VariableRef`-in-`MathOptInterface.ZeroOne`: 1 constraint
378-
Model mode: AUTOMATIC
379-
CachingOptimizer state: NO_OPTIMIZER
380-
Solver name: No optimizer attached.
371+
├ solver: none
372+
├ objective_sense: MIN_SENSE
373+
│ └ objective_function_type: AffExpr
374+
├ num_variables: 4
375+
├ num_constraints: 8
376+
│ ├ AffExpr in MOI.EqualTo{Float64}: 1
377+
│ ├ QuadExpr in MOI.LessThan{Float64}: 3
378+
│ ├ VariableRef in MOI.GreaterThan{Float64}: 3
379+
│ └ VariableRef in MOI.ZeroOne: 1
380+
└ Names registered in the model: none
381381
```
382382
The call to `build_transformation_backend!` is the backbone
383383
behind infinite model transformation and is what encapsulates all the methods to
@@ -391,11 +391,11 @@ via [`transformation_model`](@ref):
391391
```jldoctest transcribe; setup = :(empty!(inf_model.backend))
392392
julia> transformation_model(inf_model)
393393
A JuMP Model
394-
Feasibility problem with:
395-
Variables: 0
396-
Model mode: AUTOMATIC
397-
CachingOptimizer state: NO_OPTIMIZER
398-
Solver name: No optimizer attached.
394+
├ solver: none
395+
├ objective_sense: FEASIBILITY_SENSE
396+
├ num_variables: 0
397+
├ num_constraints: 0
398+
└ Names registered in the model: none
399399
```
400400
Here we observe that such a model is currently empty and hasn't been populated
401401
yet.

docs/src/tutorials/quick_start.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Feasibility problem with:
7272
Measures: 0
7373
Transformation backend information:
7474
Backend type: TranscriptionBackend
75-
Solver name: Ipopt
75+
Solver: Ipopt
7676
Transformation built and up-to-date: false
7777
```
7878
Learn more about `InfiniteModel`s and optimizers on our

src/TranscriptionOpt/model.jl

+15-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ function TranscriptionBackend(optimizer_constructor; kwargs...)
130130
return InfiniteOpt.JuMPBackend{Transcription}(model, TranscriptionData())
131131
end
132132

133+
# Get the solver name from MOI
134+
# Inspired by https://github.com/jump-dev/JuMP.jl/blob/ce946b7092c45bdac916c9b531a13a5b929d45f0/src/print.jl#L281-L291
135+
function _try_solver_name(model)
136+
if mode(model) != JuMP.DIRECT &&
137+
MOI.Utilities.state(backend(model)) == MOI.Utilities.NO_OPTIMIZER
138+
return "none"
139+
end
140+
try
141+
return MOI.get(backend(model), MOI.SolverName())
142+
catch
143+
return "unknown"
144+
end
145+
end
146+
133147
# Printing
134148
function JuMP.show_backend_summary(
135149
io::IO,
@@ -148,9 +162,7 @@ function JuMP.show_backend_summary(
148162
# TODO add approximation method info (requires InfiniteOpt refactoring)
149163
end
150164
# solver name
151-
moi_summary = sprint(JuMP.show_backend_summary, backend.model)
152-
solver_str = filter(startswith("Solver"), split(moi_summary, "\n"))[1]
153-
println(io, " ", solver_str)
165+
println(io, " Solver: ", _try_solver_name(backend.model))
154166
return
155167
end
156168

0 commit comments

Comments
 (0)