9.7. io#

Input-output functions for ampform and sympy objects.

Functions in this module are registered with functools.singledispatch() and can be extended as follows:

>>> from polarimetry.io import as_latex
>>> @as_latex.register(int)
... def _(obj: int) -> str:
...     return "my custom rendering"
>>> as_latex(1)
'my custom rendering'
>>> as_latex(3.4 - 2j)
'3.4-2i'

This code originates from ComPWA/ampform#280.

as_latex(obj, **kwargs) str[source]#

Render objects as a LaTeX str.

The resulting str can for instance be given to IPython.display.Math.

Optional keywords:

  • only_jp: Render a Particle as \(J^P\) value (spin-parity) only.

  • with_jp: Render a Particle with value \(J^P\) value.

as_markdown_table(obj: Sequence) str[source]#

Render objects a str suitable for generating a table.

display_latex(obj) None[source]#
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 an Expr and 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.Expr on which to call doit().

  • 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 variable SYMPY_CACHE_DIR.

Tip

For a faster cache, set PYTHONHASHSEED to a fixed value.

perform_cached_lambdify(expr: Expr, parameters: Mapping[Symbol, ParameterValue] | None = None, backend: str = 'jax', directory: str | None = None) ParametrizedFunction | Function[source]#

Lambdify a SymPy Expr and 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

Tip

For a faster cache, set PYTHONHASHSEED to a fixed value.

get_readable_hash(obj) str[source]#
mute_jax_warnings() None[source]#
export_polarimetry_field(sigma1: ndarray, sigma2: ndarray, alpha_x: ndarray, alpha_y: ndarray, alpha_z: ndarray, intensity: ndarray, filename: str, metadata: dict | None = None) None[source]#
import_polarimetry_field(filename: str, steps: int = 1) dict[str, ndarray][source]#