Commit 9bad685f authored by Helen Schottenhamml's avatar Helen Schottenhamml
Browse files

Merge branch 'Fixes' into 'master'

Clean up and Bug Fixes

Closes #38

See merge request pycodegen/pystencils!264
parents a3cec2ce 6f74f2ab
Pipeline #35071 passed with stages
in 17 minutes and 57 seconds
This diff is collapsed.
......@@ -117,6 +117,7 @@ def test_advection_diffusion_2d(velocity):
advection_diffusion.runners[2](velocity)
@pytest.mark.longrun
@pytest.mark.parametrize("velocity", list(product([0, -0.047, 0.041], [0, -0.031, 0.023], [0, -0.017, 0.011])))
def test_advection_diffusion_3d(velocity):
if 3 not in advection_diffusion.runners:
......
......@@ -44,7 +44,6 @@ def test_compilation():
print(mine)
@pytest.mark.kerncraft
def analysis(kernel, machine, model='ecmdata'):
if model == 'ecmdata':
model = ECMData(kernel, machine, KerncraftParameters())
......
import pytest
import sympy as sp
import pystencils as ps
from pystencils.math_optimizations import HAS_REWRITING, optimize_assignments, optims_pystencils_cpu, optimize_ast
@pytest.mark.skipif(not HAS_REWRITING, reason="need sympy.codegen.rewriting")
def test_sympy_optimizations():
for target in (ps.Target.CPU, ps.Target.GPU):
for op_ast in (True, False):
x, y, z = ps.fields('x, y, z: float32[2d]')
# Triggers Sympy's expm1 optimization
# Sympy's expm1 optimization is tedious to use and the behaviour is highly depended on the sympy version. In
# some cases the exp expression has to be encapsulated in brackets or multiplied with 1 or 1.0
# for sympy to work properly ...
assignments = ps.AssignmentCollection({
x[0, 0]: 1.0 * (sp.exp(y[0, 0]) - 1)
})
if not op_ast:
assignments = optimize_assignments(assignments, optims_pystencils_cpu)
print(assignments)
ast = ps.create_kernel(assignments, config=ps.CreateKernelConfig(target=target))
if op_ast:
optimize_ast(ast, optims_pystencils_cpu)
code = ps.get_code_str(ast)
assert 'expm1(' in code
@pytest.mark.skipif(not HAS_REWRITING, reason="need sympy.codegen.rewriting")
def test_evaluate_constant_terms():
for target in (ps.Target.CPU, ps.Target.GPU):
x, y, z = ps.fields('x, y, z: float32[2d]')
# Triggers Sympy's cos optimization
assignments = ps.AssignmentCollection({
x[0, 0]: -sp.cos(1) + y[0, 0]
})
assignments = optimize_assignments(assignments, optims_pystencils_cpu)
ast = ps.create_kernel(assignments, config=ps.CreateKernelConfig(target=target))
code = ps.get_code_str(ast)
assert 'cos(' not in code
print(code)
@pytest.mark.skipif(not HAS_REWRITING, reason="need sympy.codegen.rewriting")
def test_do_not_evaluate_constant_terms():
optimizations = ps.math_optimizations.optims_pystencils_cpu
optimizations.remove(ps.math_optimizations.evaluate_constant_terms)
for target in (ps.Target.CPU, ps.Target.GPU):
x, y, z = ps.fields('x, y, z: float32[2d]')
assignments = ps.AssignmentCollection({
x[0, 0]: -sp.cos(1) + y[0, 0]
})
ast = ps.create_kernel(assignments, config=ps.CreateKernelConfig(target=target))
code = ps.get_code_str(ast)
assert 'cos(' in code
print(code)
......@@ -5,7 +5,7 @@ import ctypes
import pystencils as ps
from pystencils import data_types
from pystencils.data_types import TypedSymbol, get_type_of_expression, VectorType, collate_types, create_type,\
from pystencils.data_types import TypedSymbol, get_type_of_expression, VectorType, collate_types, create_type, \
typed_symbols, type_all_numbers, matrix_symbols, cast_func, pointer_arithmetic_func, ctypes_from_llvm, PointerType
......@@ -114,11 +114,11 @@ def test_Basic_data_type():
assert s.dtype.is_uint()
assert s.dtype.is_complex() == 0
assert typed_symbols(("s"), str).dtype.is_other()
assert typed_symbols(("s"), bool).dtype.is_other()
assert typed_symbols(("s"), np.void).dtype.is_other()
assert typed_symbols("s", str).dtype.is_other()
assert typed_symbols("s", bool).dtype.is_other()
assert typed_symbols("s", np.void).dtype.is_other()
assert typed_symbols(("s"), np.float64).dtype.base_name == 'double'
assert typed_symbols("s", np.float64).dtype.base_name == 'double'
# removed for old sympy version
# assert typed_symbols(("s"), np.float64).dtype.sympy_dtype == typed_symbols(("s"), float).dtype.sympy_dtype
......
......@@ -5,6 +5,14 @@ addopts = --doctest-modules --durations=20 --cov-config pytest.ini
markers =
kerncraft: tests depending on kerncraft
notebook: mark for notebooks
# these warnings all come from third party libraries.
filterwarnings =
ignore:an integer is required:DeprecationWarning
ignore:\s*load will be removed, use:PendingDeprecationWarning
ignore:the imp module is deprecated in favour of importlib:DeprecationWarning
ignore:.*is a deprecated alias for the builtin `bool`:DeprecationWarning
ignore:'contextfilter' is renamed to 'pass_context':DeprecationWarning
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc':DeprecationWarning
[run]
branch = True
......
import distutils
import io
import os
import sys
from contextlib import redirect_stdout
from importlib import import_module
......@@ -11,6 +10,7 @@ import versioneer
try:
import cython # noqa
USE_CYTHON = True
except ImportError:
USE_CYTHON = False
......@@ -32,13 +32,13 @@ class SimpleTestRunner(distutils.cmd.Command):
@staticmethod
def _run_tests_in_module(test):
"""Short test runner function - to work also if py.test is not installed."""
test = 'pystencils_tests.' + test
test = f'pystencils_tests.{test}'
mod, function_name = test.rsplit('.', 1)
if isinstance(mod, str):
mod = import_module(mod)
func = getattr(mod, function_name)
print(f" -> {function_name} in {mod.__name__}" )
print(f" -> {function_name} in {mod.__name__}")
with redirect_stdout(io.StringIO()):
func()
......@@ -76,7 +76,7 @@ def cython_extensions(*extensions):
def get_cmdclass():
cmdclass={"quicktest": SimpleTestRunner}
cmdclass = {"quicktest": SimpleTestRunner}
cmdclass.update(versioneer.get_cmdclass())
return cmdclass
......@@ -91,7 +91,7 @@ setuptools.setup(name='pystencils',
author_email='cs10-codegen@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.2', 'numpy>=1.8.0', 'appdirs', 'joblib'],
install_requires=['sympy>=1.5.1,<=1.9', 'numpy>=1.8.0', 'appdirs', 'joblib'],
package_data={'pystencils': ['include/*.h',
'kerncraft_coupling/templates/*',
'backends/cuda_known_functions.txt',
......@@ -122,7 +122,9 @@ setuptools.setup(name='pystencils',
'autodiff': ['pystencils-autodiff'],
'doc': ['sphinx', 'sphinx_rtd_theme', 'nbsphinx',
'sphinxcontrib-bibtex', 'sphinx_autodoc_typehints', 'pandoc'],
'use_cython': ['Cython']
'use_cython': ['Cython'],
'kerncraft': ['osaca', 'kerncraft'],
'llvm_jit': ['llvmlite']
},
tests_require=['pytest',
'pytest-cov',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment