ffc.uflacs.analysis package¶
Submodules¶
ffc.uflacs.analysis.balancing module¶
Algorithms for the representation phase of the form compilation.
ffc.uflacs.analysis.crsarray module¶
Compressed row storage ‘matrix’ (actually just a non-rectangular 2d array).
-
class
ffc.uflacs.analysis.crsarray.
CRSArray
(row_capacity, element_capacity, dtype)[source]¶ Bases:
object
An array of variable length dense arrays.
Stored efficiently with simple compressed row storage. This CRS array variant doesn’t have a sparsity pattern, as each row is simply a dense vector.
Values are stored in one flat array ‘data[]’, and ‘row_offsets[i]’ contains the index to the first element on row i for 0<=i<=num_rows. There is no column index.
-
classmethod
from_rows
(rows, num_rows, num_elements, dtype)[source]¶ Construct a CRSArray from a list of row element lists.
-
num_elements
¶
-
classmethod
ffc.uflacs.analysis.dependencies module¶
Tools for analysing dependencies within expression graphs.
-
ffc.uflacs.analysis.dependencies.
compute_dependencies
(e2i, V, ignore_terminal_modifiers=True)[source]¶
-
ffc.uflacs.analysis.dependencies.
mark_active
(dependencies, targets)[source]¶ Return an array marking the recursive dependencies of targets.
Input: - dependencies - CRSArray of ints, a mapping from a symbol to the symbols of its dependencies. - targets - Sequence of symbols to mark the dependencies of.
Output: - active - Truth value for each symbol. - num_used - Number of true values in active array.
-
ffc.uflacs.analysis.dependencies.
mark_image
(inverse_dependencies, sources)[source]¶ Return an array marking the set of symbols dependent on the sources.
Input: - dependencies - CRSArray of ints, a mapping from a symbol to the symbols of its dependencies. - sources - Sequence of symbols to mark the dependants of.
Output: - image - Truth value for each symbol. - num_used - Number of true values in active array.
ffc.uflacs.analysis.expr_shapes module¶
Tools for computing various shapes of ufl expressions.
The total shape is the regular shape tuple plus the index shape tuple. The index shape tuple is the tuple of index dimensions of the free indices of the expression, sorted by the count of the free indices.
The total shape of a tensor valued expression A
and
A[*indices(len(A.ufl_shape))]
is therefore the same.
ffc.uflacs.analysis.factorization module¶
Algorithms for factorizing argument dependent monomials.
-
ffc.uflacs.analysis.factorization.
add_to_fv
(expr, FV, e2fi)[source]¶ Add expression expr to factor vector FV and expr->FVindex mapping e2fi.
-
ffc.uflacs.analysis.factorization.
build_argument_dependencies
(dependencies, arg_indices)[source]¶ Preliminary algorithm: build list of argument vertex indices each vertex (indirectly) depends on.
-
ffc.uflacs.analysis.factorization.
build_argument_indices
(V)[source]¶ Build ordered list of indices to modified arguments.
-
ffc.uflacs.analysis.factorization.
compute_argument_factorization
(SV, SV_deps, SV_targets, rank)[source]¶ Factorizes a scalar expression graph w.r.t. scalar Argument components.
The result is a triplet (AV, FV, IM):
The scalar argument component subgraph:
AV[ai] = v
with the property
SV[arg_indices] == AV[:]
An expression graph vertex list with all non-argument factors:
FV[fi] = f
with the property that none of the expressions depend on Arguments.
A dict representation of the final integrand of rank r:
IM = { (ai1_1, ..., ai1_r): fi1, (ai2_1, ..., ai2_r): fi2, }
This mapping represents the factorization of SV[-1] w.r.t. Arguments s.t.:
SV[-1] := sum(FV[fik] * product(AV[ai] for ai in aik) for aik, fik in IM.items())
where := means equivalence in the mathematical sense, of course in a different technical representation.
-
ffc.uflacs.analysis.factorization.
handle_conditional
(v, si, deps, SV_factors, FV, sv2fv, e2fi)[source]¶
-
ffc.uflacs.analysis.factorization.
handle_division
(v, si, deps, SV_factors, FV, sv2fv, e2fi)[source]¶
ffc.uflacs.analysis.graph module¶
Linearized data structure for the computational graph.
ffc.uflacs.analysis.graph_rebuild module¶
Rebuilding UFL expressions from linearized representation of computational graph.
-
class
ffc.uflacs.analysis.graph_rebuild.
ReconstructScalarSubexpressions
[source]¶ Bases:
ufl.corealg.multifunction.MultiFunction
-
abs
(o, ops)¶
-
atan_2
(o, ops)¶
-
bessel_function
(o, ops)¶
-
component_tensor
(o, *args, **kwargs)¶
-
expr_list
(o, *args, **kwargs)¶
-
expr_mapping
(o, *args, **kwargs)¶
-
label
(o, *args, **kwargs)¶
-
list_tensor
(o, *args, **kwargs)¶
-
math_function
(o, ops)¶
-
max_value
(o, ops)¶
-
min_value
(o, ops)¶
-
multi_index
(o, *args, **kwargs)¶
-
power
(o, ops)¶
-
transposed
(o, *args, **kwargs)¶
-
utility_type
(o, *args, **kwargs)¶
-
variable
(o, *args, **kwargs)¶
-
-
ffc.uflacs.analysis.graph_rebuild.
rebuild_expression_from_graph
(G)[source]¶ This is currently only used by tests.
-
ffc.uflacs.analysis.graph_rebuild.
rebuild_with_scalar_subexpressions
(G, targets=None)[source]¶ Build a new expression2index mapping where each subexpression is scalar valued.
Input: - G.e2i - G.V - G.V_symbols - G.total_unique_symbols
Output: - NV - Array with reverse mapping from index to expression - nvs - Tuple of ne2i indices corresponding to the last vertex of G.V
Old output now no longer returned but possible to restore if needed: - ne2i - Mapping from scalar subexpressions to a contiguous unique index - W - Array with reconstructed scalar subexpressions for each original symbol
ffc.uflacs.analysis.graph_ssa module¶
Algorithms for working with computational graphs.
-
ffc.uflacs.analysis.graph_ssa.
allocate_registers
(active, partitions, targets, scores, max_registers, score_threshold)[source]¶ FIXME: Cover with tests.
TODO: Allow reuse of registers, reducing memory usage.
TODO: Probably want to sort within partitions.
-
ffc.uflacs.analysis.graph_ssa.
compute_cache_scores
(V, active, dependencies, inverse_dependencies, partitions, cache_score_policy=<function default_cache_score_policy>)[source]¶ FIXME: Cover with tests.
TODO: Experiment with heuristics later when we have functional code generation.
-
ffc.uflacs.analysis.graph_ssa.
default_cache_score_policy
(vtype, ndeps, ninvdeps, partition)[source]¶
-
ffc.uflacs.analysis.graph_ssa.
default_partition_seed
(expr, rank)[source]¶ Partition 0: Piecewise constant on each cell (including Real and DG0 coefficients) Partition 1: Depends on x Partition 2: Depends on x and coefficients Partitions [3,3+rank): depend on argument with count partition-3
-
ffc.uflacs.analysis.graph_ssa.
mark_partitions
(V, active, dependencies, rank, partition_seed=<function default_partition_seed>, partition_combiner=<built-in function max>)[source]¶ FIXME: Cover this with tests.
Input: - V - Array of expressions. - active - Boolish array. - dependencies - CRSArray with V dependencies. - partition_seed - Policy for determining the partition of a terminalish. - partition_combiner - Policy for determinging the partition of an operator.
Output: - partitions - Array of partition int ids.
ffc.uflacs.analysis.graph_symbols module¶
Assigning symbols to computational graph nodes.
-
ffc.uflacs.analysis.graph_symbols.
build_graph_symbols
(V, e2i, DEBUG)[source]¶ Tabulate scalar value numbering of all nodes in a a list based representation of an expression graph.
Returns: V_shapes - CRSArray of the total shapes of nodes in V. V_symbols - CRSArray of symbols (value numbers) of each component of each node in V. total_unique_symbols - The number of symbol values assigned to unique scalar components of the nodes in V.
-
ffc.uflacs.analysis.graph_symbols.
build_node_shapes
(V)[source]¶ Build total shapes for each node in list representation of expression graph.
V is an array of ufl expressions, possibly nonscalar and with free indices.
Returning a CRSArray where row i is the total shape of V[i].
-
ffc.uflacs.analysis.graph_symbols.
build_node_sizes
(V_shapes)[source]¶ Compute all the products of a sequence of shapes.
-
ffc.uflacs.analysis.graph_symbols.
build_node_symbols
(V, e2i, V_shapes, V_sizes)[source]¶ Tabulate scalar value numbering of all nodes in a a list based representation of an expression graph.
Returns: V_symbols - CRSArray of symbols (value numbers) of each component of each node in V. total_unique_symbols - The number of symbol values assigned to unique scalar components of the nodes in V.
ffc.uflacs.analysis.graph_vertices module¶
Algorithms for working with graphs.
ffc.uflacs.analysis.indexing module¶
Algorithms for working with multiindices.
ffc.uflacs.analysis.modified_terminals module¶
Definitions of ‘modified terminals’, a core concept in uflacs.
-
class
ffc.uflacs.analysis.modified_terminals.
ModifiedTerminal
(expr, terminal, reference_value, base_shape, base_symmetry, component, flat_component, global_derivatives, local_derivatives, averaged, restriction)[source]¶ Bases:
object
A modified terminal expression is an object of a Terminal subtype, wrapped in terminal modifier types.
The variables of this class are:
expr - The original UFL expression terminal - the underlying Terminal object
global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘
component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
Possibly other component model: - global_component - reference_component - flat_component
-
ffc.uflacs.analysis.modified_terminals.
analyse_modified_terminal
(expr)[source]¶ Analyse a so-called ‘modified terminal’ expression.
Return its properties in more compact form as a ModifiedTerminal object.
A modified terminal expression is an object of a Terminal subtype, wrapped in terminal modifier types.
The wrapper types can include 0-* Grad or ReferenceGrad objects, and 0-1 ReferenceValue, 0-1 Restricted, 0-1 Indexed, and 0-1 FacetAvg or CellAvg objects.
ffc.uflacs.analysis.valuenumbering module¶
Algorithms for value numbering within computational graphs.
-
class
ffc.uflacs.analysis.valuenumbering.
ValueNumberer
(e2i, V_sizes, V_symbols)[source]¶ Bases:
ufl.corealg.multifunction.MultiFunction
An algorithm to map the scalar components of an expression node to unique value numbers, with fallthrough for types that can be mapped to the value numbers of their operands.
-
cell_avg
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
facet_avg
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
grad
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
reference_grad
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
reference_value
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
restricted
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
Module contents¶
Algorithms for the analysis phase of the form compilation.