From 642bbba07bbcb0e0a0292f68dff8ec042de95bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Mon, 1 Jul 2019 14:11:28 +0200 Subject: [PATCH 1/4] Flake8 CI --- .gitlab-ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6371035..13c5398 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 -- GitLab From 4b0109d5da7f67159d416cb3a5dec7f5125bc677 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 1 Jul 2019 14:40:10 +0200 Subject: [PATCH 2/4] Fix Flake8 complaints --- benchmark.py | 7 ++++--- test.py | 39 +++++++++++++++++++-------------------- utilities.py | 15 ++++++++++----- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/benchmark.py b/benchmark.py index 6d2b9b0..cf49ddd 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/test.py b/test.py index b64ddfb..7cd79a8 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_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 = r_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 c619310..34bd676 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] -- GitLab From 3b68fd4ff7525bf340d179389eaa7fe769629858 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 8 Jul 2019 16:16:27 -0500 Subject: [PATCH 3/4] revert changes to R, R_inv variable names --- test.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test.py b/test.py index 7cd79a8..c12593e 100644 --- a/test.py +++ b/test.py @@ -104,17 +104,17 @@ 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, r_inv): + def check_roe_identity(states, R, R_inv): d_state = states[:, 1] - states[:, 0] - u.compare_arrays(r@(r_inv@d_state), d_state) + u.compare_arrays(R@(R_inv@d_state), d_state) - def check_roe_property(states, fluxes, r, r_inv, lam): + def check_roe_property(states, fluxes, R, R_inv, lam): d_state = states[:, 1] - states[:, 0] d_flux = fluxes[:, 1] - fluxes[:, 0] - temp = r_inv@d_state + temp = R_inv@d_state temp = np.multiply(lam, temp) - u.compare_arrays(r@temp, d_flux) + u.compare_arrays(R@temp, d_flux) prg = u.get_weno_program_with_root_kernel("roe_eigensystem") queue = u.get_queue(ctx_factory) @@ -127,22 +127,22 @@ def test_roe_uniform_grid_ideal_gas(ctx_factory, states_str, fluxes_str, directi fluxes = u.transposed_array_from_string(fluxes_str) metrics_frozen = identity_matrix(ndim) - r_dev = u.empty_array_on_device(queue, nvars, nvars) - r_inv_dev = u.empty_array_on_device(queue, nvars, nvars) + R_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=r_inv_dev, lambda_roe=lam_dev) + R=R_dev, R_inv=R_inv_dev, lambda_roe=lam_dev) - r = r_dev.get() - r_inv = r_inv_dev.get() + R = R_dev.get() + R_inv = R_inv_dev.get() lam = lam_dev.get() print(lam) - check_roe_identity(states, r, r_inv) - check_roe_property(states, fluxes, r, r_inv, lam) + check_roe_identity(states, R, R_inv) + check_roe_property(states, fluxes, R, R_inv, lam) def test_matvec(ctx_factory): -- GitLab From ff1ee5a8aedc6d83ac937cde219663c0e729fff2 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Mon, 8 Jul 2019 16:26:07 -0500 Subject: [PATCH 4/4] added N803, N806 to flake8's list of ignored error codes --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index b62c36e..6fdc175 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 -- GitLab