|
| 1 | +# Copyright (c) 2018-2024: Charlie Vanaret and contributors |
| 2 | +# |
| 3 | +# Use of this source code is governed by an MIT-style license that can be found |
| 4 | +# in the LICENSE.md file or at https://opensource.org/licenses/MIT. |
| 5 | + |
| 6 | +# For help with this file, please contact `@odow` on GitHub. |
| 7 | + |
| 8 | +using Test |
| 9 | + |
| 10 | +import AmplNLWriter |
| 11 | +import MathOptInterface as MOI |
| 12 | +import MINLPTests |
| 13 | +import Uno_jll |
| 14 | + |
| 15 | +""" |
| 16 | + Optimizer() |
| 17 | +
|
| 18 | +Create a new `AmplNLWriter.Optimizer` object that uses Uno as the backing |
| 19 | +solver. |
| 20 | +""" |
| 21 | +function Optimizer() |
| 22 | + options = String["logger=SILENT"] |
| 23 | + return AmplNLWriter.Optimizer(Uno_jll.amplexe, options) |
| 24 | +end |
| 25 | + |
| 26 | +# This testset runs https://github.com/jump-dev/MINLPTests.jl |
| 27 | +@testset "MINLPTests" begin |
| 28 | + primal_target = Dict( |
| 29 | + MINLPTests.FEASIBLE_PROBLEM => MOI.FEASIBLE_POINT, |
| 30 | + # If Uno starts writing a .sol file with an infeasible point, change |
| 31 | + # this to `=> MOI.INFEASIBLE_POINT` |
| 32 | + MINLPTests.INFEASIBLE_PROBLEM => MOI.NO_SOLUTION, |
| 33 | + ) |
| 34 | + # This function tests (potentially) non-convex nonlinear programs. The tests |
| 35 | + # are meant to be "easy" in the sense that most NLP solvers can find the |
| 36 | + # same global minimum, but a test failure can sometimes be allowed. |
| 37 | + MINLPTests.test_nlp_expr(; |
| 38 | + exclude = [ |
| 39 | + # Remove once https://github.com/cvanaret/Uno/issues/39 is fixed |
| 40 | + "005_010", |
| 41 | + # Okay to exclude forever: AmplNLWriter does not support |
| 42 | + # user-defined functions. |
| 43 | + "006_010", |
| 44 | + # Remove once https://github.com/cvanaret/Uno/issues/38 is fixed |
| 45 | + "007_010", |
| 46 | + ], |
| 47 | + primal_target = primal_target, |
| 48 | + ) do |
| 49 | + return |
| 50 | + end |
| 51 | + # This function tests convex nonlinear programs. Test failures here should |
| 52 | + # never be allowed, because even local NLP solvers should find the global |
| 53 | + # optimum. |
| 54 | + MINLPTests.test_nlp_cvx_expr(; primal_target) do |
| 55 | + return AmplNLWriter.Optimizer(Uno_jll.amplexe, ["logger=SILENT"]) |
| 56 | + end |
| 57 | +end |
| 58 | + |
| 59 | +# This testset runs the full gamut of MOI.Test.runtests. There are a number of |
| 60 | +# tests in here with weird edge cases, so a variety of exclusions are expected. |
| 61 | +@testset "MathOptInterface.test" begin |
| 62 | + optimizer = MOI.instantiate( |
| 63 | + Optimizer; |
| 64 | + with_cache_type = Float64, |
| 65 | + with_bridge_type = Float64, |
| 66 | + ) |
| 67 | + MOI.Test.runtests( |
| 68 | + optimizer, |
| 69 | + MOI.Test.Config( |
| 70 | + # These are pretty loose tolerances so that all tests pass. There |
| 71 | + # are few tests with weird numerics. If tests fail because of |
| 72 | + # tolerances, it might be okay to make these looser, or you could |
| 73 | + # tighten the tolerances used by Uno. |
| 74 | + atol = 1e-4, |
| 75 | + rtol = 1e-4, |
| 76 | + optimal_status = MOI.LOCALLY_SOLVED, |
| 77 | + infeasible_status = MOI.LOCALLY_INFEASIBLE, |
| 78 | + exclude = Any[ |
| 79 | + # It's okay to exclude BasisStatus, since AmplNLWriter doesn't |
| 80 | + # support this information, so too with ObjectiveBound, since |
| 81 | + # Uno is a local NLP solver. |
| 82 | + MOI.VariableBasisStatus, |
| 83 | + MOI.ConstraintBasisStatus, |
| 84 | + MOI.ObjectiveBound, |
| 85 | + ], |
| 86 | + ); |
| 87 | + exclude = [ |
| 88 | + # ================================================================== |
| 89 | + # The following tests are bugs. |
| 90 | + # |
| 91 | + # We should fix issues in Uno, and then try removing these lines. |
| 92 | + # |
| 93 | + # These tests return OTHER_LIMIT or OTHER_ERROR instead of |
| 94 | + # LOCALLY_SOLVED. |
| 95 | + r"^test_conic_linear_VectorOfVariables_2$", |
| 96 | + r"^test_linear_integration$", |
| 97 | + r"^test_linear_transform$", |
| 98 | + r"^test_nonlinear_expression_hs109$", |
| 99 | + r"^test_quadratic_constraint_GreaterThan$", |
| 100 | + r"^test_quadratic_constraint_LessThan$", |
| 101 | + r"^test_solve_VariableIndex_ConstraintDual_MAX_SENSE$", |
| 102 | + r"^test_solve_VariableIndex_ConstraintDual_MIN_SENSE$", |
| 103 | + # These tests return OTHER_LIMIT instead of DUAL_INFEASIBLE. It |
| 104 | + # might be acceptable to leave this as-is, but it would be better to |
| 105 | + # fix. |
| 106 | + r"^test_solve_TerminationStatus_DUAL_INFEASIBLE$", |
| 107 | + # These tests return OTHER_LIMIT instead of LOCALLY_INFEASIBLE. It |
| 108 | + # might be acceptable to leave this as-is, but it would be better to |
| 109 | + # fix. |
| 110 | + r"^test_conic_NormInfinityCone_INFEASIBLE$", |
| 111 | + r"^test_conic_NormOneCone_INFEASIBLE$", |
| 112 | + r"^test_conic_linear_INFEASIBLE$", |
| 113 | + r"^test_conic_linear_INFEASIBLE_2$", |
| 114 | + r"^test_linear_INFEASIBLE$", |
| 115 | + r"^test_linear_INFEASIBLE_2$", |
| 116 | + r"^test_solve_DualStatus_INFEASIBILITY_CERTIFICATE_", |
| 117 | + # ================================================================== |
| 118 | + # The following tests are okay to exclude forever. |
| 119 | + # |
| 120 | + # Uno does not support integrality, and AmplNLWriter has no way of |
| 121 | + # telling if a particular binary supports integers or not (it |
| 122 | + # defaults to assuming yes). |
| 123 | + "Indicator", |
| 124 | + r"[Ii]nteger", |
| 125 | + "Semicontinuous", |
| 126 | + "Semiinteger", |
| 127 | + "SOS1", |
| 128 | + "SOS2", |
| 129 | + "ZeroOne", |
| 130 | + r"^test_cpsat_", |
| 131 | + r"^test_attribute_SolverVersion$", |
| 132 | + r"^test_nonlinear_invalid$", |
| 133 | + r"^test_basic_VectorNonlinearFunction_", |
| 134 | + ], |
| 135 | + ) |
| 136 | +end |
0 commit comments