quil.expression
The expression
module contains classes for representing Quil expressions.
A Quil expression.
Variants:
address
: An address defined by aquil.instructions.MemoryReference
.function_call
: AFunctionCallExpression
.infix
: AnInfixExpression
.number
: A number defined as acomplex
.pi
: The constantpi
. No inner data.prefix
: APrefixExpression
.variable
: A variable defined as astr
.
As seen above, some variants contain inner data that fully specify the expression.
For example, the number
variant contains an int
. This is in contrast to variants like
pi
that have no inner data because they require none to fully specify the expression.
This difference is important for determining which methods are available for each variant.
Methods (for every variant):
is_*
: ReturnsTrue
if the expression is that variant,False
otherwise.
If the variant has inner data:
as_*
: returns the inner data if it is the given variant,None
otherwise.to_*
: returns the inner data if it is the given variant, raisesValueError
otherwise.from_*
: Creates a newExpression
of the given variant from an instance of the inner type.
If the variant doesn't have inner data (e.g. pi
)
new_*
: Creates a newExpression
for the variant
Returns the inner value of the variant. Raises a RuntimeError
if inner data doesn't exist.
Attempt to convert the instruction to a valid Quil string. Raises an exception if the instruction can't be converted to valid Quil.
Convert the instruction to a Quil string.
If any part of the instruction can't be converted to valid Quil, it will be printed in a human-readable debug format that isn't valid Quil.
Parses an Expression
from a string.
Raises a ParseExpressionError
if the string isn't a valid Quil expression.
Evaluate an expression, expecting that it may be fully reduced to a single complex number.
If it cannot be reduced to a complex number, raises an EvaluationError
.
Returns a copy of the expression where every matching variable in variable_values
is replaced by the corresponding expression.
If this is a number with imaginary part "equal to" zero (of small absolute value), return that number. Otherwise, raises an EvaluationError
.
A Quil function call.
A Quil infix expression.
A Quil prefix expression.
An enum representing a Quil function that can be applied to an expression.
An enum that represents the operators supported on a prefix expression.
An enum that represents the operators supported on an infix expression.
Error that may occur while evaluation an Expression
.
Inherited Members
- builtins.ValueError
- ValueError
- builtins.BaseException
- with_traceback
- add_note
- args
Error that may occur while parsing an Expression
.
Inherited Members
- builtins.ValueError
- ValueError
- builtins.BaseException
- with_traceback
- add_note
- args