3.3. qupulse.expressions

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

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

Bases: qupulse.serialization.AnonymousSerializable

Base class for expressions.

evaluate_in_scope(scope)[source]

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

Returns:

Return type

Union[Number, ndarray]

evaluate_numeric(**kwargs)[source]
Return type

Union[Number, ndarray]

evaluate_symbolic(substitutions)[source]
Return type

Expression

classmethod make(expression_or_dict, numpy_evaluation=None)[source]

Backward compatible expression generation

Return type

Union[ExpressionScalar, ExpressionVector, ~_ExpressionType]

property underlying_expression
Return type

Union[Expr, ndarray]

property variables

Get all free variables in the expression.

Return type

Sequence[str]

Returns

A collection of all free variables occurring in the expression.

exception qupulse.expressions.ExpressionVariableMissingException(variable, expression)[source]

Bases: Exception

An exception indicating that a variable value was not provided during expression evaluation.

See also

qupulse.expressions.Expression

class qupulse.expressions.ExpressionScalar(ex)[source]

Bases: qupulse.expressions.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)[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

Return type

None

get_serialization_data()[source]

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

Return type

Union[str, float, int]

Returns

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

is_nan()[source]
Return type

bool

property original_expression
Return type

Union[str, Number]

property sympified_expression
Return type

Expr

property underlying_expression
Return type

Expr

property variables

Get all free variables in the expression.

Return type

Sequence[str]

Returns

A collection of all free variables occurring in the expression.

class qupulse.expressions.ExpressionVector(expression_vector)[source]

Bases: qupulse.expressions.Expression

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

evaluate_numeric(**kwargs)[source]
Return type

Union[ndarray, Number]

property expression_lambda
Return type

Callable

get_serialization_data()[source]

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

Return type

Sequence[str]

Returns

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

sympify_vector = <numpy.vectorize object>
property underlying_expression
Return type

ndarray

property variables

Get all free variables in the expression.

Return type

Sequence[str]

Returns

A collection of all free variables occurring in the expression.