sympy

import tensorwaves.model.sympy

Lambdify sympy expression trees from a Model to a Function.

class SympyModel(expression: Expr, parameters: Dict[Symbol, Union[complex, float]], use_cse: bool = True, max_complexity: Optional[int] = None)[source]

Bases: tensorwaves.interface.Model

Full definition of an arbitrary model based on sympy.

Note that input for particle physics amplitude models are based on four-momenta. However, for reasons of convenience, some models may define and use a distinct set of kinematic variables (e.g. in the helicity formalism: angles \(\theta\) and \(\phi\)). In this case, a DataTransformer instance (adapter) is needed to transform four momentum information into the custom set of kinematic variables.

Parameters
  • expression – A sympy expression that contains the complete information of the model based on some inputs. The inputs are defined via the free_symbols attribute of the sympy.Expr.

  • parameters – Defines which inputs of the model are parameters. The keys represent the parameter set, while the values represent their default values. Consequently, the variables of the model are defined as the intersection of the total input set with the parameter set.

property argument_order: Tuple[str, ...]

Order of arguments of lambdified function signature.

lambdify(backend: Union[str, tuple, dict]) Callable[source]

Lambdify the model using lambdify.

property parameters: Dict[str, Union[complex, float]]

Get mapping of parameters to suggested initial values.

performance_optimize(fix_inputs: Mapping[Union[int, str], ndarray]) Model[source]

Create a performance optimized model, based on fixed inputs.

property variables: FrozenSet[str]

Expected input variable names.

optimized_lambdify(expression: Expr, symbols: Sequence[Symbol], backend: Union[str, tuple, dict], use_cse: bool = True, *, min_complexity: int = 0, max_complexity: int) Callable[source]

Speed up lambdify with split_expression.

split_expression(expression: Expr, max_complexity: int, min_complexity: int = 1) Tuple[Expr, Dict[Symbol, Expr]][source]

Split an expression into a ‘top expression’ and several sub-expressions.

Replace nodes in the expression tree of a sympy.Expr that lie within a certain complexity range (see count_ops()) with symbols and keep a mapping of each to these symbols to the sub-expressions that they replaced.