From becbbccf016e90e5d1398722a725c40642ec1c66 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 3 May 2019 02:48:26 -0500 Subject: [PATCH 1/5] Add Pylint job --- .gitlab-ci.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc4e285..2e67cc3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -57,6 +57,17 @@ Python 3 Examples: reports: junit: test/pytest.xml +Pylint: + script: + - export PY_EXE=python3 + - EXTRA_INSTALL="numpy" + - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-pylint.sh + - ". ./prepare-and-run-pylint.sh leap test/*.py" + tags: + - python3 + except: + - tags + Documentation: script: - EXTRA_INSTALL="numpy" -- GitLab From c85de8f26b595cecb53ba7cfe8208dcd32f76d9b Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 3 May 2019 02:48:30 -0500 Subject: [PATCH 2/5] Pylint fixes --- leap/__init__.py | 5 ++++- leap/multistep/__init__.py | 2 +- leap/rk/__init__.py | 30 +++++++++++++++++++++++++++--- leap/rk/imex.py | 18 +++++++++++++++--- test/multirate_test_systems.py | 6 ++++++ test/test_misc.py | 2 +- test/test_multirate.py | 4 +++- test/utils.py | 2 +- 8 files changed, 58 insertions(+), 11 deletions(-) diff --git a/leap/__init__.py b/leap/__init__.py index ec749a5..a078a13 100644 --- a/leap/__init__.py +++ b/leap/__init__.py @@ -83,7 +83,10 @@ class Method(object): # {{{ two-order adaptivity -class TwoOrderAdaptiveMethod(Method): +class TwoOrderAdaptiveMethodMixin(Method): + """ + This class expected the following members to be defined: state, t, dt. + """ def __init__(self, atol=0, rtol=0, max_dt_growth=None, min_dt_shrinkage=None): self.adaptive = bool(atol or rtol) diff --git a/leap/multistep/__init__.py b/leap/multistep/__init__.py index ff1fe06..619b3ca 100644 --- a/leap/multistep/__init__.py +++ b/leap/multistep/__init__.py @@ -292,7 +292,7 @@ class AdamsBashforthMethod(Method): dt_factor = 1 else: - time_hist = list(range(-self.hist_length+1, 0+1)) + time_hist = list(range(-self.hist_length+1, 0+1)) # noqa pylint:disable=invalid-unary-operand-type dt_factor = self.dt t_end = 1 diff --git a/leap/rk/__init__.py b/leap/rk/__init__.py index c64264b..87f9114 100644 --- a/leap/rk/__init__.py +++ b/leap/rk/__init__.py @@ -29,7 +29,7 @@ THE SOFTWARE. import six import numpy as np -from leap import Method, TwoOrderAdaptiveMethod +from leap import Method, TwoOrderAdaptiveMethodMixin from dagrt.language import CodeBuilder, DAGCode from pymbolic import var @@ -106,6 +106,22 @@ def _is_last_stage_same_as_output(c, coeff_sets, output_stage_coefficients): class ButcherTableauMethod(Method): """Infrastructure to generate code from butcher tableaux.""" + @property + def c(self): + raise NotImplementedError + + @property + def a_explicit(self): + raise NotImplementedError + + @property + def output_coeffs(self): + raise NotImplementedError + + @property + def recycle_last_stage_coeff_set_names(self): + raise NotImplementedError + def __init__(self, component_id, state_filter_name=None): self.component_id = component_id @@ -525,13 +541,21 @@ ORDER_TO_RK_METHOD = { # {{{ Embedded Runge-Kutta schemes base class -class EmbeddedButcherTableauMethod(ButcherTableauMethod, TwoOrderAdaptiveMethod): +class EmbeddedButcherTableauMethod(ButcherTableauMethod, TwoOrderAdaptiveMethodMixin): """ User-supplied context: + component_id: The value that is integrated + component_id: The right hand side function """ + @property + def high_order_coeffs(self): + raise NotImplementedError + + @property + def low_order_coeffs(self): + raise NotImplementedError + def __init__(self, component_id, use_high_order=True, state_filter_name=None, atol=0, rtol=0, max_dt_growth=None, min_dt_shrinkage=None): ButcherTableauMethod.__init__( @@ -539,7 +563,7 @@ class EmbeddedButcherTableauMethod(ButcherTableauMethod, TwoOrderAdaptiveMethod) component_id=component_id, state_filter_name=state_filter_name) - TwoOrderAdaptiveMethod.__init__( + TwoOrderAdaptiveMethodMixin.__init__( self, atol=atol, rtol=rtol, diff --git a/leap/rk/imex.py b/leap/rk/imex.py index 5df7e3d..5c0183f 100644 --- a/leap/rk/imex.py +++ b/leap/rk/imex.py @@ -3,7 +3,7 @@ from __future__ import division from pymbolic import var -from leap import TwoOrderAdaptiveMethod +from leap import TwoOrderAdaptiveMethodMixin from leap.rk import ButcherTableauMethod @@ -43,7 +43,7 @@ IMEX Methods class KennedyCarpenterIMEXRungeKuttaMethodBase( - TwoOrderAdaptiveMethod, ButcherTableauMethod): + TwoOrderAdaptiveMethodMixin, ButcherTableauMethod): """ Christopher A. Kennedy, Mark H. Carpenter. Additive Runge-Kutta schemes for convection-diffusion-reaction equations. @@ -61,6 +61,18 @@ class KennedyCarpenterIMEXRungeKuttaMethodBase( """ + @property + def a_implicit(self): + raise NotImplementedError + + @property + def high_order_coeffs(self): + raise NotImplementedError + + @property + def low_order_coeffs(self): + raise NotImplementedError + def __init__(self, component_id, use_high_order=True, state_filter_name=None, use_explicit=True, use_implicit=True, atol=0, rtol=0, max_dt_growth=None, min_dt_shrinkage=None, @@ -70,7 +82,7 @@ class KennedyCarpenterIMEXRungeKuttaMethodBase( component_id=component_id, state_filter_name=state_filter_name) - TwoOrderAdaptiveMethod.__init__( + TwoOrderAdaptiveMethodMixin.__init__( self, atol=atol, rtol=rtol, diff --git a/test/multirate_test_systems.py b/test/multirate_test_systems.py index b362686..c7ecd3c 100644 --- a/test/multirate_test_systems.py +++ b/test/multirate_test_systems.py @@ -45,6 +45,12 @@ class LinearODESystemsBase(): self.initial_values = np.array([self.soln_0(self.t_start), self.soln_1(self.t_start)]) + def soln_0(self, t): + raise NotImplementedError + + def soln_1(self, t): + raise NotImplementedError + class Basic(LinearODESystemsBase): """ diff --git a/test/test_misc.py b/test/test_misc.py index c36e2fd..bd01f10 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -55,7 +55,7 @@ def test_strang_splitting(plot_solution=False): from pytools.convergence import EOCRecorder eocrec = EOCRecorder() - for dt in 2 ** -np.array(range(4, 7), dtype=np.float64): + for dt in 2 ** -np.array(range(4, 7), dtype=np.float64): # noqa pylint:disable=invalid-unary-operand-type interp = python_method_impl_codegen(code, function_map={ "y1": lambda t, y: 1j*y, "y2": lambda t, y: 2j*y, diff --git a/test/test_multirate.py b/test/test_multirate.py index 5eed940..0e7e16f 100644 --- a/test/test_multirate.py +++ b/test/test_multirate.py @@ -150,7 +150,9 @@ class MultirateTimestepperAccuracyChecker(object): def show_dag(self): from dagrt.language import show_dependency_graph - show_dependency_graph(self.get_code()) + # The value of dt doesn't matter here. + dt = 2 ** -6 + show_dependency_graph(self.get_code(dt)) def plot_solution(self, times, values, soln, label=None): import matplotlib.pyplot as pt diff --git a/test/utils.py b/test/utils.py index 3f80926..6e02576 100644 --- a/test/utils.py +++ b/test/utils.py @@ -92,7 +92,7 @@ class DefaultProblem(Problem): return np.array([v, -u / t ** 2], dtype=np.float64) -_default_dts = 2 ** -np.array(range(4, 7), dtype=np.float64) +_default_dts = 2 ** -np.array(range(4, 7), dtype=np.float64) # noqa pylint:disable=invalid-unary-operand-type def check_simple_convergence(method, method_impl, expected_order, -- GitLab From 78084f12001284dce9ae070f27210abb477b372d Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 3 May 2019 02:51:44 -0500 Subject: [PATCH 3/5] Install scipy and matplotlib --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2e67cc3..06962c9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,7 +60,7 @@ Python 3 Examples: Pylint: script: - export PY_EXE=python3 - - EXTRA_INSTALL="numpy" + - EXTRA_INSTALL="numpy scipy matplotlib" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-pylint.sh - ". ./prepare-and-run-pylint.sh leap test/*.py" tags: -- GitLab From acf5f30be62f7883605c5bcb0bb6663bb70ecb5b Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 3 May 2019 02:52:42 -0500 Subject: [PATCH 4/5] flake8 fixes --- leap/rk/__init__.py | 3 ++- test/multirate_test_systems.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/leap/rk/__init__.py b/leap/rk/__init__.py index 87f9114..6b38592 100644 --- a/leap/rk/__init__.py +++ b/leap/rk/__init__.py @@ -541,7 +541,8 @@ ORDER_TO_RK_METHOD = { # {{{ Embedded Runge-Kutta schemes base class -class EmbeddedButcherTableauMethod(ButcherTableauMethod, TwoOrderAdaptiveMethodMixin): +class EmbeddedButcherTableauMethod( + ButcherTableauMethod, TwoOrderAdaptiveMethodMixin): """ User-supplied context: + component_id: The value that is integrated diff --git a/test/multirate_test_systems.py b/test/multirate_test_systems.py index c7ecd3c..fa75a6c 100644 --- a/test/multirate_test_systems.py +++ b/test/multirate_test_systems.py @@ -47,7 +47,7 @@ class LinearODESystemsBase(): def soln_0(self, t): raise NotImplementedError - + def soln_1(self, t): raise NotImplementedError -- GitLab From f410c3f4655c1a07456c0bed1ed99910f2b4aa35 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 3 May 2019 02:56:24 -0500 Subject: [PATCH 5/5] Promote dt to an argument with a default --- test/test_multirate.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_multirate.py b/test/test_multirate.py index 0e7e16f..95c6e24 100644 --- a/test/test_multirate.py +++ b/test/test_multirate.py @@ -148,10 +148,8 @@ class MultirateTimestepperAccuracyChecker(object): return abs(sqrt(y[0]**2 + y[1]**2) - sqrt(self.ode.soln_0(t)**2 + self.ode.soln_1(t)**2)) - def show_dag(self): + def show_dag(self, dt=2**(-6)): from dagrt.language import show_dependency_graph - # The value of dt doesn't matter here. - dt = 2 ** -6 show_dependency_graph(self.get_code(dt)) def plot_solution(self, times, values, soln, label=None): -- GitLab