from noodles import (schedule, run_single) from noodles.tutorial import (add) from noodles.draw_workflow import draw_workflow @schedule class A: def __init__(self, value): self.value = value @property def square(self): return self.value**2 @square.setter def square(self, sqr): self.value = sqr**(1 / 2) u = A(3) v = A(4) u.square = add(u.square, v.square) draw_workflow("pythagoras.pdf", u.value._workflow) print("⎷(3² + 4²) = ", run_single(u.value))
# ~\~ begin <<lit/paranoodles.md|noodlify>>[3] y_euler = noodles.gather(*tabulate(noodles.schedule(fine), [1.0, 0.0], t)) # ~\~ end # ~\~ begin <<lit/paranoodles.md|noodlify>>[4] def paint(node, name): if name == "coarse": node.attr["fillcolor"] = "#cccccc" elif name == "fine": node.attr["fillcolor"] = "#88ff88" else: node.attr["fillcolor"] = "#ffffff" draw_workflow('seq-graph.svg', noodles.get_workflow(y_euler), paint) # ~\~ end # ~\~ begin <<lit/paranoodles.md|noodlify>>[5] @noodles.schedule def coarse(x, t_0, t_1): return forward_euler(f)(x, t_0, t_1) # ~\~ end # ~\~ begin <<lit/paranoodles.md|noodlify>>[6] y_first = noodles.gather(*tabulate(noodles.schedule(coarse), [1.0, 0.0], t)) # ~\~ end # ~\~ begin <<lit/paranoodles.md|noodlify>>[7] y_parareal = noodles.gather(*parareal(coarse, fine)(y_first, t))
from noodles.tutorial import (add, sub, mul) from noodles.draw_workflow import draw_workflow u = add(5, 4) v = sub(u, 3) w = sub(u, 2) x = mul(v, w) draw_workflow("callgraph-a.pdf", x._workflow)
@property def attr(self): return sqr(self.__attr) def mul_attr(self, factor=1): return mul(self.__attr, factor) @attr.setter def attr(self, x): self.__attr = divide(x, 2) @schedule class B: pass a = A(5).multiply(10) a.second = 7 a.attr = 1.0 b = B() b.x = a.x b.second = a.second b.attr = a.attr draw_workflow("oop-wf.svg", b._workflow) result = run_single(b) print(result.x, result.second, result.attr)
from noodles import gather from noodles.draw_workflow import draw_workflow from noodles.tutorial import (add, mul, sub, accumulate) def test_42(): A = add(1, 1) B = sub(3, A) multiples = [mul(add(i, B), A) for i in range(6)] return accumulate(gather(*multiples)) draw_workflow("wf42.svg", test_42()._workflow)