nifty8.operator_tree_optimiser module#
- optimise_operator(op)[source]#
Merges redundant operations in the tree structure of an operator. For example it is ensured that for
f@x + x
the operatorx
is only computed once. It is supposed to be used on the whole operator chain before doing minimisation.Currently optimises only
_OpChain
,_OpSum
and_OpProd
and not their linear pendantsChainOp
andSumOperator
.- Parameters:
op (Operator) – Operator with a tree structure.
- Returns:
op_optimised – Operator with same input/output, but optimised tree structure.
- Return type:
Notes
Operators are compared only by id, so best results are achieved when the following code
>>> from nifty8 import UniformOperator, DomainTuple >>> uni1 = UniformOperator(DomainTuple.scalar_domain() >>> uni2 = UniformOperator(DomainTuple.scalar_domain() >>> op = (uni1 + uni2)*(uni1 + uni2)
is replaced by something comparable to
>>> uni = UniformOperator(DomainTuple.scalar_domain()) >>> uni_add = uni + uni >>> op = uni_add * uni_add
After optimisation the operator is as fast as
>>> op = (2*uni)**2