uniqc.qasm.qasm_base_parser module#

OpenQASM 2.0 base parser module.

This module provides the base parser for OpenQASM 2.0 quantum circuit representation, including parsing qreg/creg definitions, quantum operations, and measurement statements.

Key exports:

OpenQASM2_BaseParser: Base parser class for OpenQASM 2.0 circuits.

class uniqc.qasm.qasm_base_parser.OpenQASM2_BaseParser[source]#

Bases: object

Parser for OpenQASM 2.0 quantum circuit representation.

Variables:
  • qregs – List of quantum register tuples (name, size).

  • cregs – List of classical register tuples (name, size).

  • n_qubit – Total number of qubits.

  • n_cbit – Total number of classical bits.

  • program_body – List of operation opcodes.

  • measure_qubits – List of measurement tuples (qubit, cbit).

parse(raw_qasm)[source]#

Parse an OpenQASM 2.0 string and populate internal state.

Parameters:

raw_qasm – OpenQASM 2.0 string to parse.

to_circuit()[source]#

The function coverts OpenQASM string into uniqc.Circuit object.

In the initilization phase, we need to notice that OriginIR-based quantum circuit doe not need to specify how many qregs and cregs used.

Parameters: - qasm_str: The quantum circuit of intersts in the OpenQASM format.

Returns: - origin_qcirc: The quantum circuit of intersts in the OriginIR format.

Return type:

Circuit

to_originir()[source]#

Convert parsed OpenQASM data to OriginIR string.

Returns:

OriginIR string representation, including any MEASURE statements collected from the QASM source.

Return type:

str