def solver_hook(solve_expr, unknown, solver_id, guess): from dagrt.expression import match, substitute pieces = match( "k - <func>rhs(time, y + dt * (c0 + c1 * k))", solve_expr, pre_match={"k": unknown}) return substitute("-10 * (dt * c0 + y) / (10 * dt * c1 + 1)", pieces)
def solver_hook(solve_expr, solve_var, solver_id, guess): from dagrt.expression import match, substitute pieces = match("unk - <func>rhs(t=t, y=sub_y + coeff*unk)", solve_expr, pre_match={"unk": solve_var}) pieces["guess"] = guess return substitute("<func>solver(t, sub_y, coeff, guess)", pieces)
def solver_hook(solve_expr, solve_var, solver_id, guess): from dagrt.expression import match, substitute pieces = match("unk + (-1)*<func>impl_y(y=sub_y + coeff*unk, t=t)", solve_expr, pre_match={"unk": solve_var}) pieces["guess"] = guess return substitute("<func>solver(sub_y, coeff)", pieces)
def am_solver_hook(solve_expr, solve_var, solver_id, guess): from dagrt.expression import match, substitute pieces = match( "unk + (-1)*<func>f(t=t, fast=sub_fast + coeff*unk, " "slow=sub_slow)", solve_expr, pre_match={"unk": solve_var}) pieces["guess"] = guess return substitute("<func>solver(sub_fast, sub_slow, " "coeff, t)", pieces)
def solver_hook(solve_expr, solve_var, solver_id, guess): from dagrt.expression import match, substitute pieces = match("unk - <func>rhs(t=t, y=<state>y + sub_y + coeff*unk)", solve_expr, bound_variable_names=["<state>y"], pre_match={"unk": solve_var}) pieces["guess"] = guess return substitute("<func>solver(t, <state>y, sub_y, coeff)", pieces)
def test_substitute(): f, a = declare("f", "a") from dagrt.expression import substitute assert substitute("f(<state>y)", {"<state>y": a}) == f(a)
def solver_hook(expr, var, solver_id, guess): from dagrt.expression import match, substitute pieces = match("unk-y-h*<func>f(t=t,y=unk)", expr, pre_match={"unk": var}) pieces["guess"] = guess return substitute("<func>solver(t,h,y,guess)", pieces)