io
9.7. io#
import polarimetry.io
Input-output functions for ampform and sympy objects.
Functions in this module are registered with functools.singledispatch() and can be
extended as follows:
This code originates from ComPWA/ampform#280.
- as_latex(obj, **kwargs) str[source]#
Render objects as a LaTeX
str.The resulting
strcan for instance be given toIPython.display.Math.Optional keywords:
- display_doit(expr: UnevaluatedExpression, deep=False, terms_per_line: int | None = None) None[source]#
- perform_cached_doit(unevaluated_expr: Expr, directory: str | None = None) Expr[source]#
Perform
doit()on anExprand cache the result to disk.The cached result is fetched from disk if the hash of the original expression is the same as the hash embedded in the filename.
- Parameters
unevaluated_expr – A
sympy.Expron which to calldoit().directory – The directory in which to cache the result. If
None, the cache directory will be put under the home directory, or to the path specified by the environment variableSYMPY_CACHE_DIR.
Tip
For a faster cache, set PYTHONHASHSEED to a fixed value.
See also
- perform_cached_lambdify(expr: Expr, parameters: Mapping[Symbol, ParameterValue] | None = None, backend: str = 'jax', directory: str | None = None) ParametrizedFunction | Function[source]#
Lambdify a SymPy
Exprand cache the result to disk.The cached result is fetched from disk if the hash of the expression is the same as the hash embedded in the filename.
- Parameters
expr – A
sympy.Expron which to callcreate_function()orcreate_parametrized_function().parameters – Specify this argument in order to create a
ParametrizedBackendFunctioninstead of aPositionalArgumentFunction.backend – The choice of backend for the created numerical function. WARNING: this function has only been tested for
backend="jax"!directory – The directory in which to cache the result. If
None, the cache directory will be put under the home directory, or to the path specified by the environment variableSYMPY_CACHE_DIR.
Tip
For a faster cache, set PYTHONHASHSEED to a fixed value.
See also