Skip to content

Commit 12bba95

Browse files
committed
Always alias the parameter storage of the inner model
Sharing only when the inner model is a Nonlinear.Model silently left qp.parameters empty for any other inner model type. Assume instead that the inner model exposes its parameter values as parameters::Vector{T}, like Nonlinear.Model does, and always alias it; an inner model without that field fails loudly at construction.
1 parent 00f3978 commit 12bba95

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

src/Nonlinear/model_with_quad.jl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ everything else to the `inner` model, typically a [`Model`](@ref).
2121
Add variables with `MOI.add_variable`: the layer guarantees that the variable
2222
indices are `1:n`, like `MOI.Utilities.MatrixOfConstraints`. Add parameters
2323
with `MOI.add_constrained_variable(model, ::MOI.Parameter)`: parameters get
24-
indices offset by [`_PARAMETER_OFFSET`](@ref), their values are stored in the
25-
inner model through [`add_parameter`](@ref), and `qp.parameters` aliases that
26-
storage, so a parameter update is visible to both blocks.
24+
indices offset by [`_PARAMETER_OFFSET`](@ref), and their values are stored in
25+
the inner model through [`add_parameter`](@ref). The inner model must expose
26+
that storage as `parameters::Vector{T}`, like [`Model`](@ref) does:
27+
`qp.parameters` aliases it, so a parameter update is visible to both blocks.
2728
2829
Add constraints with [`add_constraint`](@ref) or `MOI.add_constraint`, and
2930
set the objective with [`set_objective`](@ref): affine and quadratic
@@ -53,7 +54,10 @@ mutable struct ModelWithQuad{T,M}
5354
inner,
5455
objective_sink,
5556
)
56-
_share_parameters(model.qp, model.inner)
57+
# The QP block reads the parameter values from the storage of the
58+
# inner model, which must expose them as `parameters::Vector{T}`,
59+
# like [`Model`](@ref) does.
60+
model.qp.parameters = inner.parameters
5761
return model
5862
end
5963
end
@@ -64,14 +68,6 @@ end
6468

6569
ModelWithQuad(inner) = ModelWithQuad{Float64}(inner)
6670

67-
# The QP block reads the parameter values from the inner model's storage.
68-
_share_parameters(::QPBlockData, ::Any) = nothing
69-
70-
function _share_parameters(qp::QPBlockData{Float64}, inner::Model)
71-
qp.parameters = inner.parameters
72-
return
73-
end
74-
7571
# The variables and the parameters.
7672

7773
MOI.add_variable(model::ModelWithQuad) = MOI.add_variable(model.variables)

0 commit comments

Comments
 (0)