3.2.2. qupulse.expressions.sympy

This module defines the class Expression to represent mathematical expression as well as corresponding exception classes.

Functions

_flat_iter(arr)

_parse_evaluate_numeric(result)

Tries to parse the result as a scalar if possible.

_parse_evaluate_numeric_vector(vector_result)

Classes

Expression(*args, **kwargs)

Base class for expressions.

ExpressionScalar(*args, **kwargs)

A scalar mathematical expression instantiated from a string representation.

ExpressionVector(*args, **kwargs)

N-dimensional expression.

_ExpressionMeta

Metaclass that forwards calls to Expression(...) to Expression.make(...) to make subclass objects

class qupulse.expressions.sympy.Expression(*args, **kwargs)[source]

Bases: qupulse.serialization.AnonymousSerializable

Base class for expressions.

evaluate_in_scope(scope: Mapping) Union[numbers.Number, numpy.ndarray][source]

Evaluate the expression by taking the variables from the given scope (typically of type Scope but it can be any mapping.) :param scope:

Returns:

evaluate_numeric(**kwargs) Union[numbers.Number, numpy.ndarray][source]
evaluate_symbolic(substitutions: Mapping[Any, Any]) qupulse.expressions.sympy.Expression[source]
classmethod make(expression_or_dict, numpy_evaluation=None) Union[qupulse.expressions.sympy.ExpressionScalar, qupulse.expressions.sympy.ExpressionVector, qupulse.expressions.sympy._ExpressionType][source]

Backward compatible expression generation

property underlying_expression: Union[sympy.core.expr.Expr, numpy.ndarray]
property variables: Sequence[str]

Get all free variables in the expression.

Returns

A collection of all free variables occurring in the expression.

class qupulse.expressions.sympy.ExpressionScalar(*args, **kwargs)[source]

Bases: qupulse.expressions.sympy.Expression

A scalar mathematical expression instantiated from a string representation. TODO: update doc! TODO: write tests!

Create an Expression object.

Receives the mathematical expression which shall be represented by the object as a string which will be parsed using py_expression_eval. For available operators, functions and constants see SymPy documentation

Parameters

ex (string) – The mathematical expression represented as a string

__init__(ex: Union[str, numbers.Number, sympy.core.expr.Expr]) None[source]

Create an Expression object.

Receives the mathematical expression which shall be represented by the object as a string which will be parsed using py_expression_eval. For available operators, functions and constants see SymPy documentation

Parameters

ex (string) – The mathematical expression represented as a string

evaluate_in_scope(scope: Mapping) Union[numbers.Number, numpy.ndarray][source]

Evaluate the expression by taking the variables from the given scope (typically of type Scope but it can be any mapping.) :param scope:

Returns:

evaluate_with_exact_rationals(scope: Mapping) Union[numbers.Number, numpy.ndarray][source]
get_serialization_data() Union[str, float, int][source]

Return all data relevant for serialization as a JSON compatible type that is accepted as constructor argument

Returns

A JSON compatible type that can be used to construct an equal object.

is_nan() bool[source]
property original_expression: Union[str, numbers.Number]
property sympified_expression: sympy.core.expr.Expr
property underlying_expression: sympy.core.expr.Expr
property variables: Sequence[str]

Get all free variables in the expression.

Returns

A collection of all free variables occurring in the expression.

class qupulse.expressions.sympy.ExpressionVector(*args, **kwargs)[source]

Bases: qupulse.expressions.sympy.Expression

N-dimensional expression. TODO: write doc! TODO: write tests!

evaluate_in_scope(scope: Mapping) numpy.ndarray[source]

Evaluate the expression by taking the variables from the given scope (typically of type Scope but it can be any mapping.) :param scope:

Returns:

get_serialization_data() Sequence[str][source]

Return all data relevant for serialization as a JSON compatible type that is accepted as constructor argument

Returns

A JSON compatible type that can be used to construct an equal object.

sympify_vector = <numpy.vectorize object>
to_ndarray() numpy.ndarray[source]
property underlying_expression: numpy.ndarray
property variables: Sequence[str]

Get all free variables in the expression.

Returns

A collection of all free variables occurring in the expression.