Skip to content

Commit

Permalink
CI: Remove matplotlib in minimal test setting (#479)
Browse files Browse the repository at this point in the history
* Remove matplotlib in minimal test setting

* Skip examples test when matplotlib not installed

* Do not require matplotlib for testing

* Fix format

* Do not require matplotlib for testing

* Do not require matplotlib for testing
  • Loading branch information
relf authored Nov 24, 2023
1 parent a33b5e7 commit 141b82e
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 92 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/tests_minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
- name: Install dependencies
run: |
pip install --upgrade pip
pip install numpy cython
pip install matplotlib # required by GENN atm, to be fixed
pip install numpy cython
pip install -e .
- name: Test with pytest
Expand Down
15 changes: 12 additions & 3 deletions smt/applications/tests/test_ego.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
import unittest
import numpy as np
from sys import argv
import matplotlib

matplotlib.use("Agg")
try:
import matplotlib

matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

from smt.applications import EGO
from smt.applications.ego import Evaluator
from smt.utils.sm_test_case import SMTestCase
Expand Down Expand Up @@ -1051,7 +1057,10 @@ def test_qei_criterion_default(self):
actual = float(ego._get_virtual_point(xtest, fun(xtest))[0])
self.assertAlmostEqual(expected, actual)

@unittest.skipIf(int(os.getenv("RUN_SLOW", 0)) < 2, "too slow")
@unittest.skipIf(
int(os.getenv("RUN_SLOW", 0)) < 2 or NO_MATPLOTLIB,
"too slow or matplotlib not installed",
)
def test_examples(self):
self.run_ego_example()
self.run_ego_parallel_example()
Expand Down
17 changes: 9 additions & 8 deletions smt/applications/tests/test_mfk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
@author: m.meliani
"""

import matplotlib

matplotlib.use("Agg")

import unittest
import numpy as np
import unittest
import inspect

from collections import OrderedDict
try:
import matplotlib

matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

from smt.problems import Sphere, TensorProduct
from smt.sampling_methods import LHS, FullFactorial
Expand Down Expand Up @@ -130,8 +131,8 @@ def test_mfk_derivs(self):

if print_output:
print(
"%8s %6s %18.9e %18.9e %18.9e %18.9e"
% (pname[:6], sname, t_error, e_error, e_error0, e_error1)
"%6s %18.9e %18.9e %18.9e %18.9e"
% ("MFK", t_error, e_error, e_error0, e_error1)
)

self.assert_error(e_error0, 0.0, 1e-1)
Expand Down
8 changes: 6 additions & 2 deletions smt/applications/tests/test_mfk_1fidelity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import matplotlib
try:
import matplotlib

matplotlib.use("Agg")
matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

import unittest
import numpy as np
Expand Down
20 changes: 10 additions & 10 deletions smt/applications/tests/test_mfk_mfkpls_mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@

import unittest
import numpy as np
import matplotlib
import itertools

matplotlib.use("Agg")
try:
import matplotlib

matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

import numpy.linalg as npl
import matplotlib.pyplot as plt

from smt.applications.mfkpls import MFKPLS
from smt.applications.mfk import MFK

from smt.applications.mixed_integer import (
MixedIntegerContext,
MixedIntegerSamplingMethod,
MixedIntegerKrigingModel,
MixedIntegerSurrogateModel,
)

from smt.applications import NestedLHS
Expand All @@ -34,9 +33,7 @@
from smt.surrogate_models import (
KRG,
KPLS,
QP,
MixIntKernelType,
MixHrcKernelType,
)

import warnings
Expand All @@ -47,7 +44,6 @@
DesignSpace,
FloatVariable,
IntegerVariable,
OrdinalVariable,
CategoricalVariable,
)

Expand Down Expand Up @@ -330,6 +326,8 @@ def DTLZ5_LF_mixt(self, x):
###############################################################################

def run_mfk_mixed_example(self):
from matplotlib.pyplot import plt

# KRG_METHODS = ["krg", "kpls", "mfk", "mfkpls"]
# KRG_METHODS = ["krg"]
# KRG_METHODS = ["kpls"]
Expand Down Expand Up @@ -654,6 +652,8 @@ def run_mfk_mixed_example(self):
# ------------------------------------------------------------------------------

def run_mfkpls_mixed_example(self):
from matplotlib.pyplot import plt

# KRG_METHODS = ["krg", "kpls", "mfk", "mfkpls"]
# KRG_METHODS = ["krg"]
# KRG_METHODS = ["kpls"]
Expand Down
17 changes: 7 additions & 10 deletions smt/applications/tests/test_mfkpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
Adapted to new SMT version in march 2020 by Nathalie Bartoli
"""

import matplotlib

matplotlib.use("Agg")
try:
import matplotlib

matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

import unittest
import numpy as np
Expand Down Expand Up @@ -129,17 +134,9 @@ def test_mfkpls_derivs(self):
with Silence():
sm.train()

t_error = compute_rms_error(sm)
e_error = compute_rms_error(sm, xe, ye)
e_error0 = compute_rms_error(sm, xe, dye[0], 0)
e_error1 = compute_rms_error(sm, xe, dye[1], 1)

if print_output:
print(
"%8s %6s %18.9e %18.9e %18.9e %18.9e"
% (pname[:6], sname, t_error, e_error, e_error0, e_error1)
)

self.assert_error(e_error0, 0.0, 1e-1)
self.assert_error(e_error1, 0.0, 1e-1)

Expand Down
18 changes: 6 additions & 12 deletions smt/applications/tests/test_mfkplsk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
Adapted to new SMT version in march 2020 by Nathalie Bartoli
"""
try:
import matplotlib

import matplotlib

matplotlib.use("Agg")
matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

import unittest
import numpy as np
import unittest
import inspect

from collections import OrderedDict

from smt.problems import Sphere, TensorProduct
from smt.sampling_methods import LHS, FullFactorial
Expand Down Expand Up @@ -137,12 +137,6 @@ def test_mfkplsk_derivs(self):
e_error0 = compute_rms_error(sm, xe, dye[0], 0)
e_error1 = compute_rms_error(sm, xe, dye[1], 1)

if print_output:
print(
"%8s %6s %18.9e %18.9e %18.9e %18.9e"
% (pname[:6], sname, t_error, e_error, e_error0, e_error1)
)

self.assert_error(e_error0, 0.0, 1e-1)
self.assert_error(e_error1, 0.0, 1e-1)

Expand Down
10 changes: 8 additions & 2 deletions smt/applications/tests/test_mixed_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@

import unittest
import numpy as np
import matplotlib
import itertools

matplotlib.use("Agg")
try:
import matplotlib

matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

from smt.applications.mixed_integer import (
MixedIntegerContext,
Expand Down Expand Up @@ -296,6 +301,7 @@ def test_cast_to_discrete_values_with_non_integer_ordinal_values(self):
atol=1e-9,
)

@unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed")
def test_examples(self):
self.run_mixed_integer_lhs_example()
self.run_mixed_integer_qp_example()
Expand Down
8 changes: 6 additions & 2 deletions smt/applications/tests/test_moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
This package is distributed under New BSD license.
"""

import matplotlib
try:
import matplotlib

matplotlib.use("Agg")
matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

import unittest
import numpy as np
Expand Down
9 changes: 7 additions & 2 deletions smt/applications/tests/test_vfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
"""

import unittest
import matplotlib

matplotlib.use("Agg")
try:
import matplotlib

matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

import numpy as np
from scipy import linalg
Expand Down
2 changes: 0 additions & 2 deletions smt/examples/airfoil_parameters/run_genn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
Predicting Airfoil Aerodynamics through data by Raul Carreira Rufato and Prof. Joseph Morlier
"""

import os
import numpy as np
import csv

from smt.examples.airfoil_parameters.learning_airfoil_parameters import (
load_cd_training_data,
Expand Down
22 changes: 16 additions & 6 deletions smt/examples/b777_engine/tests/test_b777_engine.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import unittest

import matplotlib
try:
import matplotlib

matplotlib.use("Agg")
matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

try:
from smt.surrogate_models import RMTB, RMTC

compiled_available = True
NO_COMPILED = True
except:
compiled_available = False
NO_COMPILED = False


class Test(unittest.TestCase):
@unittest.skipIf(not compiled_available, "C compilation failed")
@unittest.skipIf(
NO_COMPILED or NO_MATPLOTLIB,
"C compilation failed or matplotlib not installed",
)
def test_rmtb(self):
from smt.examples.b777_engine import run_b777_engine_rmtb

@unittest.skipIf(not compiled_available, "C compilation failed")
@unittest.skipIf(
NO_COMPILED or NO_MATPLOTLIB,
"C compilation failed or matplotlib not installed",
)
def test_rmtc(self):
from smt.examples.b777_engine import run_b777_engine_rmtc

Expand Down
22 changes: 16 additions & 6 deletions smt/examples/one_D_step/tests/test_one_D_step.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import unittest

import matplotlib
try:
import matplotlib

matplotlib.use("Agg")
matplotlib.use("Agg")
NO_MATPLOTLIB = False
except:
NO_MATPLOTLIB = True

try:
from smt.surrogate_models import RMTB, RMTC

compiled_available = True
NO_COMPILED = True
except:
compiled_available = False
NO_COMPILED = False


class Test(unittest.TestCase):
@unittest.skipIf(not compiled_available, "C compilation failed")
@unittest.skipIf(
NO_COMPILED or NO_MATPLOTLIB,
"C compilation failed or matplotlib not installed",
)
def test_rmtb(self):
from smt.examples.one_D_step import run_one_D_step_rmtb

@unittest.skipIf(not compiled_available, "C compilation failed")
@unittest.skipIf(
NO_COMPILED or NO_MATPLOTLIB,
"C compilation failed or matplotlib not installed",
)
def test_rmtc(self):
from smt.examples.one_D_step import run_one_D_step_rmtc
Loading

0 comments on commit 141b82e

Please sign in to comment.