qat.runtime.expressions module
Variables and Expressions for Quantum Program Runtime Arguments.
Provides a Pydantic-serializable representation of typed variables and expressions (unary/binary) over those variables and literals. Intended for use in variational quantum circuits, software-iterated sweeps, and general runtime argument injection via virtual registers.
- class BinaryExpression(**data)
Bases:
BaseModelA representation of a binary operation on two nodes, which might be literals, variables, or nested expressions.
- Variables:
operator – The binary operator to apply.
left – The left operand, which can be a Variable, Literal, or another expression.
right – The right operand, which can be a Variable, Literal, or another expression.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- evaluate(params=None)
Evaluate the expression, resolving free variables from params.
- Parameters:
params¶ (
Optional[dict[str,Any]]) – Dictionary of variable values to use for evaluation.- Return type:
Any
- left: Node
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- operator: BinaryOp
- right: Node
- class BinaryOp(value)
Bases:
str,EnumBinary operators supported in expressions.
For now, this only includes basic arithmetic operators, but we can easily expand this in the future.
- Variables:
ADD – Addition operator, does
a + bSUB – Subtraction operator, does
a - bMUL – Multiplication operator, does
a * bDIV – Division operator, does
a / bPOW – Power operator, does
a ** bMOD – Modulo operator, does
a % b
- ADD = 'add'
- DIV = 'div'
- MOD = 'mod'
- MUL = 'mul'
- POW = 'pow'
- SUB = 'sub'
- class Literal(**data)
Bases:
BaseModelA concrete numeric constant wrapped for use inside an expression tree.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- evaluate(_params=None)
Evaluate the literal, which just returns its value.
- Return type:
Any
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- simplify(_params=None)
Does nothing, as a literal is already as simple as it can be.
- Return type:
- value: int | float | complex | bool
- class UnaryExpression(**data)
Bases:
BaseModelAn expression that applies a unary operator to a single operand.
- Variables:
operator – The unary operator to apply.
operand – The operand, which can be a Variable, Literal, or another expression.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- evaluate(params=None)
Evaluate the expression, resolving free variables from params.
- Parameters:
params¶ (
Optional[dict[str,Any]]) – Optional dict of variable values to use for evaluation.- Return type:
Any
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- operand: Node
- operator: UnaryOp
- class UnaryOp(value)
Bases:
str,EnumUnary operators supported in expressions.
This only includes a basic subset of operators, but we can easily expand this in the future.
- Variables:
NEG – Negation operator, does
-xABS – Absolute value operator, does
abs(x)SIN – Sine operator, does
sin(x)COS – Cosine operator, does
cos(x)SQRT – Square root operator, does
sqrt(x)
- ABS = 'abs'
- COS = 'cos'
- NEG = 'neg'
- SIN = 'sin'
- SQRT = 'sqrt'
- class Variable(**data)
Bases:
BaseModelA named and typed variable representing a runtime argument.
- Variables:
name – Unique identifier for the variable.
var_type – The
VariableTypeof this variable.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- evaluate(params=None)
Evaluate the variable, fetching the value from params.
- Parameters:
params¶ (
Optional[dict[str,Any]]) – Optional dict of variable values to use for evaluation.- Return type:
Any
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str
- classmethod name_must_be_nonempty(v)
- Return type:
str
- simplify(params=None)
Simplifies a variable by replacing it with a literal if the value is known.
- var_type: VariableType
- class VariableType(value)
Bases:
str,EnumSupported types for program variables.
This includes standard numeric types, but also domain-specific types such as Phase and Frequency, which are contextually needed to correctly interpret their meaning in quantum programs.
- AMPLITUDE = 'amplitude'
- BOOL = 'bool'
- COMPLEX = 'complex'
- FLOAT = 'float'
- FREQUENCY = 'frequency'
- INT = 'int'
- PHASE = 'phase'
- TIME = 'time'
- cos(operand)
Construct a
cosUnaryExpression.- Return type:
- sin(operand)
Construct a
sinUnaryExpression.- Return type:
- sqrt(operand)
Construct a
sqrtUnaryExpression.- Return type: