diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6371035f3fe85c90c7d14e089a4007819426f18d..13c5398ba5c3cbaf2433dca2da01529dc92581e3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,3 +12,12 @@ Python 3 POCL: artifacts: reports: junit: pytest.xml + +Flake8: + script: + - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-flake8.sh + - ". ./prepare-and-run-flake8.sh benchmark*.py test*.py util*.py" + tags: + - python3 + except: + - tags \ No newline at end of file diff --git a/benchmark.py b/benchmark.py index 6d2b9b007f6af52bcfd55906658879ee5764219c..cf49ddd6ffe56868d1ee7b3ea26458522209a3e3 100644 --- a/benchmark.py +++ b/benchmark.py @@ -1,5 +1,5 @@ -import numpy as np -import numpy.linalg as la +import numpy as np # noqa: F401 +import numpy.linalg as la # noqa: F401 import pyopencl as cl import pyopencl.array # noqa import pyopencl.tools # noqa @@ -40,7 +40,8 @@ def benchmark_compute_flux_derivatives_gpu(ctx_factory, write_code=False): metric_jacobians = u.random_array_on_device(queue, nx+6, ny+6, nz+6) print("END ARRAY GEN") - flux_derivatives_dev = u.empty_array_on_device(queue, nvars, ndim, nx+6, ny+6, nz+6) + flux_derivatives_dev = u.empty_array_on_device( + queue, nvars, ndim, nx+6, ny+6, nz+6) if write_code: u.write_target_device_code(prg) diff --git a/setup.cfg b/setup.cfg index b62c36ed026bbfaf059687974de9ed562fa60476..6fdc175dd5bae21563adf96162fd2a2ad06e992e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,3 @@ [flake8] -ignore = E126,E127,E128,E123,E226,E241,E242,E265,N802,W503,E402,N814,W504 +ignore = E126,E127,E128,E123,E226,E241,E242,E265,N802,N803,N806,W503,E402,N814,W504 max-line-length=85 diff --git a/test.py b/test.py index b64ddfbb36cf1752f95ed9de35b6369c897f82f7..c12593e2d977db4d22374bc924972995195548b4 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,6 @@ import numpy as np -import numpy.linalg as la -import pyopencl as cl +import numpy.linalg as la # noqa: F401 +import pyopencl as cl # noqa: F401 import pyopencl.array # noqa import pyopencl.tools # noqa import pyopencl.clrandom # noqa @@ -10,7 +10,6 @@ import sys import logging import pytest -from pytest import approx from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) @@ -75,7 +74,7 @@ def test_pointwise_eigenvalues_ideal_gas( queue = u.get_queue(ctx_factory) nvars = 5 - dirs = {"x" : 1, "y" : 2, "z" : 3} + dirs = {"x": 1, "y": 2, "z": 3} states = u.expand_to_6(u.transposed_array_from_string(states_str)) lam_dev = u.empty_array_on_device(queue, nvars, 6) @@ -105,45 +104,45 @@ def test_roe_uniform_grid_ideal_gas(ctx_factory, states_str, fluxes_str, directi def identity_matrix(n): return np.identity(n).astype(np.float32).copy(order="F") - def check_roe_identity(states, R, Rinv): - dState = states[:,1] - states[:,0] - u.compare_arrays(R@(Rinv@dState), dState) + def check_roe_identity(states, R, R_inv): + d_state = states[:, 1] - states[:, 0] + u.compare_arrays(R@(R_inv@d_state), d_state) - def check_roe_property(states, fluxes, R, Rinv, lam): - dState = states[:,1] - states[:,0] - dFlux = fluxes[:,1] - fluxes[:,0] + def check_roe_property(states, fluxes, R, R_inv, lam): + d_state = states[:, 1] - states[:, 0] + d_flux = fluxes[:, 1] - fluxes[:, 0] - temp = Rinv@dState + temp = R_inv@d_state temp = np.multiply(lam, temp) - u.compare_arrays(R@temp, dFlux) + u.compare_arrays(R@temp, d_flux) prg = u.get_weno_program_with_root_kernel("roe_eigensystem") queue = u.get_queue(ctx_factory) nvars = 5 ndim = 3 - dirs = {"x" : 1, "y" : 2, "z" : 3} + dirs = {"x": 1, "y": 2, "z": 3} states = u.transposed_array_from_string(states_str) fluxes = u.transposed_array_from_string(fluxes_str) metrics_frozen = identity_matrix(ndim) R_dev = u.empty_array_on_device(queue, nvars, nvars) - Rinv_dev = u.empty_array_on_device(queue, nvars, nvars) + R_inv_dev = u.empty_array_on_device(queue, nvars, nvars) lam_dev = u.empty_array_on_device(queue, nvars) prg(queue, nvars=nvars, ndim=ndim, d=dirs[direction], states=states, metrics_frozen=metrics_frozen, - R=R_dev, R_inv=Rinv_dev, lambda_roe=lam_dev) + R=R_dev, R_inv=R_inv_dev, lambda_roe=lam_dev) R = R_dev.get() - Rinv = Rinv_dev.get() + R_inv = R_inv_dev.get() lam = lam_dev.get() print(lam) - check_roe_identity(states, R, Rinv) - check_roe_property(states, fluxes, R, Rinv, lam) + check_roe_identity(states, R, R_inv) + check_roe_property(states, fluxes, R, R_inv, lam) def test_matvec(ctx_factory): diff --git a/utilities.py b/utilities.py index c619310ed0ff59c260744f5b08a8590f5997a7d6..34bd676fc7ee4d7ea85e19ad6b0fc50899a0e978 100644 --- a/utilities.py +++ b/utilities.py @@ -1,5 +1,5 @@ import numpy as np -import numpy.linalg as la +import numpy.linalg as la # noqa: F401 import pyopencl as cl import pyopencl.array # noqa import pyopencl.tools # noqa @@ -37,19 +37,22 @@ def array_from_string(string_array): if string_array[0] == "i": return np.array(split_map_to_list(string_array[1:], int, " ")) else: - return np.array(split_map_to_list(string_array, float, " "), dtype=np.float32) + return np.array( + split_map_to_list(string_array, float, " "), dtype=np.float32) def array_from_string_2d(string_array): if string_array[0] == ",": return array_from_string_1d(string_array[1:]).reshape((-1, 1)) else: - return np.array(split_map_to_list(string_array, array_from_string_1d, ",")) + return np.array( + split_map_to_list(string_array, array_from_string_1d, ",")) def array_from_string_3d(string_array): if string_array[0] == ";": return array_from_string_1d(string_array[1:]).reshape((-1, 1, 1)) else: - return np.array(split_map_to_list(string_array, array_from_string_2d, ";")) + return np.array( + split_map_to_list(string_array, array_from_string_2d, ";")) if ";" not in string_array: if "," not in string_array: @@ -70,6 +73,7 @@ def expand_to_6(pair): # }}} + # {{{ device def get_queue(ctx_factory): @@ -78,6 +82,7 @@ def get_queue(ctx_factory): # }}} + # {{{ program / kernel _WENO_PRG = {} @@ -118,7 +123,7 @@ def setup_weno_program_with_root_kernel(knl): def get_weno_program_with_root_kernel(knl): - if not knl in _WENO_PRG: + if knl not in _WENO_PRG: setup_weno_program_with_root_kernel(knl) return _WENO_PRG[knl]