From 70b7713650ed773b2f0b30ddf8cb91b6d04d3794 Mon Sep 17 00:00:00 2001
From: Markus Holzer <markus.holzer@fau.de>
Date: Thu, 4 Feb 2021 17:14:07 +0100
Subject: [PATCH] Bump minimum SymPy version and add Python 3.9 to CI

---
 .gitlab-ci.yml                              | 32 ++++++++++++++++++++-
 pystencils_tests/test_custom_backends.py    |  3 +-
 pystencils_tests/test_datahandling.py       |  1 +
 pystencils_tests/test_fast_approximation.py |  3 ++
 pystencils_tests/test_stencils.py           | 10 +++++--
 setup.py                                    |  2 +-
 6 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8d5624e00..132543d71 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -34,6 +34,29 @@ tests-and-coverage:
       cobertura: coverage.xml
       junit: report.xml
 
+# pipeline with latest python version
+latest-python:
+  stage: test
+  except:
+    variables:
+      - $ENABLE_NIGHTLY_BUILDS
+  image: i10git.cs.fau.de:5005/pycodegen/pycodegen/latest_python
+  script:
+    - env
+    - pip list
+    - export NUM_CORES=$(nproc --all)
+    - mkdir -p ~/.config/matplotlib
+    - echo "backend:template" > ~/.config/matplotlib/matplotlibrc
+    - mkdir public
+    - py.test -v -n $NUM_CORES -m "not longrun" --junitxml=report.xml
+  tags:
+    - docker
+    - AVX
+  artifacts:
+    when: always
+    reports:
+      junit: report.xml
+
 # Nightly test  - runs "long run" jobs only
 test-longrun:
   stage: test
@@ -80,11 +103,18 @@ ubuntu:
     variables:
       - $ENABLE_NIGHTLY_BUILDS
   image: i10git.cs.fau.de:5005/pycodegen/pycodegen/ubuntu
+  before_script:
+    - apt-get -y remove python3-sympy
+    - ln -s /usr/include/locale.h /usr/include/xlocale.h
+    - pip3 install `grep -Eo 'sympy[>=]+[0-9\.]+' setup.py | sed 's/>/=/g'`
   script:
+    - export NUM_CORES=$(nproc --all)
     - mkdir -p ~/.config/matplotlib
     - echo "backend:template" > ~/.config/matplotlib/matplotlibrc
     - sed -i 's/--doctest-modules //g' pytest.ini
-    - pytest-3 -v -m "not longrun" --junitxml=report.xml
+    - env
+    - pip3 list
+    - pytest-3 -v -n $NUM_CORES -m "not longrun" --junitxml=report.xml
   tags:
     - docker
     - cuda11
diff --git a/pystencils_tests/test_custom_backends.py b/pystencils_tests/test_custom_backends.py
index 6500076ce..aa889f339 100644
--- a/pystencils_tests/test_custom_backends.py
+++ b/pystencils_tests/test_custom_backends.py
@@ -3,10 +3,8 @@ from subprocess import CalledProcessError
 import pytest
 import sympy
 
-import pycuda.driver
 import pystencils
 import pystencils.cpu.cpujit
-import pystencils.gpucuda.cudajit
 from pystencils.backends.cbackend import CBackend
 from pystencils.backends.cuda_backend import CudaBackend
 
@@ -40,6 +38,7 @@ def test_custom_backends_cpu():
 def test_custom_backends_gpu():
     pytest.importorskip('pycuda')
     import pycuda.driver
+    import pystencils.gpucuda.cudajit
 
     z, x, y = pystencils.fields("z, y, x: [2d]")
 
diff --git a/pystencils_tests/test_datahandling.py b/pystencils_tests/test_datahandling.py
index 57b904e53..9d0798ee8 100644
--- a/pystencils_tests/test_datahandling.py
+++ b/pystencils_tests/test_datahandling.py
@@ -365,6 +365,7 @@ def test_load_data():
 def test_array_handler(target):
     size = (2, 2)
     if target == 'gpu':
+        pytest.importorskip('pycuda')
         array_handler = PyCudaArrayHandler()
     if target == 'opencl':
         pytest.importorskip('pyopencl')
diff --git a/pystencils_tests/test_fast_approximation.py b/pystencils_tests/test_fast_approximation.py
index ccd2d7b8e..c596bed1a 100644
--- a/pystencils_tests/test_fast_approximation.py
+++ b/pystencils_tests/test_fast_approximation.py
@@ -1,3 +1,4 @@
+import pytest
 import sympy as sp
 
 import pystencils as ps
@@ -6,6 +7,7 @@ from pystencils.fast_approximation import (
 
 
 def test_fast_sqrt():
+    pytest.importorskip('pycuda')
     f, g = ps.fields("f, g: double[2D]")
     expr = sp.sqrt(f[0, 0] + f[1, 0])
 
@@ -28,6 +30,7 @@ def test_fast_sqrt():
 
 
 def test_fast_divisions():
+    pytest.importorskip('pycuda')
     f, g = ps.fields("f, g: double[2D]")
     expr = f[0, 0] / f[1, 0]
     assert len(insert_fast_divisions(expr).atoms(fast_division)) == 1
diff --git a/pystencils_tests/test_stencils.py b/pystencils_tests/test_stencils.py
index e66971316..3f7d49b3b 100644
--- a/pystencils_tests/test_stencils.py
+++ b/pystencils_tests/test_stencils.py
@@ -2,6 +2,7 @@ import pystencils as ps
 import sympy as sp
 
 from pystencils.stencil import coefficient_list, plot_expression
+import pystencils.plot as plt
 
 
 def test_coefficient_list():
@@ -9,7 +10,8 @@ def test_coefficient_list():
     expr = 2 * f[1] + 3 * f[-1]
     coff = coefficient_list(expr)
     assert coff == [3, 0, 2]
-    plot_expression(expr, matrix_form=True)
+    figure = plt.figure()
+    plot_expression(expr, matrix_form=True, figure=figure)
 
     f = ps.fields("f: double[3D]")
     expr = 2 * f[1, 0, 0] + 3 * f[0, -1, 0]
@@ -22,9 +24,11 @@ def test_coefficient_list():
 
     # in 3D plot only works if there are entries on every of the three 2D planes. In the above examples z-1 was empty
     expr = 2 * f[1, 0, 0] + 1 * f[0, -1, 0] + 1 * f[0, 0, 1] + f[0, 0, -1]
-    plot_expression(expr)
+    figure = plt.figure()
+    plot_expression(expr, figure=figure)
 
 
 def test_plot_expression():
     f = ps.fields("f: double[2D]")
-    plot_expression(2 * f[1, 0] + 3 * f[0, -1], matrix_form=True)
+    figure = plt.figure()
+    plot_expression(2 * f[1, 0] + 3 * f[0, -1], matrix_form=True, figure=figure)
diff --git a/setup.py b/setup.py
index b209fcbb9..bce6eed2d 100644
--- a/setup.py
+++ b/setup.py
@@ -85,7 +85,7 @@ setuptools.setup(name='pystencils',
                  author_email='martin.bauer@fau.de',
                  url='https://i10git.cs.fau.de/pycodegen/pystencils/',
                  packages=['pystencils'] + ['pystencils.' + s for s in setuptools.find_packages('pystencils')],
-                 install_requires=['sympy>=1.1', 'numpy', 'appdirs', 'joblib'],
+                 install_requires=['sympy>=1.2', 'numpy>=1.8.0', 'appdirs', 'joblib'],
                  package_data={'pystencils': ['include/*.h',
                                               'backends/cuda_known_functions.txt',
                                               'backends/opencl1.1_known_functions.txt',
-- 
GitLab