From 29f1f9b4a9068de8c69f003821ed5fcd868a533c Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Tue, 13 Mar 2018 19:33:23 -0500 Subject: [PATCH 1/2] [ci skip] Remove make_solver_call(). This closes #121 Depends on dagrt!15 --- examples/imex/imex.py | 7 ++++--- examples/implicit_euler/test_implicit_euler.py | 7 +++---- leap/implicit.py | 16 ---------------- test/test_imex.py | 8 +++----- 4 files changed, 10 insertions(+), 28 deletions(-) diff --git a/examples/imex/imex.py b/examples/imex/imex.py index a775234..16ca230 100644 --- a/examples/imex/imex.py +++ b/examples/imex/imex.py @@ -70,15 +70,16 @@ def solver(f, j, t, u_n, x, c): def solver_hook(solve_expr, solve_var, solver_id, guess): - from dagrt.expression import match - from leap.implicit import make_solver_call + from dagrt.expression import match, substitute pieces = match("unk - rhs(t=t, y=y + sub_y + coeff*unk)", solve_expr, bound_variable_names=["y"], pre_match={"unk": solve_var}) - return make_solver_call("solver(t, y, sub_y, coeff)", pieces) + pieces["guess"] = guess + + return substitute("solver(t, y, sub_y, coeff)", pieces) def run(): diff --git a/examples/implicit_euler/test_implicit_euler.py b/examples/implicit_euler/test_implicit_euler.py index 203c6ce..ad7da16 100755 --- a/examples/implicit_euler/test_implicit_euler.py +++ b/examples/implicit_euler/test_implicit_euler.py @@ -48,11 +48,10 @@ def solver(f, t, h, y, guess): def solver_hook(expr, var, solver_id, guess): - from dagrt.expression import match - from leap.implicit import make_solver_call + from dagrt.expression import match, substitute pieces = match("unk-y-h*f(t=t,y=unk)", expr, pre_match={"unk": var}) - return make_solver_call("solver(t,h,y,guess)", - pieces, guess, guess_name="guess") + pieces["guess"] = guess + return substitute("solver(t,h,y,guess)", pieces) @pytest.mark.parametrize("python_method_impl", diff --git a/leap/implicit.py b/leap/implicit.py index 26d18f6..5be6d4d 100644 --- a/leap/implicit.py +++ b/leap/implicit.py @@ -27,22 +27,6 @@ THE SOFTWARE. """ -def make_solver_call(template, pieces, guess=None, guess_name=None): - """ - :arg template: A template for a solver call - :arg pieces: A dictionary mapping variable names to subexpressions, to - substitute into the template - :arg guess: The expression for the initial guess - :arg guess_name: The variable name for the initial guess - """ - if isinstance(template, str): - from dagrt.expression import parse - template = parse(template) - from pymbolic import substitute - pieces.update({guess_name: guess}) - return substitute(template, pieces) - - def replace_AssignSolved(dag, solver_hooks): """ :arg dag: The :class:`DAGCode` instance diff --git a/test/test_imex.py b/test/test_imex.py index 19a0a0e..f853351 100755 --- a/test/test_imex.py +++ b/test/test_imex.py @@ -42,14 +42,12 @@ def solver(f, t, sub_y, coeff, guess): def solver_hook(solve_expr, solve_var, solver_id, guess): - from dagrt.expression import match - from leap.implicit import make_solver_call + from dagrt.expression import match, substitute pieces = match("unk - rhs(t=t, y=sub_y + coeff*unk)", solve_expr, pre_match={"unk": solve_var}) - return make_solver_call("solver(t, sub_y, coeff, guess)", - pieces, - guess, guess_name="guess") + pieces["guess"] = guess + return substitute("solver(t, sub_y, coeff, guess)", pieces) @pytest.mark.parametrize("problem, method, expected_order", [ -- GitLab From b2fc4eed01f03e2bf72ed7b3bb00f8b03c019fc0 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 14 Mar 2018 01:05:55 -0500 Subject: [PATCH 2/2] Fix flake8 warning --- leap/implicit.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/leap/implicit.py b/leap/implicit.py index 82d4ebb..02e98f1 100644 --- a/leap/implicit.py +++ b/leap/implicit.py @@ -26,8 +26,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ - - import six -- GitLab