3.1.2. qupulse.expressions.sympy

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

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.

class Expression(*args, **kwargs)[source]

Bases: AnonymousSerializable

Base class for expressions.

evaluate_in_scope(scope: Mapping) Number | 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) Number | ndarray[source]
evaluate_symbolic(substitutions: Mapping[Any, Any]) Expression[source]
classmethod make(expression_or_dict, numpy_evaluation=None) ExpressionScalar | ExpressionVector | _ExpressionType[source]

Backward compatible expression generation

property underlying_expression: Expr | ndarray
property variables: Sequence[str]

Get all free variables in the expression.

Returns:

A collection of all free variables occurring in the expression.

class ExpressionScalar(*args, **kwargs)[source]

Bases: 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

evaluate_in_scope(scope: Mapping) Number | 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) Number | ndarray[source]
get_serialization_data() 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: str | Number
property sympified_expression: Expr
property underlying_expression: Expr
property variables: Sequence[str]

Get all free variables in the expression.

Returns:

A collection of all free variables occurring in the expression.

class ExpressionVector(*args, **kwargs)[source]

Bases: Expression

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

evaluate_in_scope(scope: Mapping) 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() ndarray[source]
property underlying_expression: ndarray
property variables: Sequence[str]

Get all free variables in the expression.

Returns:

A collection of all free variables occurring in the expression.