From 8acb0be31e060ede271e8ccbde9cf26972ab3026 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Fri, 28 Jun 2019 23:59:57 -0500 Subject: [PATCH 1/7] add flux splitting test with no parametrization --- test.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test.py b/test.py index b64ddfb..1b4f6d1 100644 --- a/test.py +++ b/test.py @@ -18,6 +18,36 @@ from pyopencl.tools import ( # noqa import utilities as u +def test_flux_splitting_uniform_grid( + ctx_factory, states_str, fluxes_str, R_inv_str, wavespeeds_str, + fluxes_pos_expected_str, fluxes_neg_expected_str): + prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") + queue = u.get_queue(ctx_factory) + + nvars = 5 + + states = u.transposed_array_from_string(states_str) + fluxes = u.transposed_array_from_string(fluxes_str) + R_inv = u.array_from_string(R_inv_str) + wavespeeds = u.array_from_string(wavespeeds_str) + fluxes_pos_dev = u.empty_array_on_device(queue, nvars, 6) + fluxes_neg_dev = u.empty_array_on_device(queue, nvars, 6) + + prg(queue, nvars=nvars, + generalized_states_frozen=states, + generalized_fluxes_frozen=fluxes, + R_inv=R_inv, + wavespeeds=wavespeeds, + characteristic_fluxes_pos=fluxes_pos_dev, + characteristic_fluxes_neg=fluxes_neg_dev) + + fluxes_pos_expected = u.array_from_string(fluxes_pos_expected_str) + u.compare_arrays(fluxes_pos_dev.get(), fluxes_pos_expected) + + fluxes_neg_expected = u.array_from_string(fluxes_neg_expected_str) + u.compare_arrays(fluxes_neg_dev.get(), fluxes_neg_expected) + + @pytest.mark.parametrize("lam_pointwise_str,lam_roe_str,lam_expected_str", [ ("1 2 3 4 5,2 4 6 8 10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), ("1 2 3 4 5,-2 -4 -6 -8 -10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), -- GitLab From 5de1dffb2d446e526ed9aa929a9780c91ff7d5bd Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Sat, 29 Jun 2019 00:21:42 -0500 Subject: [PATCH 2/7] add initial (broken) paramatrization for flux splitting test --- test.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/test.py b/test.py index 1b4f6d1..6c03a4c 100644 --- a/test.py +++ b/test.py @@ -18,6 +18,31 @@ from pyopencl.tools import ( # noqa import utilities as u +@pytest.mark.parametrize(("states_str,fluxes_str,R_inv_str,wavespeeds_str," + "fluxes_pos_expected_str,fluxes_neg_expected_str"), [ + ("2 4 4 4 20,1 1 1 1 5.5", "4 11.2 8 8 46.4,1 2.6 1 1 7.1", + ("0.367521364 0.265894836 0.265894836 0.265894836 -0.167673798," + "-1.12132034 0 0.707106781 0 0," + "-1.12132034 0 0 0.707106781 0," + "-0.430558632 0.416709665 -0.290397116 -0.290397116 0.183124984," + "1.81208206 -0.997503897 -0.290397116 -0.290397116 0.183124984"), + "2.2 2.2 2.2 3.84632925 0.55367075", + ("1.09071563 1.23015152 1.23015152 7.52305259 0.232956271," + "0.467376796 -0.6627417 -0.6627417 1.47953026 0.312527304"), + ("-0.168354897 -0.0585786438 -0.0585786438 -0.727493464 -0.306026299," + "-0.0672231577 0.248528137 0.248528137 -0.107250611 -0.374562227")), + #("2 4 4 4 20,1 1 1 1 5.5", "4 8 11.2 8 46.4,1 1 2.6 1 7.1", "y"), + #("2 4 4 4 20,1 1 1 1 5.5", "4 8 8 11.2 46.4,1 1 1 2.6 7.1", "z"), + #("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", "x"), + #("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "-1 1 2.6 1 -7.1,-4 8 11.2 8 -46.4", "y"), + #("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "-1 1 1 2.6 -7.1,-4 8 8 11.2 -46.4", "z"), + #("2 4 8 12 64,1 1 2 3 11", "4 11.2 16 24 134.4,1 2.6 2 3 12.6", "x"), + #("2 4 8 12 64,1 1 2 3 11", "8 16 35.2 48 268.8,2 2 5.6 6 25.2", "y"), + #("2 4 8 12 64,1 1 2 3 11", "12 24 48 75.2 403.2,3 3 6 10.6 37.8", "z"), + #("1 -1 -2 -3 11,2 -4 -8 -12 64", "-1 2.6 2 3 -12.6,-4 11.2 16 24 -134.4", "x"), + #("1 -1 -2 -3 11,2 -4 -8 -12 64", "-2 2 5.6 6 -25.2,-8 16 35.2 48 -268.8", "y"), + #("1 -1 -2 -3 11,2 -4 -8 -12 64", "-3 3 6 10.6 -37.8,-12 24 48 75.2 -403.2", "z") + ]) def test_flux_splitting_uniform_grid( ctx_factory, states_str, fluxes_str, R_inv_str, wavespeeds_str, fluxes_pos_expected_str, fluxes_neg_expected_str): @@ -26,8 +51,8 @@ def test_flux_splitting_uniform_grid( nvars = 5 - states = u.transposed_array_from_string(states_str) - fluxes = u.transposed_array_from_string(fluxes_str) + states = u.expand_to_6(u.transposed_array_from_string(states_str)) + fluxes = u.expand_to_6(u.transposed_array_from_string(fluxes_str)) R_inv = u.array_from_string(R_inv_str) wavespeeds = u.array_from_string(wavespeeds_str) fluxes_pos_dev = u.empty_array_on_device(queue, nvars, 6) @@ -41,10 +66,10 @@ def test_flux_splitting_uniform_grid( characteristic_fluxes_pos=fluxes_pos_dev, characteristic_fluxes_neg=fluxes_neg_dev) - fluxes_pos_expected = u.array_from_string(fluxes_pos_expected_str) + fluxes_pos_expected = u.expand_to_6(u.transposed_array_from_string(fluxes_pos_expected_str)) u.compare_arrays(fluxes_pos_dev.get(), fluxes_pos_expected) - fluxes_neg_expected = u.array_from_string(fluxes_neg_expected_str) + fluxes_neg_expected = u.expand_to_6(u.transposed_array_from_string(fluxes_neg_expected_str)) u.compare_arrays(fluxes_neg_dev.get(), fluxes_neg_expected) -- GitLab From ac75230792eb159e86e3b7aba8722a0181aef320 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Sat, 29 Jun 2019 00:23:32 -0500 Subject: [PATCH 3/7] mark all passing tests as slow --- test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test.py b/test.py index 6c03a4c..a7596fb 100644 --- a/test.py +++ b/test.py @@ -73,6 +73,7 @@ def test_flux_splitting_uniform_grid( u.compare_arrays(fluxes_neg_dev.get(), fluxes_neg_expected) +@pytest.mark.slow @pytest.mark.parametrize("lam_pointwise_str,lam_roe_str,lam_expected_str", [ ("1 2 3 4 5,2 4 6 8 10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), ("1 2 3 4 5,-2 -4 -6 -8 -10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), @@ -98,6 +99,7 @@ def test_lax_wavespeeds( u.compare_arrays(lam_dev.get(), lam_expected) +@pytest.mark.slow @pytest.mark.parametrize("states_str,direction,lam_expected_str", [ ("2 4 4 4 20,1 1 1 1 5.5", "x", "2 2 2 3.49666295 0.503337045,1 1 1 2.49666295 -0.496662955"), @@ -142,6 +144,7 @@ def test_pointwise_eigenvalues_ideal_gas( u.compare_arrays(lam_dev.get(), lam_expected) +@pytest.mark.slow @pytest.mark.parametrize("states_str,fluxes_str,direction", [ ("2 4 4 4 20,1 1 1 1 5.5", "4 11.2 8 8 46.4,1 2.6 1 1 7.1", "x"), ("2 4 4 4 20,1 1 1 1 5.5", "4 8 11.2 8 46.4,1 1 2.6 1 7.1", "y"), @@ -201,6 +204,7 @@ def test_roe_uniform_grid_ideal_gas(ctx_factory, states_str, fluxes_str, directi check_roe_property(states, fluxes, R, Rinv, lam) +@pytest.mark.slow def test_matvec(ctx_factory): prg = u.get_weno_program_with_root_kernel("mult_mat_vec") queue = u.get_queue(ctx_factory) -- GitLab From d4970c13c1eec2de6e386ac95e05ecbc0ca568fe Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Sat, 29 Jun 2019 00:25:52 -0500 Subject: [PATCH 4/7] loosen tolerance because we are working with single precision --- utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities.py b/utilities.py index c619310..9ae6179 100644 --- a/utilities.py +++ b/utilities.py @@ -11,7 +11,7 @@ from pytest import approx # {{{ arrays def compare_arrays(a, b): - assert a == approx(b) + assert a == approx(b, rel=1e-5) def random_array_on_device(queue, *shape): -- GitLab From 787c1a47673dcc0e1b6414156746e7b6b58a2a65 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Sat, 29 Jun 2019 00:48:22 -0500 Subject: [PATCH 5/7] add additional test cases for flux splitting --- test.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/test.py b/test.py index a7596fb..f215d97 100644 --- a/test.py +++ b/test.py @@ -31,17 +31,28 @@ import utilities as u "0.467376796 -0.6627417 -0.6627417 1.47953026 0.312527304"), ("-0.168354897 -0.0585786438 -0.0585786438 -0.727493464 -0.306026299," "-0.0672231577 0.248528137 0.248528137 -0.107250611 -0.374562227")), - #("2 4 4 4 20,1 1 1 1 5.5", "4 8 11.2 8 46.4,1 1 2.6 1 7.1", "y"), - #("2 4 4 4 20,1 1 1 1 5.5", "4 8 8 11.2 46.4,1 1 1 2.6 7.1", "z"), - #("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", "x"), - #("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "-1 1 2.6 1 -7.1,-4 8 11.2 8 -46.4", "y"), - #("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "-1 1 1 2.6 -7.1,-4 8 8 11.2 -46.4", "z"), - #("2 4 8 12 64,1 1 2 3 11", "4 11.2 16 24 134.4,1 2.6 2 3 12.6", "x"), - #("2 4 8 12 64,1 1 2 3 11", "8 16 35.2 48 268.8,2 2 5.6 6 25.2", "y"), - #("2 4 8 12 64,1 1 2 3 11", "12 24 48 75.2 403.2,3 3 6 10.6 37.8", "z"), - #("1 -1 -2 -3 11,2 -4 -8 -12 64", "-1 2.6 2 3 -12.6,-4 11.2 16 24 -134.4", "x"), - #("1 -1 -2 -3 11,2 -4 -8 -12 64", "-2 2 5.6 6 -25.2,-8 16 35.2 48 -268.8", "y"), - #("1 -1 -2 -3 11,2 -4 -8 -12 64", "-3 3 6 10.6 -37.8,-12 24 48 75.2 -403.2", "z") + ("1 -1 -1 -1 5.5,2 -4 -4 -4 20", "-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", + ("0.367521364 -0.265894836 -0.265894836 -0.265894836 -0.167673798," + "1.12132034 0 0.707106781 0 0," + "1.12132034 0 0 0.707106781 0," + "1.81208206 0.997503897 0.290397116 0.290397116 0.183124984," + "-0.430558632 -0.416709665 0.290397116 0.290397116 0.183124984"), + "2.2 2.2 2.2 0.55367075 3.84632925", + ("0.0672231577 0.248528137 0.248528137 0.374562227 0.107250611," + "0.168354897 -0.0585786438 -0.0585786438 0.306026299 0.727493464"), + ("-0.467376796 -0.6627417 -0.6627417 -0.312527304 -1.47953026," + "-1.09071563 1.23015152 1.23015152 -0.232956271 -7.52305259")), + ("2 4 8 12 64,1 1 2 3 11", "4 11.2 16 24 134.4,1 2.6 2 3 12.6", + ("-1.41187463 0.217276117 0.434552233 0.65182835 -0.13701474," + "-2.24264069 0 0.707106781 0 0," + "-3.36396103 0 0 0.707106781 0," + "1.79265641 0.444598298 -0.525016967 -0.78752545 0.165538358," + "4.03529709 -0.969615265 -0.525016967 -0.78752545 0.165538358"), + "2.2 2.2 2.2 3.84632925 0.55367075", + ("1.1162114 2.46030304 3.69045456 7.98692488 0.429010898," + "0.260735274 -1.3254834 -1.9882251 2.05242289 0.501788756"), + ("-0.148282372 -0.117157288 -0.175735931 -0.889325254 -0.200040418," + "-0.00948821371 0.497056275 0.745584412 -0.430637881 -0.314318322")), ]) def test_flux_splitting_uniform_grid( ctx_factory, states_str, fluxes_str, R_inv_str, wavespeeds_str, -- GitLab From 73613eeacef62de1f3e7481595ac3a2a7e8d14f4 Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Sat, 29 Jun 2019 00:49:35 -0500 Subject: [PATCH 6/7] mark test as slow to facilitate adding future tests --- test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test.py b/test.py index f215d97..23ce5f8 100644 --- a/test.py +++ b/test.py @@ -18,6 +18,7 @@ from pyopencl.tools import ( # noqa import utilities as u +@pytest.mark.slow @pytest.mark.parametrize(("states_str,fluxes_str,R_inv_str,wavespeeds_str," "fluxes_pos_expected_str,fluxes_neg_expected_str"), [ ("2 4 4 4 20,1 1 1 1 5.5", "4 11.2 8 8 46.4,1 2.6 1 1 7.1", -- GitLab From f20a8e6244cb0d93bbbc0e2b5e6af58a76a3191c Mon Sep 17 00:00:00 2001 From: "Timothy A. Smith" Date: Sat, 29 Jun 2019 11:01:32 -0500 Subject: [PATCH 7/7] register pytest.mark.slow so pytest stops whining --- pytest.ini | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..30a7e19 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +markers = + slow: marks tests as slow (deselect with '--runslow') -- GitLab