diff --git a/examples/adaptive-rk/adaptive-rk.py b/examples/adaptive-rk/adaptive-rk.py index 84a37d08976be6b991b7aaa623cb4ca550527474..72067f5b11ae89194eb290a90bf5a164a4c9bc71 100755 --- a/examples/adaptive-rk/adaptive-rk.py +++ b/examples/adaptive-rk/adaptive-rk.py @@ -10,7 +10,7 @@ Source: Appl. Math. Lett., 2(4):321–325, 1989. doi: 10.1016/0893-9659(89)90079-7. -The same functionality is supported using leap.rk.ODE23Method. +The same functionality is supported using leap.rk.ODE23MethodBuilder. """ diff --git a/examples/imex/imex.py b/examples/imex/imex.py index 62d540d1b8b89d9ad65f9c4c298e398dad8ad05d..d43e9bd7418dc4957c8126829e5aff0f29d89133 100644 --- a/examples/imex/imex.py +++ b/examples/imex/imex.py @@ -83,11 +83,11 @@ def solver_hook(solve_expr, solve_var, solver_id, guess): def run(): - from leap.rk.imex import KennedyCarpenterIMEXARK4Method + from leap.rk.imex import KennedyCarpenterIMEXARK4MethodBuilder from dagrt.codegen import PythonCodeGenerator # Construct the method generator. - mgen = KennedyCarpenterIMEXARK4Method("y", atol=_atol) + mgen = KennedyCarpenterIMEXARK4MethodBuilder("y", atol=_atol) # Generate the code for the method. code = mgen.generate() diff --git a/examples/implicit_euler/implicit_euler.py b/examples/implicit_euler/implicit_euler.py index 6ce1d9e031e476984578e29eb12e71f383017b6c..15a8d8d98b14effe4bbd144278892a7ee50e8011 100644 --- a/examples/implicit_euler/implicit_euler.py +++ b/examples/implicit_euler/implicit_euler.py @@ -1,7 +1,7 @@ """Implicit Euler timestepper""" from __future__ import division -from leap import Method +from leap import MethodBuilder from dagrt.language import DAGCode, CodeBuilder from pymbolic import var from pymbolic.primitives import CallWithKwargs @@ -30,7 +30,7 @@ THE SOFTWARE. """ -class ImplicitEulerMethod(Method): +class ImplicitEulerMethodBuilder(MethodBuilder): """ Context: state: The value that is integrated diff --git a/examples/implicit_euler/test_implicit_euler.py b/examples/implicit_euler/test_implicit_euler.py index ad7da16cab126ddad76d4a2130ae9decd71741ef..cf235cc087d3716f8d22b9935d50a2804873bff0 100755 --- a/examples/implicit_euler/test_implicit_euler.py +++ b/examples/implicit_euler/test_implicit_euler.py @@ -38,7 +38,7 @@ def python_method_impl_interpreter(code, **kwargs): # Taken from test.utils def python_method_impl_codegen(code, **kwargs): from dagrt.codegen import PythonCodeGenerator - codegen = PythonCodeGenerator(class_name='Method') + codegen = PythonCodeGenerator(class_name="Method") return codegen.get_class(code)(**kwargs) @@ -60,9 +60,9 @@ def test_im_euler_accuracy(python_method_impl, show_dag=False, plot_solution=False): component_id = "y" - from implicit_euler import ImplicitEulerMethod + from implicit_euler import ImplicitEulerMethodBuilder - method = ImplicitEulerMethod(component_id) + method = ImplicitEulerMethodBuilder(component_id) code = method.generate(solver_hook) expected_order = 1 diff --git a/examples/rk/run_rk_method.py b/examples/rk/run_rk_method.py index 63d1e78a0c10070793ca89754cfedb71dac5dfa5..c23b0be6c7d959da43a039554a254d6f60849d44 100644 --- a/examples/rk/run_rk_method.py +++ b/examples/rk/run_rk_method.py @@ -25,13 +25,13 @@ THE SOFTWARE. """ -from leap.rk import ODE23Method +from leap.rk import ODE23MethodBuilder import numpy as np def main(show_dag=False, plot_solution=False): component_id = "y" - method = ODE23Method(component_id, use_high_order=True) + method = ODE23MethodBuilder(component_id, use_high_order=True) expected_order = 3 # Use "DEBUG" to trace execution diff --git a/examples/semi-implicit-rk/semi-implicit-rk.py b/examples/semi-implicit-rk/semi-implicit-rk.py index 7d134e346ebf955042d375ff8335941245afaff2..94175c21b6886c0011f1be0aebe733d587bfd4e0 100755 --- a/examples/semi-implicit-rk/semi-implicit-rk.py +++ b/examples/semi-implicit-rk/semi-implicit-rk.py @@ -116,8 +116,8 @@ def demo_rk_implicit(): print(code) from dagrt.codegen import PythonCodeGenerator - IRKMethod = PythonCodeGenerator("IRKMethod").get_class(code) - eocrec = get_convergence_data(IRKMethod, SimpleDecayProblem()) + IRKMethodBuilder = PythonCodeGenerator("IRKMethodBuilder").get_class(code) + eocrec = get_convergence_data(IRKMethodBuilder, SimpleDecayProblem()) print(eocrec.pretty_print()) diff --git a/examples/stability/mr-max-eigvals.py b/examples/stability/mr-max-eigvals.py index 4beab2cd791720f9648ea11d4d454e6717438048..25b70a842d9095ef58c08d21f3df3d0aa3c252cb 100644 --- a/examples/stability/mr-max-eigvals.py +++ b/examples/stability/mr-max-eigvals.py @@ -5,7 +5,7 @@ matplotlib.use("Agg") # noqa import numpy as np import numpy.linalg as la -from leap.multistep.multirate import TwoRateAdamsBashforthMethod +from leap.multistep.multirate import TwoRateAdamsBashforthMethodBuilder import matplotlib.pyplot as pt from functools import partial @@ -36,7 +36,7 @@ def main(): step_ratio = 3 prec = 1e-5 - method = TwoRateAdamsBashforthMethod( + method = TwoRateAdamsBashforthMethodBuilder( method=method_name, order=order, step_ratio=step_ratio, static_dt=True) diff --git a/examples/stability/mr-stability-diagram.py b/examples/stability/mr-stability-diagram.py index 90a47c1150e27a6f523a42ad43bd493d61078d69..dc94910e66140f109a16f1da634be01610ed8a2b 100644 --- a/examples/stability/mr-stability-diagram.py +++ b/examples/stability/mr-stability-diagram.py @@ -5,7 +5,7 @@ matplotlib.use("Agg") # noqa import numpy as np import numpy.linalg as la -from leap.multistep.multirate import TwoRateAdamsBashforthMethod +from leap.multistep.multirate import TwoRateAdamsBashforthMethodBuilder import matplotlib.pyplot as pt @@ -27,7 +27,7 @@ def main(): "- order: %d" % (speed_factor, step_ratio, method_name, order)) - method = TwoRateAdamsBashforthMethod( + method = TwoRateAdamsBashforthMethodBuilder( method=method_name, order=order, step_ratio=step_ratio, static_dt=True) diff --git a/examples/stability/multirate-step-matrix.py b/examples/stability/multirate-step-matrix.py index 1c60cb569a3362ad7b33e165d4844cb3b53d07c9..551e2fad868deba8f53817675fd661a7c13db889 100644 --- a/examples/stability/multirate-step-matrix.py +++ b/examples/stability/multirate-step-matrix.py @@ -1,7 +1,7 @@ from __future__ import division, print_function import numpy as np import numpy.linalg as la -from leap.multistep.multirate import TwoRateAdamsBashforthMethod +from leap.multistep.multirate import TwoRateAdamsBashforthMethodBuilder def main(): @@ -18,7 +18,7 @@ def main(): "- order: %d" % (speed_factor, step_ratio, method_name, order)) - method = TwoRateAdamsBashforthMethod( + method = TwoRateAdamsBashforthMethodBuilder( method=method_name, order=order, step_ratio=step_ratio, static_dt=True) diff --git a/examples/stability/plot-stability-regions.py b/examples/stability/plot-stability-regions.py index 754ea1ad4221151928dc9db08e4473c6bb26b7a5..b9444f2c0c334b343d9597cbaf9cdbf6111f1ac0 100644 --- a/examples/stability/plot-stability-regions.py +++ b/examples/stability/plot-stability-regions.py @@ -29,12 +29,12 @@ def main(save_pdfs=True): import leap.multistep as multistep for label, method, factor in [ - #("ode23", rk.ODE23Method("y", use_high_order=True), 1), - #("ab2", multistep.AdamsBashforthMethod("y", 2), 1), - ("ab3", multistep.AdamsBashforthMethod("y", 3), 1), - #("ab4", multistep.AdamsBashforthMethod("y", 4), 1), - ("lserk", rk.LSRK4Method("y"), 1/5), - ("rk4", rk.RK4Method("y"), 1/4), + #("ode23", rk.ODE23MethodBuilder("y", use_high_order=True), 1), + #("ab2", multistep.AdamsBashforthMethodBuilder("y", 2), 1), + ("ab3", multistep.AdamsBashforthMethodBuilder("y", 3), 1), + #("ab4", multistep.AdamsBashforthMethodBuilder("y", 4), 1), + ("lserk", rk.LSRK4MethodBuilder("y"), 1/5), + ("rk4", rk.RK4MethodBuilder("y"), 1/4), ]: code = method.generate() diff --git a/examples/stability/step-matrix.py b/examples/stability/step-matrix.py index 2cb942a7c3312b512db8d6ffe0837796daa935f6..2d3acf8fda3e3752ac3ac407e1b75d03df734e4f 100644 --- a/examples/stability/step-matrix.py +++ b/examples/stability/step-matrix.py @@ -1,8 +1,8 @@ from __future__ import division, print_function import numpy as np import numpy.linalg as la -from leap.rk import RK4Method # noqa -from leap.multistep import AdamsBashforthMethod # noqa +from leap.rk import RK4MethodBuilder # noqa +from leap.multistep import AdamsBashforthMethodBuilder # noqa def main(): @@ -10,8 +10,8 @@ def main(): from pymbolic import var - #method = RK4Method("y") - method = AdamsBashforthMethod("y", order=3, static_dt=True) + #method = RK4MethodBuilder("y") + method = AdamsBashforthMethodBuilder("y", order=3, static_dt=True) code = method.generate() diff --git a/examples/variable-coeff-wave-equation/wave-equation.py b/examples/variable-coeff-wave-equation/wave-equation.py index cb8a5d9fef1bc7410c89a9b36fa419433958b488..b0cd1bba46bae4d7677f2309c429784dafd1efdd 100755 --- a/examples/variable-coeff-wave-equation/wave-equation.py +++ b/examples/variable-coeff-wave-equation/wave-equation.py @@ -264,12 +264,12 @@ def make_3_component_multirate_method( """ from leap.multistep.multirate import ( - MultiRateMultiStepMethod, MultiRateHistory) + MultiRateMultiStepMethodBuilder, MultiRateHistory) ncomponents = 3 assert problem.ncomponents == ncomponents - code = MultiRateMultiStepMethod( + code = MultiRateMultiStepMethodBuilder( default_order=3, system_description=( ("dt", "comp0", @@ -309,7 +309,7 @@ def make_3_component_multirate_method( return code from dagrt.codegen import PythonCodeGenerator - MRABMethod = PythonCodeGenerator(class_name='MRABMethod').get_class(code) # noqa + MRABMethod = PythonCodeGenerator(class_name="MRABMethod").get_class(code) # noqa if return_rhs_map: return MRABMethod(rhs_map), rhs_map diff --git a/experiments/pde-discretization/pde-discretization.py b/experiments/pde-discretization/pde-discretization.py index 2fce9e6b9cd55921c82c9156de731815a0dc1fb8..a8c4277e8dbea224c2802d8e76e47d063ed51194 100644 --- a/experiments/pde-discretization/pde-discretization.py +++ b/experiments/pde-discretization/pde-discretization.py @@ -11,7 +11,7 @@ partitioned than [0, 1] by a given ratio. from __future__ import division from dagrt.codegen import PythonCodeGenerator -from leap.multistep.multirate import TwoRateAdamsBashforthMethod +from leap.multistep.multirate import TwoRateAdamsBashforthMethodBuilder import numpy as np import scipy.linalg as sla @@ -107,7 +107,7 @@ def make_multirate_method(f2f, s2f, f2s, s2s, ratio=2, order=3): """Return the object that drives the multirate method for the given parameters.""" FastestFirst = "Fq" - code = TwoRateAdamsBashforthMethod(FastestFirst, order, ratio).generate() + code = TwoRateAdamsBashforthMethodBuilder(FastestFirst, order, ratio).generate() MRABMethod = PythonCodeGenerator(class_name='MRABMethod').get_class(code) rhs_map = {'f2f': f2f, 's2f': s2f, 'f2s': f2s, diff --git a/experiments/stability-study/mrab_stability.py b/experiments/stability-study/mrab_stability.py index bd18e0e83364eb9cd00b87129f2eaa59b5391e63..1fd3eee9a0ecf7863896e224d3017561085e7ae0 100644 --- a/experiments/stability-study/mrab_stability.py +++ b/experiments/stability-study/mrab_stability.py @@ -266,13 +266,13 @@ def make_method_matrix(stepper, rhss, f_size, s_size): -class MethodFactory(FactoryWithParameters): +class MethodBuilderFactory(FactoryWithParameters): __slots__ = ["method", "substep_count", "meth_order"] def __call__(self, dt): from hedge.timestep.multirate_ab import \ - TwoRateAdamsBashforthMethod - return TwoRateAdamsBashforthMethod( + TwoRateAdamsBashforthMethodBuilder + return TwoRateAdamsBashforthMethodBuilder( method=self.method, large_dt=dt, substep_count=self.substep_count, @@ -285,13 +285,13 @@ def generate_method_factories(): for method in methods.keys(): for order in [3]: for substep_count in [2, 3, 4]: - yield MethodFactory(method=method, meth_order=order, + yield MethodBuilderFactory(method=method, meth_order=order, substep_count=substep_count) else: for method in ["Fqsr"]: for order in [3]: for substep_count in [2, 3]: - yield MethodFactory(method=method, meth_order=order, + yield MethodBuilderFactory(method=method, meth_order=order, substep_count=substep_count) @@ -301,7 +301,7 @@ def generate_method_factories_hires(): for method in ["Fq", "Ssf", "Sr"]: for order in [3]: for substep_count in [2, 5, 10]: - yield MethodFactory(method=method, meth_order=order, + yield MethodBuilderFactory(method=method, meth_order=order, substep_count=substep_count) @@ -416,12 +416,12 @@ def generate_mrab_jobs_step_verify(): # {{{ single-rate reference --------------------------------------------------- -class SRABMethodFactory(FactoryWithParameters): +class SRABMethodBuilderFactory(FactoryWithParameters): __slots__ = ["method", "substep_count", "meth_order"] def __call__(self): - from hedge.timestep.ab import AdamsBashforthMethod - return AdamsBashforthMethod(order=self.meth_order, + from hedge.timestep.ab import AdamsBashforthMethodBuilder + return AdamsBashforthMethodBuilder(order=self.meth_order, dtype=numpy.complex128) @@ -450,7 +450,7 @@ class SRABJob(IterativeStabilityTester): def generate_srab_jobs(): - for method_fac in [SRABMethodFactory(method="SRAB", substep_count=1, meth_order=3)]: + for method_fac in [SRABMethodBuilderFactory(method="SRAB", substep_count=1, meth_order=3)]: for matrix_fac in generate_matrix_factories(): yield SRABJob(method_fac, matrix_fac, 120) @@ -461,9 +461,9 @@ def generate_srab_jobs(): def test(): from hedge.timestep.multirate_ab import \ - TwoRateAdamsBashforthMethod + TwoRateAdamsBashforthMethodBuilder from pymbolic import var - stepper = TwoRateAdamsBashforthMethod( + stepper = TwoRateAdamsBashforthMethodBuilder( method="Fqsr", large_dt=var("dt"), substep_count=2, diff --git a/leap/__init__.py b/leap/__init__.py index df957ddb30bf704cf6000ea8b8c9185618c0221f..3cd06abb94b2d1b4376ce9b9821ed62affcb104d 100644 --- a/leap/__init__.py +++ b/leap/__init__.py @@ -50,9 +50,9 @@ def run_script_from_commandline(): # }}} -# {{{ method base class +# {{{ method builder base class -class Method(object): +class MethodBuilder(object): def generate(self, *solver_hooks): """ @@ -83,7 +83,7 @@ class Method(object): # {{{ two-order adaptivity -class TwoOrderAdaptiveMethodMixin(Method): +class TwoOrderAdaptiveMethodBuilderMixin(MethodBuilder): """ This class expected the following members to be defined: state, t, dt. """ diff --git a/leap/multistep/__init__.py b/leap/multistep/__init__.py index c18155e6fdba8d1a3cf9ae0a2ab9488d6f70a2d6..e357a47d6742adf5a4e2029487861d0743215a6f 100644 --- a/leap/multistep/__init__.py +++ b/leap/multistep/__init__.py @@ -31,12 +31,12 @@ THE SOFTWARE. import six.moves import numpy as np import numpy.linalg as la -from leap import Method +from leap import MethodBuilder from pymbolic import var __doc__ = """ -.. autoclass:: AdamsBashforthMethod +.. autoclass:: AdamsBashforthMethodBuilder """ @@ -197,7 +197,7 @@ def emit_ab_extrapolation(cb, name_gen, # {{{ ab method -class AdamsBashforthMethod(Method): +class AdamsBashforthMethodBuilder(MethodBuilder): """ User-supplied context: + component_id: The value that is integrated @@ -228,7 +228,7 @@ class AdamsBashforthMethod(Method): if isinstance(function_family, int): function_family = ABMonomialIntegrationFunctionFamily(function_family) - super(AdamsBashforthMethod, self).__init__() + super(AdamsBashforthMethodBuilder, self).__init__() self.function_family = function_family if hist_length is None: @@ -372,12 +372,12 @@ class AdamsBashforthMethod(Method): if not self.static_dt: cb(self.time_history[i], self.t) - from leap.rk import ORDER_TO_RK_METHOD - rk_method = ORDER_TO_RK_METHOD[self.function_family.order] + from leap.rk import ORDER_TO_RK_METHOD_BUILDER + rk_method = ORDER_TO_RK_METHOD_BUILDER[self.function_family.order] rk_tableau = tuple(zip(rk_method.c, rk_method.a_explicit)) rk_coeffs = rk_method.output_coeffs - # Stage loop (taken from EmbeddedButcherTableauMethod) + # Stage loop (taken from EmbeddedButcherTableauMethodBuilder) rhss = [var("rk_rhs_" + str(i)) for i in range(len(rk_tableau))] for stage_num, (c, coeffs) in enumerate(rk_tableau): if len(coeffs) == 0: diff --git a/leap/multistep/multirate/__init__.py b/leap/multistep/multirate/__init__.py index 8d172f9643edc4bc50288b3a3d7eb17d23b3bbce..8f4d60df6cf8350349158085684512be2c518ebc 100644 --- a/leap/multistep/multirate/__init__.py +++ b/leap/multistep/multirate/__init__.py @@ -31,7 +31,7 @@ THE SOFTWARE. import six from pytools import Record -from leap import Method +from leap import MethodBuilder from pymbolic import var from leap.multistep import _linear_comb @@ -41,7 +41,7 @@ __doc__ = """ .. autoclass:: rhs_policy .. autoclass:: MultiRateHistory -.. autoclass:: MultiRateMultiStepMethod +.. autoclass:: MultiRateMultiStepMethodBuilder .. autoclass:: SchemeExplainerBase .. autoclass:: TextualSchemeExplainer @@ -74,7 +74,7 @@ class MultiRateHistory(Record): updated. (where each update will typically involve a call to *func_name*) :arg arguments: A tuple of component names - (see :class:`MultiRateMultiStepMethod`) + (see :class:`MultiRateMultiStepMethodBuilder`) which are passed to this right-hand side function. :arg order: The AB approximation order to be used for this history, or None if the method default is to be used. @@ -157,7 +157,7 @@ class InconsistentHistoryError: # {{{ method -class MultiRateMultiStepMethod(Method): +class MultiRateMultiStepMethodBuilder(MethodBuilder): """Simultaneously timesteps multiple parts of an ODE system, each with adjustable orders, rates, and dependencies. @@ -223,7 +223,7 @@ class MultiRateMultiStepMethod(Method): :arg static_dt: If *True*, changing the timestep in between steps during time integration is not allowed. """ - super(MultiRateMultiStepMethod, self).__init__() + super(MultiRateMultiStepMethodBuilder, self).__init__() # Variables from pymbolic import var @@ -418,8 +418,8 @@ class MultiRateMultiStepMethod(Method): def emit_small_rk_step(self, cb, name_prefix, name_gen, rhss_on_entry): """Emit a single step of an RK method.""" - from leap.rk import ORDER_TO_RK_METHOD - rk_method = ORDER_TO_RK_METHOD[self.max_order] + from leap.rk import ORDER_TO_RK_METHOD_BUILDER + rk_method = ORDER_TO_RK_METHOD_BUILDER[self.max_order] rk_tableau = tuple(zip(rk_method.c, rk_method.a_explicit)) rk_coeffs = rk_method.output_coeffs @@ -1149,7 +1149,7 @@ class MultiRateMultiStepMethod(Method): # {{{ two-rate compatibility shim -class TwoRateAdamsBashforthMethod(MultiRateMultiStepMethod): +class TwoRateAdamsBashforthMethodBuilder(MultiRateMultiStepMethodBuilder): methods = [ "Sqrs", "Sqr", @@ -1188,9 +1188,10 @@ class TwoRateAdamsBashforthMethod(MultiRateMultiStepMethod): hist_length_slow=None, hist_length_fast=None): from warnings import warn - warn("TwoRateAdamsBashforthMethod is a compatibility shim that should no " + warn("TwoRateAdamsBashforthMethodBuilder " + "is a compatibility shim that should no " "longer be used. Use the fully general " - "MultiRateMultiStepMethod interface instead.", + "MultiRateMultiStepMethodBuilder interface instead.", DeprecationWarning, stacklevel=2) if "S" in method: @@ -1224,7 +1225,7 @@ class TwoRateAdamsBashforthMethod(MultiRateMultiStepMethod): if hist_length_fast is None: hist_length_slow = order - super(TwoRateAdamsBashforthMethod, self).__init__( + super(TwoRateAdamsBashforthMethodBuilder, self).__init__( order, ( ( diff --git a/leap/rk/__init__.py b/leap/rk/__init__.py index 9b474c58c43395501a3341686a25ca5634ca945c..0cdb4f3bee3695d9a8598f2ca306db094c963be2 100644 --- a/leap/rk/__init__.py +++ b/leap/rk/__init__.py @@ -29,35 +29,36 @@ THE SOFTWARE. import six import numpy as np -from leap import Method, TwoOrderAdaptiveMethodMixin +from leap import MethodBuilder, TwoOrderAdaptiveMethodBuilderMixin from dagrt.language import CodeBuilder, DAGCode from pymbolic import var __doc__ = """ -.. data:: ORDER_TO_RK_METHOD +.. data:: ORDER_TO_RK_METHOD_BUILDER - A dictionary mapping desired order of accuracy to a corresponding RK method. + A dictionary mapping desired order of accuracy to a corresponding RK method + builder. -.. autoclass:: ForwardEulerMethod -.. autoclass:: BackwardEulerMethod -.. autoclass:: MidpointMethod -.. autoclass:: HeunsMethod -.. autoclass:: RK3Method -.. autoclass:: RK4Method -.. autoclass:: RK5Method +.. autoclass:: ForwardEulerMethodBuilder +.. autoclass:: BackwardEulerMethodBuilder +.. autoclass:: MidpointMethodBuilder +.. autoclass:: HeunsMethodBuilder +.. autoclass:: RK3MethodBuilder +.. autoclass:: RK4MethodBuilder +.. autoclass:: RK5MethodBuilder Low-Storage Methods ------------------- -.. autoclass:: LSRK4Method +.. autoclass:: LSRK4MethodBuilder Adaptive/Embedded Methods ------------------------- -.. autoclass:: ODE23Method -.. autoclass:: ODE45Method +.. autoclass:: ODE23MethodBuilder +.. autoclass:: ODE45MethodBuilder """ @@ -103,7 +104,7 @@ def _is_last_stage_same_as_output(c, coeff_sets, output_stage_coefficients): # {{{ fully general butcher tableau to code -class ButcherTableauMethod(Method): +class ButcherTableauMethodBuilder(MethodBuilder): """Infrastructure to generate code from butcher tableaux.""" @property @@ -369,10 +370,10 @@ class ButcherTableauMethod(Method): # {{{ simple butcher tableau methods -class SimpleButcherTableauMethod(ButcherTableauMethod): +class SimpleButcherTableauMethodBuilder(ButcherTableauMethodBuilder): def __init__(self, component_id, state_filter_name=None, rhs_func_name=None): - super(SimpleButcherTableauMethod, self).__init__( + super(SimpleButcherTableauMethodBuilder, self).__init__( component_id=component_id, state_filter_name=state_filter_name) @@ -395,7 +396,7 @@ class SimpleButcherTableauMethod(ButcherTableauMethod): }) -class ForwardEulerMethod(SimpleButcherTableauMethod): +class ForwardEulerMethodBuilder(SimpleButcherTableauMethodBuilder): """ .. automethod:: __init__ .. automethod:: generate @@ -411,7 +412,7 @@ class ForwardEulerMethod(SimpleButcherTableauMethod): recycle_last_stage_coeff_set_names = () -class BackwardEulerMethod(SimpleButcherTableauMethod): +class BackwardEulerMethodBuilder(SimpleButcherTableauMethodBuilder): """ .. automethod:: __init__ .. automethod:: generate @@ -427,7 +428,7 @@ class BackwardEulerMethod(SimpleButcherTableauMethod): recycle_last_stage_coeff_set_names = () -class MidpointMethod(SimpleButcherTableauMethod): +class MidpointMethodBuilder(SimpleButcherTableauMethodBuilder): """ .. automethod:: __init__ .. automethod:: generate @@ -444,7 +445,7 @@ class MidpointMethod(SimpleButcherTableauMethod): recycle_last_stage_coeff_set_names = () -class HeunsMethod(SimpleButcherTableauMethod): +class HeunsMethodBuilder(SimpleButcherTableauMethodBuilder): """ .. automethod:: __init__ .. automethod:: generate @@ -461,9 +462,9 @@ class HeunsMethod(SimpleButcherTableauMethod): recycle_last_stage_coeff_set_names = () -class RK3Method(SimpleButcherTableauMethod): +class RK3MethodBuilder(SimpleButcherTableauMethodBuilder): """ - Source: J. C. Butcher, Numerical Methods for Ordinary Differential + Source: J. C. Butcher, Numerical MethodBuilders for Ordinary Differential Equations, 2nd ed., pages 94 - 99 .. automethod:: __init__ @@ -482,7 +483,7 @@ class RK3Method(SimpleButcherTableauMethod): recycle_last_stage_coeff_set_names = () -class RK4Method(SimpleButcherTableauMethod): +class RK4MethodBuilder(SimpleButcherTableauMethodBuilder): """ .. automethod:: __init__ .. automethod:: generate @@ -501,9 +502,9 @@ class RK4Method(SimpleButcherTableauMethod): recycle_last_stage_coeff_set_names = () -class RK5Method(SimpleButcherTableauMethod): +class RK5MethodBuilder(SimpleButcherTableauMethodBuilder): """ - Source: J. C. Butcher, Numerical Methods for Ordinary Differential + Source: J. C. Butcher, Numerical MethodBuilders for Ordinary Differential Equations, 2nd ed., pages 94 - 99 """ @@ -523,12 +524,12 @@ class RK5Method(SimpleButcherTableauMethod): recycle_last_stage_coeff_set_names = () -ORDER_TO_RK_METHOD = { - 1: ForwardEulerMethod, - 2: MidpointMethod, - 3: RK3Method, - 4: RK4Method, - 5: RK5Method, +ORDER_TO_RK_METHOD_BUILDER = { + 1: ForwardEulerMethodBuilder, + 2: MidpointMethodBuilder, + 3: RK3MethodBuilder, + 4: RK4MethodBuilder, + 5: RK5MethodBuilder, } # }}} @@ -536,8 +537,8 @@ ORDER_TO_RK_METHOD = { # {{{ Embedded Runge-Kutta schemes base class -class EmbeddedButcherTableauMethod( - ButcherTableauMethod, TwoOrderAdaptiveMethodMixin): +class EmbeddedButcherTableauMethodBuilder( + ButcherTableauMethodBuilder, TwoOrderAdaptiveMethodBuilderMixin): """ User-supplied context: + component_id: The value that is integrated @@ -554,12 +555,12 @@ class EmbeddedButcherTableauMethod( 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__( + ButcherTableauMethodBuilder.__init__( self, component_id=component_id, state_filter_name=state_filter_name) - TwoOrderAdaptiveMethodMixin.__init__( + TwoOrderAdaptiveMethodBuilderMixin.__init__( self, atol=atol, rtol=rtol, @@ -590,7 +591,7 @@ class EmbeddedButcherTableauMethod( def finish(self, cb, estimate_coeff_set_names, estimate_vars): if not self.adaptive: - super(EmbeddedButcherTableauMethod, self).finish( + super(EmbeddedButcherTableauMethodBuilder, self).finish( cb, estimate_coeff_set_names, estimate_vars) else: high_est = estimate_vars[ @@ -614,7 +615,7 @@ class EmbeddedButcherTableauMethod( # {{{ Bogacki-Shampine second/third-order Runge-Kutta -class ODE23Method(EmbeddedButcherTableauMethod): +class ODE23MethodBuilder(EmbeddedButcherTableauMethodBuilder): """Bogacki-Shampine second/third-order Runge-Kutta. (same as Matlab's ode23) @@ -648,7 +649,7 @@ class ODE23Method(EmbeddedButcherTableauMethod): # {{{ Dormand-Prince fourth/fifth-order Runge-Kutta -class ODE45Method(EmbeddedButcherTableauMethod): +class ODE45MethodBuilder(EmbeddedButcherTableauMethodBuilder): """Dormand-Prince fourth/fifth-order Runge-Kutta. (same as Matlab's ode45) @@ -685,10 +686,10 @@ class ODE45Method(EmbeddedButcherTableauMethod): # {{{ Carpenter/Kennedy low-storage fourth-order Runge-Kutta -class LSRK4Method(Method): +class LSRK4MethodBuilder(MethodBuilder): """A low storage fourth-order Runge-Kutta method - See JSH, TW: Nodal Discontinuous Galerkin Methods p.64 + See JSH, TW: Nodal Discontinuous Galerkin MethodBuilders p.64 or Carpenter, M.H., and Kennedy, C.A., Fourth-order-2N-storage Runge-Kutta schemes, NASA Langley Tech Report TM 109112, 1994 diff --git a/leap/rk/imex.py b/leap/rk/imex.py index af6631552c57e86f47b5fdcbbdaf9a26793fd785..b4884b964ae986aac10e67e59a3c45df7b7a2814 100644 --- a/leap/rk/imex.py +++ b/leap/rk/imex.py @@ -3,8 +3,8 @@ from __future__ import division from pymbolic import var -from leap import TwoOrderAdaptiveMethodMixin -from leap.rk import ButcherTableauMethod +from leap import TwoOrderAdaptiveMethodBuilderMixin +from leap.rk import ButcherTableauMethodBuilder __copyright__ = """ @@ -35,15 +35,15 @@ THE SOFTWARE. __doc__ = """ -IMEX Methods +IMEX MethodBuilders ------------ -.. autoclass :: KennedyCarpenterIMEXRungeKuttaMethodBase +.. autoclass :: KennedyCarpenterIMEXRungeKuttaMethodBuilderBase """ -class KennedyCarpenterIMEXRungeKuttaMethodBase( - TwoOrderAdaptiveMethodMixin, ButcherTableauMethod): +class KennedyCarpenterIMEXRungeKuttaMethodBuilderBase( + TwoOrderAdaptiveMethodBuilderMixin, ButcherTableauMethodBuilder): """ Christopher A. Kennedy, Mark H. Carpenter. Additive Runge-Kutta schemes for convection-diffusion-reaction equations. @@ -77,12 +77,12 @@ class KennedyCarpenterIMEXRungeKuttaMethodBase( use_explicit=True, use_implicit=True, atol=0, rtol=0, max_dt_growth=None, min_dt_shrinkage=None, implicit_rhs_name=None, explicit_rhs_name=None): - ButcherTableauMethod.__init__( + ButcherTableauMethodBuilder.__init__( self, component_id=component_id, state_filter_name=state_filter_name) - TwoOrderAdaptiveMethodMixin.__init__( + TwoOrderAdaptiveMethodBuilderMixin.__init__( self, atol=atol, rtol=rtol, @@ -135,7 +135,7 @@ class KennedyCarpenterIMEXRungeKuttaMethodBase( def finish(self, cb, estimate_coeff_set_names, estimate_vars): if not self.adaptive: - super(KennedyCarpenterIMEXRungeKuttaMethodBase, self).finish( + super(KennedyCarpenterIMEXRungeKuttaMethodBuilderBase, self).finish( cb, estimate_coeff_set_names, estimate_vars) else: high_est = estimate_vars[ @@ -155,7 +155,8 @@ class KennedyCarpenterIMEXRungeKuttaMethodBase( cb(self.t, self.t + self.dt) -class KennedyCarpenterIMEXARK4Method(KennedyCarpenterIMEXRungeKuttaMethodBase): +class KennedyCarpenterIMEXARK4MethodBuilder( + KennedyCarpenterIMEXRungeKuttaMethodBuilderBase): gamma = 1./4. c = [0, 1/2, 83/250, 31/50, 17/20, 1] diff --git a/leap/version.py b/leap/version.py index 0d96d97a7541d7b87196329b1912c2f2808cd501..6f62bed21b8e655e05f84adad5649d80bda72799 100644 --- a/leap/version.py +++ b/leap/version.py @@ -1,2 +1,2 @@ -VERSION = (2019, 4) +VERSION = (2019, 5) VERSION_TEXT = ".".join(str(i) for i in VERSION) diff --git a/test/test_ab.py b/test/test_ab.py index 57667ebbe97d9903f3c453f1a366455ee0f87bdc..ea26fb890b0a7ce3147cd14fd9a0dabfa0b0b63c 100755 --- a/test/test_ab.py +++ b/test/test_ab.py @@ -26,7 +26,7 @@ THE SOFTWARE. import sys import pytest -from leap.multistep import AdamsBashforthMethod +from leap.multistep import AdamsBashforthMethodBuilder from utils import ( # noqa python_method_impl_interpreter as pmi_int, @@ -34,11 +34,11 @@ from utils import ( # noqa @pytest.mark.parametrize(("method", "expected_order"), [ - (AdamsBashforthMethod("y", order, static_dt=static_dt), order) + (AdamsBashforthMethodBuilder("y", order, static_dt=static_dt), order) for order in [1, 3, 5] for static_dt in [True, False] ] + [ - (AdamsBashforthMethod("y", order, hist_length=order+1, + (AdamsBashforthMethodBuilder("y", order, hist_length=order+1, static_dt=static_dt), order) for order in [1, 3, 5] for static_dt in [True, False] diff --git a/test/test_codegen_fortran.py b/test/test_codegen_fortran.py index 829178f3a80052895ea5597611d21c188ea0a2b7..12bdd5b0b1859a74926bf220d5674a76a57b1e3f 100755 --- a/test/test_codegen_fortran.py +++ b/test/test_codegen_fortran.py @@ -27,9 +27,11 @@ import sys import pytest import dagrt.codegen.fortran as f -from leap.rk import ODE23Method, ODE45Method, RK4Method, LSRK4Method +from leap.rk import ( + ODE23MethodBuilder, ODE45MethodBuilder, RK4MethodBuilder, + LSRK4MethodBuilder) -from leap.multistep.multirate import TwoRateAdamsBashforthMethod +from leap.multistep.multirate import TwoRateAdamsBashforthMethodBuilder from dagrt.utils import run_fortran @@ -47,12 +49,12 @@ def read_file(rel_path): # {{{ test rk methods @pytest.mark.parametrize(("min_order", "stepper"), [ - (2, ODE23Method("y", use_high_order=False)), - (3, ODE23Method("y", use_high_order=True)), - (4, ODE45Method("y", use_high_order=False)), - (5, ODE45Method("y", use_high_order=True)), - (4, RK4Method("y")), - (4, LSRK4Method("y")), + (2, ODE23MethodBuilder("y", use_high_order=False)), + (3, ODE23MethodBuilder("y", use_high_order=True)), + (4, ODE45MethodBuilder("y", use_high_order=False)), + (5, ODE45MethodBuilder("y", use_high_order=True)), + (4, RK4MethodBuilder("y")), + (4, LSRK4MethodBuilder("y")), ]) def test_rk_codegen(min_order, stepper, print_code=False): """Test whether Fortran code generation for the Runge-Kutta @@ -74,7 +76,7 @@ def test_rk_codegen(min_order, stepper, print_code=False): code = stepper.generate() codegen = f.CodeGenerator( - 'RKMethod', + "RKMethod", user_type_map={ component_id: f.ArrayType( (2,), @@ -111,7 +113,7 @@ def test_rk_codegen_fancy(): rhs_function = 'y' state_filter_name = 'state_filter_y' - stepper = ODE23Method(component_id, use_high_order=True, + stepper = ODE23MethodBuilder(component_id, use_high_order=True, state_filter_name=state_filter_name) from dagrt.function_registry import ( @@ -172,7 +174,7 @@ def test_rk_codegen_fancy(): code = stepper.generate() codegen = f.CodeGenerator( - 'RKMethod', + "RKMethod", user_type_map={ component_id: f.ArrayType( "region%n_grids", @@ -216,11 +218,11 @@ def test_rk_codegen_fancy(): @pytest.mark.parametrize("min_order", [2, 3, 4, 5]) -@pytest.mark.parametrize("method_name", TwoRateAdamsBashforthMethod.methods) +@pytest.mark.parametrize("method_name", TwoRateAdamsBashforthMethodBuilder.methods) def test_multirate_codegen(min_order, method_name): - from leap.multistep.multirate import TwoRateAdamsBashforthMethod + from leap.multistep.multirate import TwoRateAdamsBashforthMethodBuilder - stepper = TwoRateAdamsBashforthMethod( + stepper = TwoRateAdamsBashforthMethodBuilder( method_name, min_order, 4, slow_state_filter_name="slow_filt", fast_state_filter_name="fast_filt", @@ -297,7 +299,7 @@ def test_multirate_codegen(min_order, method_name): """)) codegen = f.CodeGenerator( - 'MRAB', + "MRAB", user_type_map={ "slow": f.ArrayType( (1,), @@ -346,7 +348,7 @@ def test_adaptive_rk_codegen(): component_id = 'y' rhs_function = 'y' - stepper = ODE45Method(component_id, use_high_order=False, rtol=1e-6) + stepper = ODE45MethodBuilder(component_id, use_high_order=False, rtol=1e-6) from dagrt.function_registry import ( base_function_registry, register_ode_rhs) @@ -361,7 +363,7 @@ def test_adaptive_rk_codegen(): code = stepper.generate() codegen = f.CodeGenerator( - 'RKMethod', + "RKMethod", user_type_map={ "y": f.ArrayType( (2,), @@ -384,7 +386,7 @@ def test_adaptive_rk_codegen_error(): component_id = 'y' rhs_function = 'y' - stepper = ODE45Method(component_id, use_high_order=False, atol=1e-6) + stepper = ODE45MethodBuilder(component_id, use_high_order=False, atol=1e-6) from dagrt.function_registry import ( base_function_registry, register_ode_rhs) @@ -398,7 +400,7 @@ def test_adaptive_rk_codegen_error(): code = stepper.generate() codegen = f.CodeGenerator( - 'RKMethod', + "RKMethod", user_type_map={ component_id: f.ArrayType( (2,), @@ -416,12 +418,12 @@ def test_adaptive_rk_codegen_error(): @pytest.mark.parametrize(("min_order", "hist_length"), [(5, 5), (4, 4), (4, 5), (3, 3), (3, 4), (2, 2), ]) def test_singlerate_squarewave(min_order, hist_length): - from leap.multistep import AdamsBashforthMethod + from leap.multistep import AdamsBashforthMethodBuilder component_id = 'y' rhs_function = 'y' - stepper = AdamsBashforthMethod("y", min_order, hist_length=hist_length) + stepper = AdamsBashforthMethodBuilder("y", min_order, hist_length=hist_length) from dagrt.function_registry import ( base_function_registry, register_ode_rhs) @@ -435,7 +437,7 @@ def test_singlerate_squarewave(min_order, hist_length): code = stepper.generate() codegen = f.CodeGenerator( - 'ABMethod', + "ABMethod", user_type_map={ component_id: f.ArrayType( (2,), @@ -461,11 +463,11 @@ def test_singlerate_squarewave(min_order, hist_length): ) -@pytest.mark.parametrize("method_name", TwoRateAdamsBashforthMethod.methods) +@pytest.mark.parametrize("method_name", TwoRateAdamsBashforthMethodBuilder.methods) @pytest.mark.parametrize(("min_order", "hist_length"), [(4, 4), (4, 5), (3, 3), (3, 4), (2, 2), ]) def test_multirate_squarewave(min_order, hist_length, method_name): - stepper = TwoRateAdamsBashforthMethod(method_name, min_order, 4, + stepper = TwoRateAdamsBashforthMethodBuilder(method_name, min_order, 4, hist_consistency_threshold=1e-8, early_hist_consistency_threshold="3.5e3 *
**%d" % min_order, hist_length_slow=hist_length, hist_length_fast=hist_length) @@ -520,7 +522,7 @@ def test_multirate_squarewave(min_order, hist_length, method_name): """)) codegen = f.CodeGenerator( - 'MRAB', + "MRAB", user_type_map={ "slow": f.ArrayType( (1,), diff --git a/test/test_imex.py b/test/test_imex.py index 07ae489737a593553cc27c67bda03edaafdf7df8..8e5b1d973885baca30e65ca56186c790575033a2 100755 --- a/test/test_imex.py +++ b/test/test_imex.py @@ -28,7 +28,7 @@ import numpy as np import pytest import sys -from leap.rk.imex import KennedyCarpenterIMEXARK4Method +from leap.rk.imex import KennedyCarpenterIMEXARK4MethodBuilder from stiff_test_systems import KapsProblem from utils import ( # noqa @@ -51,9 +51,9 @@ def solver_hook(solve_expr, solve_var, solver_id, guess): @pytest.mark.parametrize("problem, method, expected_order", [ - [KapsProblem(epsilon=0.9), KennedyCarpenterIMEXARK4Method( + [KapsProblem(epsilon=0.9), KennedyCarpenterIMEXARK4MethodBuilder( "y", use_high_order=False), 3], - [KapsProblem(epsilon=0.9), KennedyCarpenterIMEXARK4Method("y"), 4], + [KapsProblem(epsilon=0.9), KennedyCarpenterIMEXARK4MethodBuilder("y"), 4], ]) def test_convergence(python_method_impl, problem, method, expected_order): pytest.importorskip("scipy") @@ -110,7 +110,7 @@ def test_convergence(python_method_impl, problem, method, expected_order): @pytest.mark.parametrize("problem, method", [ - [KapsProblem(epsilon=0.001), KennedyCarpenterIMEXARK4Method], + [KapsProblem(epsilon=0.001), KennedyCarpenterIMEXARK4MethodBuilder], ]) def test_adaptive(python_method_impl, problem, method): pytest.importorskip("scipy") diff --git a/test/test_misc.py b/test/test_misc.py index bd01f10cc8498536269edf82d429f6ca0374dde1..1759e7b96b9cc9c63772ea862682b7edbdec7acd 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -34,10 +34,10 @@ logger = logging.getLogger(__name__) def test_strang_splitting(plot_solution=False): - from leap.rk import LSRK4Method + from leap.rk import LSRK4MethodBuilder - method1 = LSRK4Method("y", rhs_func_name="y1") - method2 = LSRK4Method("y", rhs_func_name="y2") + method1 = LSRK4MethodBuilder("y", rhs_func_name="y1") + method2 = LSRK4MethodBuilder("y", rhs_func_name="y2") code1 = method1.generate() code2 = method2.generate() diff --git a/test/test_multirate.py b/test/test_multirate.py index 95c6e2451bbb142fb41f2e525e53a053cf4176e1..045ce075358ed2d11a0734299aa2b8f281ce0a73 100644 --- a/test/test_multirate.py +++ b/test/test_multirate.py @@ -33,8 +33,8 @@ from pytools import memoize_method from leap.multistep.multirate import ( rhs_policy, MultiRateHistory as MRHistory, - MultiRateMultiStepMethod, - TwoRateAdamsBashforthMethod, + MultiRateMultiStepMethodBuilder, + TwoRateAdamsBashforthMethodBuilder, TextualSchemeExplainer) @@ -60,7 +60,7 @@ class MultirateTimestepperAccuracyChecker(object): @memoize_method def get_code(self, dt): - method = TwoRateAdamsBashforthMethod( + method = TwoRateAdamsBashforthMethodBuilder( self.method, self.order, self.step_ratio, static_dt=self.static_dt, hist_consistency_threshold=1e-8, @@ -191,7 +191,7 @@ class MultirateTimestepperAccuracyChecker(object): #"Comp", #"Tria" ]) -@pytest.mark.parametrize("method_name", TwoRateAdamsBashforthMethod.methods) +@pytest.mark.parametrize("method_name", TwoRateAdamsBashforthMethodBuilder.methods) @pytest.mark.parametrize("static_dt", [True, False]) def test_multirate_accuracy(method_name, order, hist_length, system, static_dt, step_ratio=2): @@ -212,7 +212,7 @@ def test_multirate_accuracy(method_name, order, hist_length, def test_single_rate_identical(order=3, hist_length=3): - from leap.multistep import AdamsBashforthMethod + from leap.multistep import AdamsBashforthMethodBuilder from dagrt.exec_numpy import NumpyInterpreter from multirate_test_systems import Full @@ -223,7 +223,7 @@ def test_single_rate_identical(order=3, hist_length=3): # {{{ single rate - single_rate_method = AdamsBashforthMethod("y", order=order, + single_rate_method = AdamsBashforthMethodBuilder("y", order=order, hist_length=hist_length) single_rate_code = single_rate_method.generate() @@ -259,7 +259,7 @@ def test_single_rate_identical(order=3, hist_length=3): # {{{ two rate - multi_rate_method = MultiRateMultiStepMethod( + multi_rate_method = MultiRateMultiStepMethodBuilder( order, ( ( @@ -322,7 +322,7 @@ def test_single_rate_identical(order=3, hist_length=3): @pytest.mark.parametrize("method_name", ["F", "Fqsr", "Srsf", "S"]) def test_2rab_scheme_explainers(method_name, order=3, step_ratio=3, explainer=TextualSchemeExplainer()): - method = TwoRateAdamsBashforthMethod( + method = TwoRateAdamsBashforthMethodBuilder( method_name, order=order, step_ratio=step_ratio) method.generate(explainer=explainer) @@ -331,7 +331,7 @@ def test_2rab_scheme_explainers(method_name, order=3, step_ratio=3, def test_mrab_scheme_explainers(order=3, step_ratio=3, explainer=TextualSchemeExplainer()): - method = MultiRateMultiStepMethod( + method = MultiRateMultiStepMethodBuilder( order, ( ( @@ -351,7 +351,7 @@ def test_mrab_scheme_explainers(order=3, step_ratio=3, def test_mrab_with_derived_state_scheme_explainers(order=3, step_ratio=3, explainer=TextualSchemeExplainer()): - method = MultiRateMultiStepMethod( + method = MultiRateMultiStepMethodBuilder( order, ( ( @@ -378,7 +378,7 @@ def test_mrab_with_derived_state_scheme_explainers(order=3, step_ratio=3, def test_dot(order=3, step_ratio=3, method_name="F", show=False): - method = TwoRateAdamsBashforthMethod( + method = TwoRateAdamsBashforthMethodBuilder( method_name, order=order, step_ratio=step_ratio, hist_consistency_threshold=1e-8) code = method.generate() @@ -407,7 +407,7 @@ def test_two_rate_intervals(fast_interval, slow_interval, order=3): def true_s(t): return np.exp(t)*np.cos(t) - method = MultiRateMultiStepMethod( + method = MultiRateMultiStepMethodBuilder( order, ( ( @@ -428,7 +428,7 @@ def test_two_rate_intervals(fast_interval, slow_interval, order=3): eocrec = EOCRecorder() from dagrt.codegen import PythonCodeGenerator - codegen = PythonCodeGenerator(class_name='Method') + codegen = PythonCodeGenerator(class_name="Method") stepper_cls = codegen.get_class(code) @@ -497,7 +497,7 @@ def test_dependent_state(order=3, step_ratio=3): def true_s(t): return np.exp(t)*np.cos(t) - method = MultiRateMultiStepMethod( + method = MultiRateMultiStepMethodBuilder( order, ( ( @@ -522,7 +522,7 @@ def test_dependent_state(order=3, step_ratio=3): eocrec = EOCRecorder() from dagrt.codegen import PythonCodeGenerator - codegen = PythonCodeGenerator(class_name='Method') + codegen = PythonCodeGenerator(class_name="Method") stepper_cls = codegen.get_class(code) diff --git a/test/test_rk.py b/test/test_rk.py index 95ea340975d928318cc59194acb602e1c4a4fb9d..d05266ec052bced6f8af6111059ae3d3ec99622b 100755 --- a/test/test_rk.py +++ b/test/test_rk.py @@ -27,12 +27,12 @@ import sys import pytest from leap.rk import ( - ODE23Method, ODE45Method, - ForwardEulerMethod, - MidpointMethod, HeunsMethod, - RK3Method, RK4Method, RK5Method, - LSRK4Method,) -from leap.rk.imex import KennedyCarpenterIMEXARK4Method + ODE23MethodBuilder, ODE45MethodBuilder, + ForwardEulerMethodBuilder, + MidpointMethodBuilder, HeunsMethodBuilder, + RK3MethodBuilder, RK4MethodBuilder, RK5MethodBuilder, + LSRK4MethodBuilder,) +from leap.rk.imex import KennedyCarpenterIMEXARK4MethodBuilder import numpy as np import logging @@ -47,21 +47,21 @@ logger = logging.getLogger(__name__) # {{{ non-adaptive test # test using -# python test_rk.py 'test_rk_accuracy(pmi_int, ODE23Method("y", use_high_order=False), 2)' # noqa +# python test_rk.py 'test_rk_accuracy(pmi_int, ODE23MethodBuilder("y", use_high_order=False), 2)' # noqa @pytest.mark.parametrize(("method", "expected_order"), [ - (ODE23Method("y", use_high_order=False), 2), - (ODE23Method("y", use_high_order=True), 3), - (ODE45Method("y", use_high_order=False), 4), - (ODE45Method("y", use_high_order=True), 5), - (ForwardEulerMethod("y"), 1), - (MidpointMethod("y"), 2), - (HeunsMethod("y"), 2), - (RK3Method("y"), 3), - (RK4Method("y"), 4), - (RK5Method("y"), 5), - (LSRK4Method("y"), 4), - (KennedyCarpenterIMEXARK4Method("y", use_implicit=False, + (ODE23MethodBuilder("y", use_high_order=False), 2), + (ODE23MethodBuilder("y", use_high_order=True), 3), + (ODE45MethodBuilder("y", use_high_order=False), 4), + (ODE45MethodBuilder("y", use_high_order=True), 5), + (ForwardEulerMethodBuilder("y"), 1), + (MidpointMethodBuilder("y"), 2), + (HeunsMethodBuilder("y"), 2), + (RK3MethodBuilder("y"), 3), + (RK4MethodBuilder("y"), 4), + (RK5MethodBuilder("y"), 5), + (LSRK4MethodBuilder("y"), 4), + (KennedyCarpenterIMEXARK4MethodBuilder("y", use_implicit=False, explicit_rhs_name="y"), 4), ]) def test_rk_accuracy(python_method_impl, method, expected_order, @@ -77,9 +77,9 @@ def test_rk_accuracy(python_method_impl, method, expected_order, # {{{ adaptive test @pytest.mark.parametrize("method", [ - ODE23Method("y", rtol=1e-6), - ODE45Method("y", rtol=1e-6), - KennedyCarpenterIMEXARK4Method("y", rtol=1e-6, use_implicit=False, + ODE23MethodBuilder("y", rtol=1e-6), + ODE45MethodBuilder("y", rtol=1e-6), + KennedyCarpenterIMEXARK4MethodBuilder("y", rtol=1e-6, use_implicit=False, explicit_rhs_name="y"), ]) def test_adaptive_timestep(python_method_impl, method, show_dag=False, diff --git a/test/test_step_matrix.py b/test/test_step_matrix.py index c82bbe165d0815e4b204c23b2626bd76da48e856..4f3f9650288652de3a10547c91fca42c3b1efe56 100755 --- a/test/test_step_matrix.py +++ b/test/test_step_matrix.py @@ -26,7 +26,7 @@ THE SOFTWARE. import sys import pytest -from leap.rk import ODE23Method, ODE45Method +from leap.rk import ODE23MethodBuilder, ODE45MethodBuilder import numpy as np import numpy.linalg as la @@ -37,13 +37,13 @@ logger = logging.getLogger(__name__) # Run example with -# python test_step_matrix.py "test_step_matrix(ODE23Method())" +# python test_step_matrix.py "test_step_matrix(ODE23MethodBuilder())" @pytest.mark.parametrize("method", [ - ODE23Method("y", use_high_order=False), - ODE23Method("y", use_high_order=True), - ODE45Method("y", use_high_order=False), - ODE45Method("y", use_high_order=True), + ODE23MethodBuilder("y", use_high_order=False), + ODE23MethodBuilder("y", use_high_order=True), + ODE45MethodBuilder("y", use_high_order=False), + ODE45MethodBuilder("y", use_high_order=True), ]) def test_step_matrix(method, show_matrix=True, show_dag=False): component_id = 'y' @@ -114,9 +114,9 @@ def test_step_matrix(method, show_matrix=True, show_dag=False): def euler(component_id, show_dag): - from leap.multistep import AdamsBashforthMethod + from leap.multistep import AdamsBashforthMethodBuilder - method = AdamsBashforthMethod(component_id, 1, static_dt=True) + method = AdamsBashforthMethodBuilder(component_id, 1, static_dt=True) code = method.generate() if show_dag: from dagrt.language import show_dependency_graph diff --git a/test/utils.py b/test/utils.py index 6e025768e74c8473392e712cd3e1206e08dd3dd0..c9f22884a2d3351dcbdf904736175721cc2f9639 100644 --- a/test/utils.py +++ b/test/utils.py @@ -34,7 +34,7 @@ def python_method_impl_interpreter(code, **kwargs): def python_method_impl_codegen(code, **kwargs): from dagrt.codegen import PythonCodeGenerator - codegen = PythonCodeGenerator(class_name='Method') + codegen = PythonCodeGenerator(class_name="Method") return codegen.get_class(code)(**kwargs) # }}}