nifty7.operator_tree_optimiser module


Merges redundant operations in the tree structure of an operator. For example it is ensured that for f@x + x the operator x 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 pendants ChainOp and SumOperator.


op (Operator) – Operator with a tree structure.


op_optimised – Operator with same input/output, but optimised tree structure.

Return type



Operators are compared only by id, so best results are achieved when the following code

>>> from nifty7 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