zoomy_core.symsolver.core

zoomy_core.symsolver.core#

The machinery under the solver templates: Block and Effect names in a sympy graph, scoped common-subexpression planning, and the Python and C++ printers. A template runs once on sympy symbols and a printer turns the resulting graph into source code.

Module Contents#

Classes#

Block

Opaque building block; every backend supplies a callable of this name.

Get

Component i of a block that returns several values.

while_loop

(cond, body, init) -> final carry; cond and body take the carry.

cond

(pred, then, other) -> value; the branches take no arguments.

root

(residual, x0) -> x with residual(x) = 0.

linsolve

(matvec, b) -> x with matvec(x) = b, solved matrix-free (restarted GMRES by default).

EffectNode

Base of the graph nodes created by Effect.

Effect

Declared effect, name = Effect(n_out) inside a namespace class; the backend name is <namespace>_<attr>. It receives the order token first and returns (token, *outputs).

PyPrinter

Python family: numpy and JAX print the same text.

CxxPrinter

C++ family: foam and AMReX print the same text, with the runtime’s free functions pow / minimum / maximum and no structured bindings (C++17 lambdas cannot capture them).

Functions#

unpack

Return n Get nodes for the components of a multi-output call.

While

Run-time loop with an explicit carry: body(*carry) -> carry; returns the final carry.

Cond

Run-time branch; only the taken branch executes.

Root

Solve residual(x) = 0 from x0 at run time.

LinSolve

Solve matvec(x) = b at run time (see linsolve).

contract

Return the sorted names every backend runtime must define (blocks and effects).

API#

class zoomy_core.symsolver.core.Block#

Bases: sympy.Function

Opaque building block; every backend supplies a callable of this name.

class zoomy_core.symsolver.core.Get#

Bases: sympy.Function

Component i of a block that returns several values.

nargs#

2

class zoomy_core.symsolver.core.while_loop#

Bases: zoomy_core.symsolver.core.Block

(cond, body, init) -> final carry; cond and body take the carry.

class zoomy_core.symsolver.core.cond#

Bases: zoomy_core.symsolver.core.Block

(pred, then, other) -> value; the branches take no arguments.

class zoomy_core.symsolver.core.root#

Bases: zoomy_core.symsolver.core.Block

(residual, x0) -> x with residual(x) = 0.

class zoomy_core.symsolver.core.linsolve#

Bases: zoomy_core.symsolver.core.Block

(matvec, b) -> x with matvec(x) = b, solved matrix-free (restarted GMRES by default).

References

  • Saad, Schultz 1986, https://doi.org/10.1137/0907058

class zoomy_core.symsolver.core.EffectNode#

Bases: zoomy_core.symsolver.core.Block

Base of the graph nodes created by Effect.

class zoomy_core.symsolver.core.Effect(n_out=0)#

Declared effect, name = Effect(n_out) inside a namespace class; the backend name is <namespace>_<attr>. It receives the order token first and returns (token, *outputs).

Initialization

n_out: number of values the effect returns.

zoomy_core.symsolver.core.unpack(call, n)#

Return n Get nodes for the components of a multi-output call.

zoomy_core.symsolver.core.While(c, body, init)#

Run-time loop with an explicit carry: body(*carry) -> carry; returns the final carry.

zoomy_core.symsolver.core.Cond(pred, then, other)#

Run-time branch; only the taken branch executes.

zoomy_core.symsolver.core.Root(residual, x0)#

Solve residual(x) = 0 from x0 at run time.

zoomy_core.symsolver.core.LinSolve(matvec, b)#

Solve matvec(x) = b at run time (see linsolve).

class zoomy_core.symsolver.core.PyPrinter#

Bases: zoomy_core.symsolver.core._Common, sympy.printing.pycode.PythonCodePrinter

Python family: numpy and JAX print the same text.

Initialization

Allow unknown (block) functions and unqualified module names.

destructure#

True

assign_many(names, rhs, ind)#

Tuple-unpacking assignment.

assign(nm, rhs, ind)#

Assignment statement.

lambda_def(nm, args, body, ret, ind)#

Nested def returning ret.

proc_def(name, args, body, ret)#

Top-level def returning ret.

class zoomy_core.symsolver.core.CxxPrinter#

Bases: zoomy_core.symsolver.core._Common, zoomy_core.transformation.cxx_base.CxxBase

C++ family: foam and AMReX print the same text, with the runtime’s free functions pow / minimum / maximum and no structured bindings (C++17 lambdas cannot capture them).

Initialization

Allow unknown (block) functions.

destructure#

False

math_namespace = <Multiline-String>#
assign(nm, rhs, ind)#

auto declaration.

lambda_def(nm, args, body, ret, ind)#

Nested [&] lambda returning ret.

proc_def(name, args, body, ret)#

Top-level inline auto lambda returning ret.

zoomy_core.symsolver.core.contract()#

Return the sorted names every backend runtime must define (blocks and effects).