QXel.provider.braket.openqasm.parser.openqasm_ast module¶
Abstract Syntax Tree (openqasm3.ast)¶
The reference abstract syntax tree (AST) for OpenQASM 3 programs.
- class QXel.provider.braket.openqasm.parser.openqasm_ast.AccessControl(*values)¶
Bases:
Enum- const = 1¶
- mutable = 2¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.AliasStatement(target, value)¶
Bases:
StatementAlias statement
Example:
let a = qubits[0];
- target¶
- value¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.AngleType(size=None)¶
Bases:
ClassicalTypeNode representing the classical
angletype, with an optional precision.Example:
angle[8] angle[16]
- size = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Annotation(keyword, command=None)¶
Bases:
QASMNodeAn annotation applied to a statment.
- keyword¶
- command = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ArrayLiteral(values)¶
Bases:
ExpressionArray literal, used to initialise declared arrays.
For example:
array[uint[8], 2] row = {1, 2}; array[uint[8], 2, 2] my_array = {{1, 2}, {3, 4}}; array[uint[8], 2, 2] my_array = {row, row};
- values¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ArrayReferenceType(base_type, dimensions)¶
Bases:
ClassicalTypeType of arrays that are a reference to an array with allocated storage.
This is generally any array declared as a subroutine argument. The dimensions can be either a list of expressions (one for each dimension), or a single expression, which is the number of dimensions.
For example:
// `a` will have dimensions `[IntegerLiteral(2)]` (with a list), because // it is a 1D array, with a length of 2. def f(const array[uint[8], 2] a) {} // `b` will have dimension `IntegerLiteral(3)` (no list), because it is // a 3D array, but we don't know the lengths of its dimensions. def f(const array[uint[8], #dim=3] b) {}- base_type¶
- dimensions¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ArrayType(base_type, dimensions)¶
Bases:
ClassicalTypeType of arrays that include allocation of the storage.
This is generally any array declared as a standard statement, but not arrays declared by being arguments to subroutines.
- base_type¶
- dimensions¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.AssignmentOperator(*values)¶
Bases:
Enum
- class QXel.provider.braket.openqasm.parser.openqasm_ast.BinaryExpression(op, lhs, rhs)¶
Bases:
ExpressionA binary expression
Example:
q1 || q2
- op¶
- lhs¶
- rhs¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.BinaryOperator(*values)¶
Bases:
Enum
- class QXel.provider.braket.openqasm.parser.openqasm_ast.BitType(size=None)¶
Bases:
ClassicalTypeNode representing the classical
bittype, with an optional size.Example:
bit[8] creg[8]
- size = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.BitstringLiteral(value, width)¶
Bases:
ExpressionA literal bitstring value. The
valueis the numerical value of the bitstring, and thewidthis the number of digits given.- value¶
- width¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.BoolType¶
Bases:
ClassicalTypeLeaf node representing the Boolean classical type.
- class QXel.provider.braket.openqasm.parser.openqasm_ast.BooleanLiteral(value)¶
Bases:
ExpressionA boolean expression
Example:
true false
- value¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Box(duration, body)¶
Bases:
QuantumStatementTiming box
Example:
box [maxdur] { delay[start_stretch] $0; x $0; }- duration¶
- body¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.BranchingStatement(condition, if_block, else_block)¶
Bases:
StatementBranch (
if) statementExample:
if (temp == 1) { ry(-pi / 2) scratch[0]; } else continue;
- condition¶
- if_block¶
- else_block¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.BreakStatement¶
Bases:
StatementBreak statement
Example:
break;
- class QXel.provider.braket.openqasm.parser.openqasm_ast.CalibrationDefinition(name, arguments, qubits, return_type, body)¶
Bases:
StatementCalibration definition
Example:
defcal rz(angle[20] theta) q { shift_phase drive(q), -theta; }
- name¶
- arguments¶
- qubits¶
- return_type¶
- body¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.CalibrationGrammarDeclaration(name)¶
Bases:
StatementCalibration grammar declaration
Example:
defcalgrammar "openpulse";
- name¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Cast(type, argument)¶
Bases:
ExpressionA cast call expression
Example:
counts += int[1](b);
- type¶
- argument¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ClassicalArgument(type, name, access=None)¶
Bases:
QASMNodeClassical argument for a gate or subroutine declaration
- type¶
- name¶
- access = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ClassicalAssignment(lvalue, op, rvalue)¶
Bases:
StatementClassical assignment
Example:
a[0] = 1;
- lvalue¶
- op¶
- rvalue¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ClassicalDeclaration(type, identifier, init_expression=None)¶
Bases:
StatementClassical variable declaration
Example:
bit c;
- type¶
- identifier¶
- init_expression = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ClassicalType¶
Bases:
QASMNodeBase class for classical type
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ComplexType(base_type)¶
Bases:
ClassicalTypeComplex ClassicalType. Its real and imaginary parts are based on other classical types.
Example:
complex[float] complex[float[32]]
- base_type¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Concatenation(lhs, rhs)¶
Bases:
ExpressionConcatenation of two registers, for example:
a ++ b a[2:3] ++ a[0:1]
- lhs¶
- rhs¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ConstantDeclaration(type, identifier, init_expression)¶
Bases:
StatementConstant declaration
Example:
const int[16] n = 10;
- type¶
- identifier¶
- init_expression¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ContinueStatement¶
Bases:
StatementContinue statement
Example:
continue;
- class QXel.provider.braket.openqasm.parser.openqasm_ast.DelayInstruction(duration, qubits)¶
Bases:
QuantumStatementDelay instruction
Example:
delay[start_stretch] $0;
- duration¶
- qubits¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.DiscreteSet(values)¶
Bases:
QASMNodeA set of discrete values. This can be used for the values in a
forloop, or to index certain values out of a register:for i in {1, 2, 3} {} let alias = qubits[{2, 3, 4}];
- values¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.DurationLiteral(value, unit)¶
Bases:
ExpressionA duration literal
Example:
1.0ns
- value¶
- unit¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.DurationOf(target)¶
Bases:
ExpressionDuration Of
Example:
durationof({x $0;})- target¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.DurationType¶
Bases:
ClassicalTypeLeaf node representing the
durationtype.
- class QXel.provider.braket.openqasm.parser.openqasm_ast.EndStatement¶
Bases:
StatementEnd statement
Example:
end;
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Expression¶
Bases:
QASMNodeAn expression: anything that returns a value
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ExpressionStatement(expression)¶
Bases:
StatementA statement that contains a single expression
- expression¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ExternDeclaration(name, arguments, return_type=None)¶
Bases:
StatementA extern declaration
Example:
extern get_pauli(int[prec]) -> bit[2 * n]; get_pauli // <- name int[prec] // <- classical type bit[2 * n] // <- return type
- name¶
- arguments¶
- return_type = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.FloatLiteral(value)¶
Bases:
ExpressionAn real number literal
Example:
1.1- value¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.FloatType(size=None)¶
Bases:
ClassicalTypeNode representing the classical
floattype, with the particular IEEE-754 floating-point size optionally specified.Example
float[16] float[64]
- size = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ForInLoop(type, identifier, set_declaration, block)¶
Bases:
StatementFor in loop
Example:
for i in [0: 2] { majority a[i], b[i + 1], a[i + 1]; }
- type¶
- identifier¶
- set_declaration¶
- block¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.FunctionCall(name, arguments)¶
Bases:
ExpressionA function call expression
Example:
foo(1) foo // <- name
- name¶
- arguments¶
- QXel.provider.braket.openqasm.parser.openqasm_ast.GateModifierName¶
alias of
GateModifier
- class QXel.provider.braket.openqasm.parser.openqasm_ast.IODeclaration(io_identifier, type, identifier)¶
Bases:
StatementInput/output variable declaration
Exampe:
input angle[16] theta; output bit select;
- io_identifier¶
- type¶
- identifier¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.IOKeyword(*values)¶
Bases:
Enum- input = 1¶
- output = 2¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Identifier(name)¶
Bases:
ExpressionAn identifier
Example:
q1- name¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Include(filename)¶
Bases:
StatementAn include statement
- filename¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.IndexExpression(collection, index)¶
Bases:
ExpressionAn index expression.
Example:
q[1]
- collection¶
- index¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.IndexedIdentifier(name, indices)¶
Bases:
QASMNodeAn indentifier with index operators, such that it can be used as an lvalue. The list of indices is subsequent index brackets, so in:
a[{1, 2, 3}][0:1, 0:1]
the list of indices will have two elements. The first will be a
DiscreteSet, and the second will be a list of twoRangeDefinitions.- name¶
- indices¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.IntType(size=None)¶
Bases:
ClassicalTypeNode representing a classical
int(signed integer) type, with an optional precision.Example
int[8] int[16]
- size = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.IntegerLiteral(value)¶
Bases:
ExpressionAn integer literal
Example:
1- value¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Pragma¶
Bases:
QASMNodeExample:
#pragma val1 val2 val3- command¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Program(statements, version=None)¶
Bases:
QASMNodeAn entire OpenQASM 3 program represented by a list of top level statements
- statements¶
- version = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QASMNode¶
Bases:
objectBase class for all OpenQASM 3 nodes
- span = None¶
The span(location) of the node in the source code. Because not all the nodes are generated from source, the span is optional. To make it easier to write unit test, we exclude span from the generated __eq__().
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumArgument(name, size=None)¶
Bases:
QASMNodeQuantum argument for a subroutine declaration
- name¶
- size = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumBarrier(qubits)¶
Bases:
QuantumStatementA quantum barrier instruction
Example:
barrier q;
- qubits¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumGate(modifiers, name, arguments, qubits, duration=None)¶
Bases:
QuantumStatementInvoking a quantum gate
- Example::
cx[dur] 0, 1;
or
ctrl @ p(λ) a, b;
ctrl @ // <- quantumGateModifier p // <- quantumGateName λ // <- argument a, b // <- qubit
- modifiers¶
- name¶
- arguments¶
- qubits¶
- duration = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumGateDefinition(name, arguments, qubits, body)¶
Bases:
StatementDefine a new quantum gate
Example:
gate cx c, t { ctrl @ unitary(pi, 0, pi) c, t; }
- name¶
- arguments¶
- qubits¶
- body¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumGateModifier(modifier, argument=None)¶
Bases:
QASMNodeA quantum gate modifier.
Example:
inv @ pow(1/2) ctrl
- modifier¶
- argument = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumMeasurement(qubit)¶
Bases:
QASMNodeA quantum measurement instruction
Example:
measure q;
- qubit¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumMeasurementStatement(measure, target)¶
Bases:
StatementStand-alone statement of a quantum measurement, potentially assigning the result to a classical variable. This is not the only statement that measure can appear in (it can also be in classical declaration statements and returns).
- measure¶
- target¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumPhase(modifiers, argument, qubits)¶
Bases:
QuantumStatementA quantum phase instruction
Example:
ctrl @ gphase(λ) a; ctrl @ // <- quantumGateModifier λ // <- argument a // <- qubit
- modifiers¶
- argument¶
- qubits¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumReset(qubits)¶
Bases:
QuantumStatementA reset instruction.
Example:
reset q;
- qubits¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QuantumStatement¶
Bases:
StatementStatements that may appear inside a gate declaration
- class QXel.provider.braket.openqasm.parser.openqasm_ast.QubitDeclaration(qubit, size=None)¶
Bases:
StatementGlobal qubit declaration
Example:
qubit q; qubit[4] q; q // <- qubit 4 // <- size
- qubit¶
- size = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.RangeDefinition(start, end, step)¶
Bases:
QASMNodeRange definition.
Example:
1:2 1:1:10 :
- start¶
- end¶
- step¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.ReturnStatement(expression=None)¶
Bases:
StatementClassical or quantum return statement
Example:
return measure q; return a + b
- expression = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.SizeOf(target, index=None)¶
Bases:
Expressionsizeofan array’s dimensions.- target¶
- index = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Span(start_line, start_column, end_line, end_column)¶
Bases:
objectStart and end line/column in the source file We use the Antlr convention. The starting line number is 1 and starting column number is 0.
- start_line¶
- start_column¶
- end_line¶
- end_column¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.Statement¶
Bases:
QASMNodeA statement: anything that can appear on its own line
- annotations¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.StretchType¶
Bases:
ClassicalTypeLeaf node representing the
stretchtype.
- class QXel.provider.braket.openqasm.parser.openqasm_ast.SubroutineDefinition(name, arguments, body, return_type=None)¶
Bases:
StatementSubroutine definition
Example:
def measure(qubit q) -> bit { s q; h q; return measure q; }
- name¶
- arguments¶
- body¶
- return_type = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.TimeUnit(*values)¶
Bases:
Enum- dt = 1¶
- ns = 2¶
- us = 3¶
- ms = 4¶
- s = 5¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.UintType(size=None)¶
Bases:
ClassicalTypeNode representing a classical
uint(unsigned integer) type, with an optional precision.Example
uint[8] uint[16]
- size = None¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.UnaryExpression(op, expression)¶
Bases:
ExpressionA unary expression
Example:
~b !bool -i
- op¶
- expression¶
- class QXel.provider.braket.openqasm.parser.openqasm_ast.UnaryOperator(*values)¶
Bases:
Enum