autoqasm.simulator.native_interpreter module

class autoqasm.simulator.native_interpreter.NativeInterpreter(simulation: Simulation, context: McmProgramContext | None = None, logger: Logger | None = None)[source]

Bases: Interpreter

simulate(source: str, inputs: dict[str, Any] | None = None, is_file: bool = False, shots: int = 1) dict[str, Any][source]

Simulates the given program.

Parameters:
  • source (str) – The OpenQASM source program, or a filename containing the OpenQASM source program.

  • inputs (Optional[dict[str, Any]]) – The input parameter values to the OpenQASM source program. Defaults to None.

  • is_file (bool) – Whether source is a filename. Defaults to False.

  • shots (int) – Number of shots of the program to simulate. Defaults to 1.

Returns:

dict[str, Any] – Outputs of the program.

visit(node: QASMNode | list[QASMNode]) QASMNode | None[source]
visit(node: QubitDeclaration) None
visit(node: QuantumMeasurement) BooleanLiteral | ArrayLiteral
visit(node: QuantumMeasurementStatement) BooleanLiteral | ArrayLiteral
visit(node: QuantumReset) None
visit(node: IODeclaration) None

Generic visit function for an AST node

handle_builtin_gate(gate_name: str, arguments: list, qubits: list, modifiers: list) None[source]

Handle a call to a built-in quantum gate.

Intercepts the IQM classical-control gates measure_ff and cc_prx and implements them directly against self.simulation, bypassing the upstream ProgramContext mid-circuit-measurement pipeline (which is built around a one-pass, all-shots-at-once branching model incompatible with this per-shot interpreter).