qblox_scheduler.operations.expressions#

Classes that represent expressions, which produce a value when compiled and executed.

Attributes#

Classes#

DType

Data type of a variable or expression.

Expression

Expression that produces a value when compiled.

UnaryExpression

An expression with one operand and one operator.

BinaryExpression

An expression with two operands and one operator.

Functions#

substitute_value_in_arbitrary_container(→ tuple[Any, bool])

Make the defined substitutions in the container type val.

Module Contents#

class DType[source]#

Bases: qblox_scheduler.enums.StrEnum

Data type of a variable or expression.

NUMBER = 'number'[source]#

A number, corresponding to 1, 2, 3, etc.

AMPLITUDE = 'amplitude'[source]#

An amplitude, corresponding to 0.1, 0.2, 0.3, etc. in dimensionless units ranging from -1 to 1.

TIME = 'time'[source]#

A time, corresponding to 20e-9, 40e-9, 60e-9, etc. in seconds.

FREQUENCY = 'frequency'[source]#

A frequency, corresponding to 1e9, 2e9, 3e9, etc. in Hz.

PHASE = 'phase'[source]#

A phase, corresponding to e.g. 0, 30, 60, 90, etc. in degrees ranging from 0 to 360.

is_timing_sensitive() bool[source]#

Whether an expression of this type affects timing.

class Expression(dict=None, /, **kwargs)[source]#

Bases: collections.UserDict, abc.ABC

Expression that produces a value when compiled.

property dtype: DType[source]#
Abstractmethod:

Data type of the expression.

abstract substitute(substitutions: dict[Expression, Expression | int | float | complex]) Expression | int | float | complex[source]#

Substitute matching parts of expression, possibly evaluating a result.

reduce() Expression | int | float | complex[source]#

Reduce complex ASTs if they can be simplified due to the presence of constants.

_update() None[source]#

Update this expression’s internals.

class UnaryExpression(operator: str, operand: Expression)[source]#

Bases: Expression

An expression with one operand and one operator.

Parameters:
  • operator – The operator that acts on the operand.

  • operand – The expression or variable that is acted on.

EVALUATORS: ClassVar[dict[str, collections.abc.Callable]][source]#
_dtype[source]#
property operator: str[source]#

The operator that acts on the operand.

property operand: Expression[source]#

The expression or variable that is acted on.

property dtype: DType[source]#

Data type of this expression.

_update() None[source]#

Update this expression’s internals.

substitute(substitutions: dict[Expression, Expression | int | float | complex]) Expression | int | float | complex[source]#

Substitute matching operand, possibly evaluating a result.

reduce() Expression | int | float | complex[source]#

Reduce complex ASTs if they can be simplified due to the presence of constants.

Currently only handles a few cases (a is a constant value in these examples):

  • -(-expr) -> expr

  • +(expr * a) -> expr * a (same for /)

  • -(expr * a) -> expr * (-a) (same for /)

Returns:

Expression | int | float | complex The simplified expression.

class BinaryExpression(lhs: Expression | complex, operator: str, rhs: Expression | complex)[source]#

Bases: Expression

An expression with two operands and one operator.

Parameters:
  • lhs – The left-hand side of the expression.

  • operator – The operator that acts on the operands.

  • rhs – The right-hand side of the expression.

EVALUATORS: ClassVar[dict[str, collections.abc.Callable]][source]#
property lhs: Expression[source]#

The left-hand side of the expression.

property operator: str[source]#

The operator that acts on the operands.

property rhs: Expression | complex[source]#

The right-hand side of the expression.

property dtype: DType[source]#

Data type of this expression.

_update() None[source]#

Update this expression’s internals.

substitute(substitutions: dict[Expression, Expression | int | float | complex]) Expression | int | float | complex[source]#

Substitute matching operands, possibly evaluating a result.

reduce() Expression | int | float | complex[source]#

Reduce complex ASTs if they can be simplified due to the presence of constants.

Currently only handles a few cases (a and b are constant values in these examples):

  • expr * 1 -> expr (same for / and //)

  • expr + 0 -> expr (same for other applicable operators)

  • (expr * a) * b -> expr * (a * b)

  • (expr * a) / b -> expr * (a / b)

  • (expr / a) * b -> expr * (b / a)

  • (expr / a) / b -> expr / (a * b)

  • (-expr) * b -> expr * (-b) (same for /)

Returns:

Expression | int | float | complex The simplified expression.

ContainsExpressionType[source]#
substitute_value_in_arbitrary_container(val: ContainsExpressionType, substitutions: dict[Expression, Expression | int | float | complex]) tuple[Any, bool][source]#

Make the defined substitutions in the container type val.