Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test with multiple PSD variables on same constraint #2594

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/Test/test_conic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5770,6 +5770,95 @@
return
end

# Test with multiple PSD variable on the same constraint in order to catch
# https://github.com/jump-dev/MosekTools.jl/issues/139
function test_conic_PositiveSemidefiniteConeTriangle_4(
model::MOI.ModelLike,
config::Config{T},
) where {T<:Real}
@requires MOI.supports_incremental_interface(model)
@requires _supports(config, MOI.optimize!)
@requires MOI.supports(

Check warning on line 5781 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5781

Added line #L5781 was not covered by tests
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
)
@requires MOI.supports(model, MOI.ObjectiveSense())
@requires MOI.supports_constraint(

Check warning on line 5786 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5785-L5786

Added lines #L5785 - L5786 were not covered by tests
model,
MOI.VectorOfVariables,
MOI.PositiveSemidefiniteConeTriangle,
)
@requires MOI.supports_constraint(

Check warning on line 5791 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5791

Added line #L5791 was not covered by tests
model,
MOI.ScalarAffineFunction{T},
MOI.EqualTo{T},
)
@requires MOI.supports_constraint(

Check warning on line 5796 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5796

Added line #L5796 was not covered by tests
model,
MOI.ScalarAffineFunction{T},
MOI.GreaterThan{T},
)
x, cx = MOI.add_constrained_variables(

Check warning on line 5801 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5801

Added line #L5801 was not covered by tests
model,
MOI.PositiveSemidefiniteConeTriangle(2),
)
y, cy = MOI.add_constrained_variables(

Check warning on line 5805 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5805

Added line #L5805 was not covered by tests
model,
MOI.PositiveSemidefiniteConeTriangle(2),
)
c1 = MOI.add_constraint(

Check warning on line 5809 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5809

Added line #L5809 was not covered by tests
model,
sum(one(T) .* x) - sum(one(T) .* y),
MOI.EqualTo(zero(T)),
)
c2 = MOI.add_constraint(

Check warning on line 5814 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5814

Added line #L5814 was not covered by tests
model,
one(T) * y[1] + one(T) * y[3],
MOI.GreaterThan(one(T)),
)
obj = one(T) * x[1] + one(T) * x[3]
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(model, MOI.ObjectiveFunction{typeof(obj)}(), obj)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED
MOI.optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT
x_primal = MOI.get.(model, MOI.VariablePrimal(), x)
@test ≈(x_primal, ones(T, 3) ./ T(6), config)
y_primal = MOI.get.(model, MOI.VariablePrimal(), y)
@test ≈(y_primal, T[1, -1, 1] ./ T(2), config)
if _supports(config, MOI.ConstraintDual)
@test MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
x_dual = MOI.get(model, MOI.ConstraintDual(), cx)
@test ≈(x_dual, [1, -1, 1] ./ T(3), config)
y_dual = MOI.get(model, MOI.ConstraintDual(), cy)
@test ≈(y_dual, ones(T, 3) ./ T(3), config)
@test ≈(MOI.get(model, MOI.ConstraintDual(), c1), T(2) / T(3), config)
@test ≈(MOI.get(model, MOI.ConstraintDual(), c2), T(1) / T(3), config)

Check warning on line 5837 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5819-L5837

Added lines #L5819 - L5837 were not covered by tests
end
return

Check warning on line 5839 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5839

Added line #L5839 was not covered by tests
end

function setup_test(

Check warning on line 5842 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5842

Added line #L5842 was not covered by tests
::typeof(test_conic_PositiveSemidefiniteConeTriangle_4),
model::MOIU.MockOptimizer,
::Config{T},
) where {T<:Real}
MOIU.set_mock_optimize!(

Check warning on line 5847 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5847

Added line #L5847 was not covered by tests
model,
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(

Check warning on line 5849 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5849

Added line #L5849 was not covered by tests
mock,
T[[1, 1, 1] / T(6); [1, -1, 1] / T(2)],
(MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeTriangle) =>
T[[1, -1, 1]./T(3), ones(T, 3)./T(3)],
odow marked this conversation as resolved.
Show resolved Hide resolved
(MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}) => [T(2) / T(3)],
(MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}) =>
[T(1) / T(3)],
),
)
return

Check warning on line 5859 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5859

Added line #L5859 was not covered by tests
end

"""
_test_det_cone_helper_ellipsoid(
model::MOI.ModelLike,
Expand Down
Loading