model
model#
import tensorwaves.model
Evaluatable physics models for amplitude analysis.
The model
module takes care of lambdifying mathematical expressions to
computational backends. Currently, mathematical expressions are implemented
as sympy
expressions only.
- class LambdifiedFunction(model: Model, backend: Union[str, tuple, dict] = 'numpy')[source]#
Bases:
tensorwaves.interfaces.Function
Implements
Function
based on aModel
using {meth}`~.Model.lambdify`.
- class SympyModel(expression: Expr, parameters: Dict[Symbol, Union[float, complex]], max_complexity: Optional[int] = None)[source]#
Bases:
tensorwaves.interfaces.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.- Args: expressionA sympy expression that contains the complete
information of the model based on some inputs. The inputs are defined via the
free_symbols
attribute of thesympy.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 parameters: Dict[str, Union[complex, float]]#
Get mapping of parameters to suggested initial values.
- get_backend_modules(backend: Union[str, tuple, dict]) Union[str, tuple, dict] [source]#
Preprocess the backend argument passed to
lambdify
.Note in
lambdify
the backend is specified via themodules
argument.
- optimized_lambdify(args: Sequence[Symbol], expression: Expr, modules: Optional[Union[str, tuple, dict]] = None, *, min_complexity: int = 0, max_complexity: int, **kwargs: Any) Callable [source]#
Speed up
lambdify
withsplit_expression
.See also
- split_expression(expression: Expr, max_complexity: int, min_complexity: int = 0) 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 (seecount_ops()
) with symbols and keep a mapping of each to these symbols to the sub-expressions that they replaced.See also