Ignition v0.1.0 documentation

Ignition FLAME

The FLAME module of the Ignition library

This module provides a number of ways to represent FLAME algorithms and generate FLAME worksheets or code.

Partition Objects and Generators

Pobj

Defines PME Language

class ignition.flame.pobj.PObj(obj, *args, **kws)[source]

Represents a partitioned object

The base for the PME language. Each object in a partitioned equation must derive from this class.

Args:
obj: The underlying object being partitioned.
Optional keyword arguments:
size:
The size of the partition, currently a two-tuple. default: (2,2)
dir:
The direction of the traversal, used for automatically selecting repart and fuse rules. Optional but default assumed if repart and fuse rules are not given.
props:
List of properties of partitioned object useful for choosing choosing partitition rules. For example: [“Symmetric”, “UpperTriangular”, “LowerTriangular”, “Input”, “Output”, “Overwritten”]
part_fun:
Method for transforming object to list of objects.
repart_fun:
Method that returns dictionary for partition to loop variables before the loop updates.
fuse_fun:
Method that returns dictionary for partition to loop variables after the loop updates.
fuse[source]

Returns the partition transformed by fuse

repart[source]

Returns the partition transformed by repart

Generator

Code generator for PME Language

class ignition.flame.generator.PAlgGenerator(loop_inv_op, solver, *args, **kws)[source]

Wrapper object for generating partitioned algorithms.

operation: The operation to generate args: List of PObjs that are input for the operation.

fuse[source]

Fuse mapping

gen_update(filename=None, type=None, **solve_kws)[source]

Generates the loop updates and pre/post conditions inside loop.

partition[source]

Partition mapping

repartition[source]

Repartition mapping

ignition.flame.generator.generate(filename=None, filetype=None, op=None, loop_inv=None, inv_args=[], PME=None, solver=None, **solve_kws)[source]

Utility function for generating a flame algorithm.

Will create a generator object and write it to file, then return the generator object.

For more complete documentation see the PAlgGenerator object and the printing module.

Tensor library

Symbolic tensor library

Provides a small symbolic tensor library for use with flame algorithms.

Tensor

Rules for symbolic tensor algebra

class ignition.flame.tensors.tensor.BasisVector[source]

Unit basis vector with 1 at given position r.

>>> e_0 = BasisVector(0)
>>> A = Tensor('A')
>>> A*e_0 
a[0]
class ignition.flame.tensors.tensor.Tensor[source]

Basic Tensor symbol.

>>> A = Tensor('A', rank=2)
>>> B = Tensor('B', rank=2)
>>> x = Tensor('x', rank=1)
>>> y = Tensor('y', rank=1)
>>> alpha = Tensor('alpha', rank=0)
>>> beta = Tensor('beta', rank=0)
>>> alpha*A*x + beta*B*x
alpha*A*x + beta*B*x
>>> expand((alpha*A+beta*B)*(x+y))
alpha*A*x + alpha*A*y + beta*B*x + beta*B*y
update(name=None, l_ind=None, u_ind=None, rank=None, has_inverse=None, shape=None, conform_name=True)[source]

Forms a new Tensor with only the listed attributes changed

Tensor Expr

class ignition.flame.tensors.tensor_expr.TensorExpr[source]

Base object for things with Tensor properties such as:

  • rank
  • shape
  • has_inverse
  • algebraic ops
ignition.flame.tensors.tensor_expr.expr_rank(expr)[source]

Returns the rank of a given expression

Will raise ConformityError if expression does not conform.

>>> A = Tensor('A', rank=2)
>>> B = Tensor('B', rank=2)
>>> x = Tensor('x', rank=1)
>>> expr_rank(A+B)
2
>>> expr_rank((A+B)*x)
1
>>> expr_rank(A*T(x))
---------------------------------------------------------------------------
ConformityError                           Traceback (most recent call last)
ignition.flame.tensors.tensor_expr.expr_shape(expr)[source]

Returns the shape of a given expression

Will raise ConformityError if expression does not conform.

>>> A = Tensor('A', rank=2)
>>> B = Tensor('B', rank=2)
>>> x = Tensor('x', rank=1)
>>> expr_shape(A+B)
(n, n)
>>> expr_shape((A+B)*x)
(n, 1)
>>> expr_shape(A*T(x))
---------------------------------------------------------------------------
ConformityError                           Traceback (most recent call last)
ignition.flame.tensors.tensor_expr.is_one(expr)[source]

Returns True, False, or None

ignition.flame.tensors.tensor_expr.is_zero(expr)[source]

Returns True, False, or None

Basic Operators

Some basic tensor operators

class ignition.flame.tensors.basic_operators.Inner[source]

Represents the inner product of two tensor exprs.

class ignition.flame.tensors.basic_operators.Inverse[source]

Represents the inverse of a tensor expr.

ignition.flame.tensors.basic_operators.T

alias of Transpose

class ignition.flame.tensors.basic_operators.Transpose[source]

Represents the transpose of a tensor expr.

Solvers

Several solvers for overdetermined tensor systems.

ignition.flame.tensors.solvers.add_new_eqns(add_vars, all_eqns, sol_dict)[source]

Substitutes solved values into equations and adds them to the list of equations

ignition.flame.tensors.solvers.assump_solve(eqns, knowns, assumps=None)[source]

An aggressive solver for list of eqns and given knowns.

Similar to forward_solve, but will iteratively update equations based on given solutions by assuming an unknown is known.

