lightcurvelynx.math_nodes.basic_math_node

Nodes that perform basic math operations that can be specified as strings.

The goal of this library is to save users from needing to create a bunch of small FunctionNodes to perform basic math.

Classes

BasicMathNode

A node that evaluates basic mathematical functions.

Module Contents

class BasicMathNode(expression, backend='numpy', node_label=None, **kwargs)[source]

Bases: lightcurvelynx.base_models.FunctionNode

A node that evaluates basic mathematical functions.

The BasicMathNode wraps Python’s eval() function to sanitize the input string and thus prevent the execution of arbitrary code. It also allows the user to write the expression once and execute using math, numpy, or JAX. The names of the variables in the expression must match the input variables provided by kwargs.

Example:

my_node = BasicMathNode(
    "redshift + 10.0 * sin(phase)",
    redshift=host.redshift,
    phase=source.phase,
)
expression

The expression to evaluate.

Type:

str

backend

The math libary to use. This is auto-converted to one of (math, np, or jnp) depending on the input parameter.

Type:

str

Parameters:
  • expression (str) – The expression to evaluate.

  • backend (str) – The math libary to use. Must be one of: math, numpy, np, jax, or jnp.

  • node_label (str, optional) – An identifier (or name) for the current node.

  • **kwargs (dict, optional) – Any additional keyword arguments. Every variable in the expression must be included as a kwarg.

__getstate__()[source]

We override the default pickling behavior to handle non-pickable attributes such as the backend_lib and to_array function.

__setstate__(state)[source]

We override the default unpickling behavior to restore the non-pickable attributes.

eval(**kwargs)[source]

Evaluate the expression.

static list_functions()[source]

Return a list of the support functions.

Returns:

A list of the supported functions.

Return type:

list