diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc4e285a47080b868cdf0454a7627cf66c88c5ca..06962c9358837d56f1c19e037c4db7dfc816157a 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 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: + - python3 + except: + - tags + Documentation: script: - EXTRA_INSTALL="numpy" diff --git a/leap/__init__.py b/leap/__init__.py index ec749a570bfd18347c55c33f50bfda7f71a143c4..a078a13eac4abcc3f5e39ab6cf7dd5479e98a544 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 ff1fe06e327e9b65a356e54333d02f83a1ce55fe..619b3cada28c9b8dec89dae16c0feb6552375a6f 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 c64264bc56ced5b8d56e20d24c9bcb73b3ca4e49..6b385929f5b826de76a0b10d49ad073f68d3cfc7 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,22 @@ 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 +564,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 5df7e3de04500c3aebfb40739aaea718f2aacfcc..5c0183fbc120812ebe2b6ba42557311118ad9747 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 b362686f19ffa6cbc07c1b531b2f9140fd88442a..fa75a6c5b522e62a5175aad33f512af9f1e25479 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 c36e2fd64eb5d758d225174298c7a9fa8b48a191..bd01f10cc8498536269edf82d429f6ca0374dde1 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 5eed940262687138b5baa4ed51bfcadd139fb638..95c6e2451bbb142fb41f2e525e53a053cf4176e1 100644 --- a/test/test_multirate.py +++ b/test/test_multirate.py @@ -148,9 +148,9 @@ 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 - show_dependency_graph(self.get_code()) + 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 3f80926b26e0fe33ec9552918d0fece70c2005fc..6e025768e74c8473392e712cd3e1206e08dd3dd0 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,