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 2 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
94 changes: 94 additions & 0 deletions src/Test/test_conic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5770,6 +5770,100 @@
return
end

function test_conic_PositiveSemidefiniteConeTriangle_4(
model::MOI.ModelLike,
config::Config{T},
) where {T<:Real}
atol = config.atol
rtol = config.rtol
@requires MOI.supports_incremental_interface(model)
@requires MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
)
@requires MOI.supports(model, MOI.ObjectiveSense())
@requires MOI.supports_constraint(
model,
MOI.VectorOfVariables,
MOI.PositiveSemidefiniteConeTriangle,
)
@requires MOI.supports_constraint(
model,
MOI.ScalarAffineFunction{T},
MOI.EqualTo{T},
)
@requires MOI.supports_constraint(
model,
MOI.ScalarAffineFunction{T},
MOI.GreaterThan{T},
)

x, cx = MOI.add_constrained_variables(
model,
MOI.PositiveSemidefiniteConeTriangle(2),
)
y, cy = MOI.add_constrained_variables(
model,
MOI.PositiveSemidefiniteConeTriangle(2),
)
c1 = MOI.add_constraint(
model,
sum(1.0 .* x) - sum(1.0 .* y),
MOI.EqualTo(0.0),
odow marked this conversation as resolved.
Show resolved Hide resolved
)
c2 =
MOI.add_constraint(model, 1.0 * y[1] + 1.0 * y[3], MOI.GreaterThan(1.0))
obj = 1.0 * x[1] + 1.0 * x[3]
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(model, MOI.ObjectiveFunction{typeof(obj)}(), obj)
if _supports(config, MOI.optimize!)
@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
if _supports(config, MOI.ConstraintDual)
@test MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT

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

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5820-L5825

Added lines #L5820 - L5825 were not covered by tests
end
@test MOI.get.(model, MOI.VariablePrimal(), x) ≈ ones(3) ./ T(6) atol =

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

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5827

Added line #L5827 was not covered by tests
atol rtol = rtol
@test MOI.get.(model, MOI.VariablePrimal(), y) ≈ [1, -1, 1] ./ T(2) atol =

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

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5829

Added line #L5829 was not covered by tests
atol rtol = rtol
if _supports(config, MOI.ConstraintDual)
@test MOI.get(model, MOI.ConstraintDual(), cx) ≈ [1, -1, 1] ./ T(3) atol =

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

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5831-L5832

Added lines #L5831 - L5832 were not covered by tests
atol rtol = rtol
@test MOI.get(model, MOI.ConstraintDual(), cy) ≈ ones(3) ./ T(3) atol =

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

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5834

Added line #L5834 was not covered by tests
atol rtol = rtol
@test MOI.get(model, MOI.ConstraintDual(), c1) ≈ T(2) / T(3) atol =

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

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5836

Added line #L5836 was not covered by tests
atol rtol = rtol
@test MOI.get(model, MOI.ConstraintDual(), c2) ≈ T(1) / T(3) atol =

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

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5838

Added line #L5838 was not covered by tests
atol rtol = rtol
end
end
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 setup_test(

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
::typeof(test_conic_PositiveSemidefiniteConeTriangle_4),
model::MOIU.MockOptimizer,
::Config{T},
) where {T<:Real}
MOIU.set_mock_optimize!(

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

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5852

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

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

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5854

Added line #L5854 was not covered by tests
mock,
[[1, 1, 1] / T(6); [1, -1, 1] / T(2)],
(MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeTriangle) =>
[[1, -1, 1] ./ T(3), ones(3) ./ T(3)],
(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 5864 in src/Test/test_conic.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_conic.jl#L5864

Added line #L5864 was not covered by tests
end

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