Skip to content

Commit 4448a46

Browse files
committed
simplify method setting to sue model constructor
1 parent a636915 commit 4448a46

File tree

2 files changed

+5
-50
lines changed

2 files changed

+5
-50
lines changed

src/DiffOpt.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ function add_all_model_constructors(model)
4040
return
4141
end
4242

43-
function add_conic_model_constructor(model)
44-
add_model_constructor(model, ConicProgram.Model)
45-
return
46-
end
47-
48-
function add_quadratic_model_constructor(model)
49-
add_model_constructor(model, QuadraticProgram.Model)
50-
return
51-
end
52-
5343
export diff_optimizer
5444

5545
end # module

src/moi_wrapper.jl

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,6 @@
33
# Use of this source code is governed by an MIT-style license that can be found
44
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
55

6-
"""
7-
DiffMethod
8-
9-
An enum to define the differentiation method.
10-
11-
## Values
12-
13-
Possible values are:
14-
15-
* [`DIFF_AUTOMATIC`]: Automatic differentiation: tries all differentiation methods and chooses the first that works. This can be slower than manually choosing a method.
16-
* [`DIFF_CONIC`]: Conic optimization based differentiation: works for conic programs or programs that can be transformed into conic programs by JuMP.
17-
* [`DIFF_QUADRATIC`]: Quadratic optimization based differentiation: works for quadratic programs or programs that can be transformed into conic programs by JuMP.
18-
"""
19-
@enum(DiffMethod, DIFF_AUTOMATIC, DIFF_CONIC, DIFF_QUADRATIC)
20-
21-
@doc(
22-
"Automatic differentiation: tries all differentiation methods and chooses the first that works. This can be slower than manually choosing a method.",
23-
DIFF_AUTOMATIC
24-
)
25-
26-
@doc(
27-
"Conic optimization based differentiation: works for conic programs or programs that can be transformed into conic programs by JuMP.",
28-
DIFF_CONIC
29-
)
30-
31-
@doc(
32-
"Quadratic optimization based differentiation: works for quadratic programs or programs that can be transformed into conic programs by JuMP.",
33-
DIFF_QUADRATIC
34-
)
35-
366
"""
377
diff_optimizer(optimizer_constructor)
388
@@ -53,7 +23,7 @@ julia> model.add_constraint(model, ...)
5323
"""
5424
function diff_optimizer(
5525
optimizer_constructor;
56-
method = DIFF_AUTOMATIC,
26+
method = nothing,
5727
with_parametric_opt_interface::Bool = false,
5828
with_bridge_type = Float64,
5929
with_cache::Bool = true,
@@ -97,18 +67,13 @@ mutable struct Optimizer{OT<:MOI.ModelLike} <: MOI.AbstractOptimizer
9767

9868
function Optimizer(
9969
optimizer::OT;
100-
method = DIFF_AUTOMATIC,
70+
method = nothing,
10171
) where {OT<:MOI.ModelLike}
10272
output =
10373
new{OT}(optimizer, Any[], nothing, nothing, nothing, InputCache())
104-
if method == DIFF_CONIC
105-
add_conic_model_constructor(output)
106-
elseif method == DIFF_QUADRATIC
107-
add_quadratic_model_constructor(output)
108-
elseif method == DIFF_AUTOMATIC
109-
add_all_model_constructors(output)
110-
else
111-
add_model_constructor(output, method)
74+
add_all_model_constructors(output)
75+
if method !== nothing
76+
output.model_constructor = method
11277
end
11378
return output
11479
end

0 commit comments

Comments
 (0)