braket.default_simulator.openqasm.interpreter module
- class braket.default_simulator.openqasm.interpreter.Interpreter(context: AbstractProgramContext | None = None, logger: Logger | None = None)[source]
Bases:
object
The interpreter is responsible for visiting the AST of an OpenQASM program, as created by the parser, and building a braket.default_simulator.openqasm.circuit.Circuit to hand off to a simulator e.g. braket.default_simulator.state_vector_simulator.StateVectorSimulator.
The interpreter keeps track of all state using a ProgramContext object. The main entry point is build_circuit(), which returns the built circuit. An alternative entry poitn, run() returns the ProgramContext object, which can be used for debugging or other customizability.
- build_circuit(source: str, inputs: dict[str, ConstrainedStrValue | ConstrainedFloatValue | int | List[ConstrainedStrValue | ConstrainedFloatValue | int]] | None = None, is_file: bool = False) Circuit [source]
Interpret an OpenQASM program and build a Circuit IR.
- run(source: str, inputs: dict[str, ConstrainedStrValue | ConstrainedFloatValue | int | List[ConstrainedStrValue | ConstrainedFloatValue | int]] | None = None, is_file: bool = False) ProgramContext [source]
Interpret an OpenQASM program and return the program state
- visit(node: QASMNode | list[QASMNode]) QASMNode | None [source]
- visit(node_list: list) list[QASMNode]
- visit(node: Program) None
- visit(node: ClassicalDeclaration) None
- visit(node: IODeclaration) None
- visit(node: ConstantDeclaration) None
- visit(node: BinaryExpression) BinaryExpression | BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral
- visit(node: UnaryExpression) UnaryExpression | BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral
- visit(node: Cast) BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral
- visit(node: BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral) BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral
- visit(node: BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral) BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral
- visit(node: BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral) BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral
- visit(node: Identifier) BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral
- visit(node: QubitDeclaration) None
- visit(node: QuantumReset) None
- visit(node: IndexedIdentifier) IndexedIdentifier | BooleanLiteral | IntegerLiteral | FloatLiteral | ArrayLiteral | BitstringLiteral
- visit(node: RangeDefinition) RangeDefinition
- visit(node: IndexExpression) IndexedIdentifier | ArrayLiteral
- visit(node: QuantumGateDefinition) None
- visit(node: QuantumGate) None
- visit(node: QuantumPhase) None
- visit(node: QuantumGateModifier) QuantumGateModifier
- visit(node: QuantumMeasurement) None
- visit(node: QuantumMeasurementStatement) None
- visit(node: ClassicalAssignment) None
- visit(node: BitstringLiteral) ArrayLiteral
- visit(node: BranchingStatement) None
- visit(node: ForInLoop) None
- visit(node: WhileLoop) None
- visit(node: Include) None
- visit(node: Pragma) None
- visit(node: SubroutineDefinition) None
- visit(node: FunctionCall) QASMNode | None
- visit(node: ReturnStatement) QASMNode | None
- visit(node: SizeOf) IntegerLiteral
Generic visit function for an AST node
- inline_gate_def_body(body: list[QuantumStatement]) list[QuantumStatement] [source]
- handle_builtin_gate(gate_name: str, arguments: list[FloatLiteral], qubits: list[Identifier | IndexedIdentifier], modifiers: list[QuantumGateModifier]) None [source]
Add unitary operation to the circuit
- handle_phase(phase: FloatLiteral, qubits: Iterable[int] | None = None) None [source]
Add quantum phase operation to the circuit