>>> q, r, s = map(lambda x: Tensor(x, rank=1), 'qrs')
>>> s_t = Transpose(s)
>>> delta = Tensor('delta', rank=0)
>>> eqn1 = r - s - q * delta
>>> eqn2 = s_t * r
>>> assump_solve([eqn1, eqn2], [s, q])
{delta: -(T(s)*s)/(T(s)*q), r: delta*q + s}

Should not raise any exceptions, but may return a solution dict with unsolved variables.

ignition.flame.tensors.solvers.branching_assump_solve(eqns, knowns, levels=-1)[source]

Returns all unique solutions discovered by assuming different unknowns and branching to see if different solutions occur.

See also: assump_solve

ignition.flame.tensors.solvers.forward_solve(eqns, knowns, branching=False)[source]

Returns a dict of unknowns:solutions from a simple backward solve.

Does a simple backward solver for a list of eqn given a list of unknowns. Each equation should be an expression that equals zero. If an unknown is not solved for, then its entry in the solution dict will be None.

>>> q, r, s = map(lambda x: Tensor(x, rank=1), 'qrs')
>>> delta = Tensor('delta', rank=0)
>>> eqn1 = s + q
>>> eqn2 = delta * r - q
>>> forward_solve([eqn1, eqn2], [delta, r])
{q: delta*r, s: -q}

Will raise same exceptions as solve_vec_eqn.

ignition.flame.tensors.solvers.get_eqns_unk(eqns, knowns)[source]

Returns the list of unknowns, given the knowns, from a list of equations

ignition.flame.tensors.solvers.get_solved(sol_dict)[source]

Returns the solved variables of a solution dictionary

ignition.flame.tensors.solvers.is_solved(sol_dict)[source]

Returns if all variables in the solution dict are solved

ignition.flame.tensors.solvers.print_sols(sol, sol_dict)[source]

Simple printer for solutions

ignition.flame.tensors.solvers.solve_vec_eqn(eqn, var)[source]

Returns the solution to a linear equation containing Tensors

Raises:
NonLinearEqnError if the variable is detected to be nonlinear NotInvertibleError if an inverse is required that is not available NotImplementedError if operation isn’t supported by routine
ignition.flame.tensors.solvers.tensor_solver(b4_eqns, aft_eqns, e_knowns=[], levels=-1, num_sols=1, verbose=True, solution_file=None, logic_files=None)[source]

Updater calling tensor solvers.

ignition.flame.tensors.solvers.update_sol_dict_unk_sol(sol_dict, unknowns, solved, curr_dict)[source]

Upadates the solution dict, unknown list and solved list based on given solution dict (curr_dict)

Tensor Names

Module for manipulating tensor names according to Householder notation

ignition.flame.tensors.tensor_names.add_idx(name, idx, latex=False)[source]

Returns a name with an added index.

>>> add_idx("a", "r")
"a[r]"
>>> add_idx("a_0^2", "r")
"a[r]_0^2"
>>> add_idx("a[r]", "n")
"a[r][n]"
>>> add_idx("a", 3)
"a[3]"
>>> add_idx("a_02", "delta", latex=True)
"a[\delta]_{02}
ignition.flame.tensors.tensor_names.convert_name(name, rank)[source]

Converts a Householder name to a specific rank.

Will return non-Householder names unchanged.

>>> convert_name("A", 1)
'a'
>>> convert_name("alpha_01", 2)
'A_01'
>>> convert_name("foo_bar", 1)
'foo_bar'
ignition.flame.tensors.tensor_names.householder_name(name, rank)[source]

Returns if the name conforms to Householder notation.

>>> householder_name('A_1', 2)
True
>>> householder_name('foobar', 1)
False
ignition.flame.tensors.tensor_names.join_name(name, lower, upper, latex=False)[source]

Returns name string with upper and lower indices.

>>> join_name("A", "0", "1")
A_0^1
>>> join_name("A", "bl", "2")
A_bl^2
>>> join_name("A", "bl", "2", latex=True)
A_{bl}^2
ignition.flame.tensors.tensor_names.split_name(name)[source]

Returns base, lower, upper strings of name

ignition.flame.tensors.tensor_names.to_latex(name)[source]

Returns name for latex printing.

>>> to_latex("A_01^T")
'A_{01}^T'
>>> to_latex("alpha")
'\alpha'

Printers

Simple printers for tensor expressions

ignition.flame.tensors.printers.latex_print(expr)[source]

Prints a tensor expression in Latex.

ignition.flame.tensors.printers.numpy_print(expr)[source]

Prints a tensor expression in Python using numpy.

ignition.flame.tensors.printers.print_visitor(expr_to_print, str_dict)[source]

Prints a tensor expression in with predefined strings in string dict.

See default_strs for str_dict keys.

ignition.flame.tensors.printers.update_dict_to_latex(update_dict, order)[source]

Returns update dictionary and order as latex string.

Printing

Module defining whole program printers for generator objects.

Printer

Base printer objects.

class ignition.flame.printing.printer.TemplatePrinter(template, filename=None, **kws)[source]

Abstract printer class for using a Mako Template

ignition.flame.printing.printer.get_printer(gen_obj, filename=None, filetype=None)[source]

Return printer based on file name extension

Worksheet Printer

Worksheet printer class

class ignition.flame.printing.worksheet.WorksheetPrinter(gen_obj, filename=None, template='worksheet.mako', **kws)[source]

Basic FLAME worksheet printer class