Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Mar 15, 2024
1 parent 8af724e commit f57eade
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/QCQP/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ function _subs_ensure_moi_order(p::PolyJuMP.ScalarPolynomialFunction, old, new)
return PolyJuMP.ScalarPolynomialFunction(poly, moi_vars)

Check warning on line 232 in src/QCQP/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/QCQP/MOI_wrapper.jl#L232

Added line #L232 was not covered by tests
end


function _subs!(
p::PolyJuMP.ScalarPolynomialFunction,
index_to_var::Dict{K,V},
Expand Down
2 changes: 1 addition & 1 deletion src/nl_to_polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ end

function _scalar_polynomial(d::Dict{K,V}, ::Type{T}, poly) where {T,K,V}
var_set = Set(MP.variables(poly))
variable_map = Tuple{K, V}[(k, v) for (k, v) in d if v in var_set]
variable_map = Tuple{K,V}[(k, v) for (k, v) in d if v in var_set]
sort!(variable_map, by = x -> x[2], rev = true)
variables = [x[1] for x in variable_map]
P = MP.polynomial_type(V, T)
Expand Down
10 changes: 4 additions & 6 deletions test/qcqp_extra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ function test_unconstrained_before_projection(T)
() -> PolyJuMP.QCQP.Optimizer{T}(optimizer),
)
PolyJuMP.@variable(model, -1 <= a[1:2] <= 1)
PolyJuMP.@objective(model, Min, a[1]^2*a[2]^2)
PolyJuMP.@objective(model, Min, a[1]^2 * a[2]^2)
PolyJuMP.optimize!(model)

vis = MOI.get(inner, MOI.ListOfVariableIndices())
@test length(vis) == 4

F = MOI.ScalarQuadraticFunction{T}
S = MOI.EqualTo{T}
cis = MOI.get(inner, MOI.ListOfConstraintIndices{F,S}())
Expand All @@ -35,12 +34,11 @@ function test_unconstrained_after_projection(T)
() -> PolyJuMP.QCQP.Optimizer{T}(optimizer),
)
PolyJuMP.@variable(model, -1 <= a <= 1)
PolyJuMP.@objective(model, Min, a^2)
PolyJuMP.@objective(model, Min, a^2)
PolyJuMP.optimize!(model)

vis = MOI.get(inner, MOI.ListOfVariableIndices())
@test length(vis) == 1

F = MOI.ScalarQuadraticFunction{T}
S = MOI.EqualTo{T}
cis = MOI.get(inner, MOI.ListOfConstraintIndices{F,S}())
Expand All @@ -60,7 +58,7 @@ function test_subs!_preserves_moi_sync(xs, ys, T)

mask = rand(Bool, length(xs))
is = Random.shuffle(eachindex(xs)[mask])
index = Dict{eltype(mois), eltype(xs)}(zip(mois[is], ys[is]))
index = Dict{eltype(mois),eltype(xs)}(zip(mois[is], ys[is]))

moi_map = Dict(zip(xs, mois))
moivars = [moi_map[v] for v in MP.variables(p)]
Expand Down Expand Up @@ -171,4 +169,4 @@ import TypedPolynomials
types = [Float64, BigFloat, Rational{BigInt}]
samples = 10
TestQCQPExtra.run_tests_subs(z, w, samples, types)
end
end

0 comments on commit f57eade

Please sign in to comment.