Skip to content

Commit

Permalink
Skip tests using python-mip on macos arm64
Browse files Browse the repository at this point in the history
There are issues with cbc included in the wheel for this platform.
See coin-or/python-mip#167
  • Loading branch information
nhuet authored and g-poveda committed May 27, 2024
1 parent e6b0aa3 commit 21e72b1
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 27 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ jobs:
with:
name: dist
path: dist
- name: Install prerelease version of pymip (only for macos arm64)
if: matrix.os == 'macos-latest'
run: |
python -m pip install -U pip
pip install mip==1.16rc0
- name: Prevent installing newest release or ortools on windows (segmentation fault)
if: matrix.os == 'windows-latest'
run: |
Expand Down
36 changes: 24 additions & 12 deletions tests/coloring/test_coloring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import platform
import random
import sys

Expand Down Expand Up @@ -57,7 +58,7 @@
)
from discrete_optimization.generic_tools.ea.ga import DeapMutation, Ga
from discrete_optimization.generic_tools.ea.nsga import Nsga
from discrete_optimization.generic_tools.lp_tools import ParametersMilp
from discrete_optimization.generic_tools.lp_tools import ParametersMilp, PymipMilpSolver
from discrete_optimization.generic_tools.result_storage.result_storage import (
plot_storage_2d,
)
Expand Down Expand Up @@ -103,6 +104,11 @@ def test_load_file(coloring_problem_file):
def test_solvers(solver_class):
if solver_class == ColoringLP and not gurobi_available:
pytest.skip("You need Gurobi to test this solver.")
if issubclass(solver_class, PymipMilpSolver) and platform.machine() == "arm64":
pytest.skip(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167"
)
small_example = [f for f in get_data_available() if "gc_20_1" in f][0]
coloring_model: ColoringProblem = parse_file(small_example)
results = solve(
Expand All @@ -111,7 +117,16 @@ def test_solvers(solver_class):
sol, fit = results.get_best_solution_fit()


def test_solvers_subset():
@pytest.mark.parametrize("solver_class", solvers_map)
def test_solvers_subset(solver_class):
if solver_class == ColoringLP and not gurobi_available:
pytest.skip("You need Gurobi to test this solver.")
if issubclass(solver_class, PymipMilpSolver) and platform.machine() == "arm64":
pytest.skip(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167"
)

small_example = [f for f in get_data_available() if "gc_20_1" in f][0]
coloring_model: ColoringProblem = parse_file(small_example)
coloring_model = transform_coloring_problem(
Expand All @@ -122,16 +137,13 @@ def test_solvers_subset():
assert coloring_model.graph is not None
assert coloring_model.number_of_nodes is not None
assert coloring_model.graph.nodes_name is not None
solvers = solvers_map.keys()
for s in solvers:
logger.info(f"Running {s}")
if s == ColoringLP and not gurobi_available:
# you need a gurobi licence to test this solver.
continue
results = solve(method=s, problem=coloring_model, **solvers_map[s][1])
sol, fit = results.get_best_solution_fit()
print(f"Solver {s}, fitness = {fit}")
print(f"Evaluation : {coloring_model.evaluate(sol)}")

results = solve(
method=solver_class, problem=coloring_model, **solvers_map[solver_class][1]
)
sol, fit = results.get_best_solution_fit()
print(f"Solver {solver_class}, fitness = {fit}")
print(f"Evaluation : {coloring_model.evaluate(sol)}")


def test_mzn_solver_cb(caplog):
Expand Down
8 changes: 8 additions & 0 deletions tests/facility/test_facility_lp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# LICENSE file in the root directory of this source tree.

import os
import platform

import pytest

Expand Down Expand Up @@ -55,6 +56,13 @@ def test_facility_lp_cbc():


@pytest.mark.skipif(not gurobi_available, reason="You need Gurobi to test this solver.")
@pytest.mark.skipif(
platform.machine() == "arm64",
reason=(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167"
),
)
def test_facility_lp_pymip():
file = [f for f in get_data_available() if os.path.basename(f) == "fl_100_7"][0]
facility_problem = parse_file(file)
Expand Down
8 changes: 8 additions & 0 deletions tests/facility/test_facility_lp_lns.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# LICENSE file in the root directory of this source tree.

import os
import platform

import pytest

Expand Down Expand Up @@ -33,6 +34,13 @@


@pytest.mark.skipif(not gurobi_available, reason="You need Gurobi to test this solver.")
@pytest.mark.skipif(
platform.machine() == "arm64",
reason=(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167"
),
)
def test_facility_lns():
file = [f for f in get_data_available() if os.path.basename(f) == "fl_16_1"][0]
facility_problem = parse_file(file)
Expand Down
11 changes: 11 additions & 0 deletions tests/knapsack/test_knapsack_lp_lns_solver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Copyright (c) 2022 AIRBUS and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import platform

import pytest

from discrete_optimization.generic_tools.callbacks.early_stoppers import TimerStopper
from discrete_optimization.generic_tools.do_problem import get_default_objective_setup
from discrete_optimization.generic_tools.lns_mip import LNS_MILP
Expand All @@ -17,6 +21,13 @@
from discrete_optimization.knapsack.solvers.lp_solvers import KnapsackModel, LPKnapsack


@pytest.mark.skipif(
platform.machine() == "arm64",
reason=(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167"
),
)
def test_knapsack_lns():
model_file = [f for f in get_data_available() if "ks_30_0" in f][0]
model: KnapsackModel = parse_file(model_file)
Expand Down
26 changes: 17 additions & 9 deletions tests/knapsack/test_knapsack_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import platform
import random

import numpy as np
import pytest

from discrete_optimization.generic_tools.lp_tools import PymipMilpSolver
from discrete_optimization.knapsack.knapsack_model import (
KnapsackModel,
KnapsackSolution,
Expand Down Expand Up @@ -39,15 +41,21 @@ def test_load_file(knapsack_problem_file):
assert knapsack_model.satisfy(dummy_solution)


def test_solvers():
@pytest.mark.parametrize("solver_class", solvers_map)
def test_solvers(solver_class):
if solver_class == LPKnapsackGurobi and not gurobi_available:
pytest.skip("You need Gurobi to test this solver.")
if issubclass(solver_class, PymipMilpSolver) and platform.machine() == "arm64":
pytest.skip(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167"
)

logging.basicConfig(level=logging.INFO)
small_example = [f for f in get_data_available() if "ks_40_0" in f][0]
knapsack_model: KnapsackModel = parse_file(small_example)
solvers = solvers_map.keys()
for s in solvers:
if s == LPKnapsackGurobi:
continue
logging.info(f"Solver {s}")
results = solve(method=s, problem=knapsack_model, **solvers_map[s][1])
s, f = results.get_best_solution_fit()
logging.info(f"fitness={f}")
results = solve(
method=solver_class, problem=knapsack_model, **solvers_map[solver_class][1]
)
s, f = results.get_best_solution_fit()
logging.info(f"fitness={f}")
9 changes: 9 additions & 0 deletions tests/pickup_vrp/builders/test_linear_flow_solver_pymip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2022 AIRBUS and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import platform

import pytest

Expand Down Expand Up @@ -36,6 +37,14 @@
epsilon = 0.000001


if platform.machine() == "arm64":
pytest.skip(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167",
allow_module_level=True,
)


def test_tsp():
logging.basicConfig(level=logging.DEBUG)
files_available = tsp_parser.get_data_available()
Expand Down
11 changes: 11 additions & 0 deletions tests/rcpsp/solver/test_rcpsp_lp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import platform

import pytest

from discrete_optimization.generic_tools.lp_tools import MilpSolverName, ParametersMilp
from discrete_optimization.generic_tools.result_storage.result_storage import (
ResultStorage,
Expand All @@ -14,6 +18,13 @@
)
from discrete_optimization.rcpsp.solver.rcpsp_lp_solver import LP_MRCPSP, LP_RCPSP

if platform.machine() == "arm64":
pytest.skip(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167",
allow_module_level=True,
)


def test_rcpsp_sm_lp_cbc():
files_available = get_data_available()
Expand Down
11 changes: 11 additions & 0 deletions tests/rcpsp/solver/test_rcpsp_lp_lns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import platform

import pytest

from discrete_optimization.generic_tools.do_problem import (
ModeOptim,
ObjectiveHandling,
Expand All @@ -26,6 +30,13 @@
)
from discrete_optimization.rcpsp.solver.rcpsp_lp_solver import LP_MRCPSP, LP_RCPSP

if platform.machine() == "arm64":
pytest.skip(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167",
allow_module_level=True,
)


def test_lns_sm():
files_available = get_data_available()
Expand Down
11 changes: 10 additions & 1 deletion tests/rcpsp_multiskill/test_rcpsp_ms_lp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright (c) 2022 AIRBUS and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import platform
from typing import Dict, List, Set

import pytest

from discrete_optimization.rcpsp_multiskill.rcpsp_multiskill import (
Employee,
MS_RCPSPModel,
Expand All @@ -15,6 +17,13 @@
ParametersMilp,
)

if platform.machine() == "arm64":
pytest.skip(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167",
allow_module_level=True,
)


def test_lp():
skills_set: Set[str] = {"S1", "S2", "S3"}
Expand Down
10 changes: 10 additions & 0 deletions tests/rcpsp_multiskill/test_rcpsp_ms_rcpsp_based_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import platform
from typing import Dict, List, Set

import pytest

from discrete_optimization.generic_tools.lp_tools import MilpSolverName
from discrete_optimization.rcpsp.rcpsp_solvers import LP_MRCPSP, solvers
from discrete_optimization.rcpsp_multiskill.rcpsp_multiskill import (
Expand All @@ -16,6 +19,13 @@
Solver_RCPSP_Based,
)

if platform.machine() == "arm64":
pytest.skip(
"Python-mip has issues with cbclib on macos arm64. "
"See https://github.com/coin-or/python-mip/issues/167",
allow_module_level=True,
)


def create_toy_msrcpsp():
skills_set: Set[str] = {"S1", "S2", "S3"}
Expand Down

0 comments on commit 21e72b1

Please sign in to comment.