uniqc.compile.originir.originir_base_parser module

OriginIR base parser module.

This module provides the base parser for OriginIR quantum circuit representation, including parsing QINIT, CREG statements and quantum operations.

OriginIR-ext supports named quantum/classical registers. QINIT and CREG accept either the classic bare-integer form (QINIT 6QINIT q[6], CREG 6CREG c[6]) or one or more named-register declarations, written either as multiple lines or as a single comma-separated line (QINIT q[6], q1[6]). Registers are laid into a single flat physical index space in declaration order (so QINIT q[6] followed by QINIT q1[6] is equivalent to QINIT 12 with q → 0–5 and q1 → 6–11). Register-qualified references (q1[0], c1[2]) are resolved to physical indices at parse time; the parser (and to_extended_originir) always emit a flat single QINIT/CREG header with physical q[i]/c[i] operands — register names are not preserved on export.

DEF subroutines reuse the named-register declaration syntax for their formal signature (DEF name(q[2], anc[1]) (theta1, theta2)) with an optional trailing list of scalar parameter names. Calls (name(a[3], a[5]) (0.5)) are expanded inline into the flat program at parse time.

Key exports:

OriginIR_BaseParser: Base parser class for OriginIR circuits.

class uniqc.compile.originir.originir_base_parser.OriginIR_BaseParser[source]

Bases: object

Parser for OriginIR quantum circuit representation.

Variables:
  • n_qubit – Total number of qubits (sum over all quantum registers).

  • n_cbit – Total number of classical bits (sum over all classical registers).

  • program_body – List of operation opcodes (flat, register-resolved).

  • raw_originir – Raw OriginIR string.

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

  • qram_declarations – Mapping of QRAM name -> (addr_size, data_size).

  • qreg_map – Mapping of quantum register name -> (base_index, size).

  • creg_map – Mapping of classical register name -> (base_index, size).

  • gate_definitions – Mapping of DEF name -> _DefInfo.

property originir

OriginIR string representation (alias for to_extended_originir).

Returns:

Extended OriginIR string.

Return type:

str

parse(originir_str)[source]

Parse an OriginIR string and populate internal state.

Parameters:

originir_str – OriginIR string to parse.

to_circuit()[source]

The function coverts OriginIR string into uniqc.Circuit object.

Returns:

uniqc.Circuit object.

to_extended_originir()[source]

Convert parsed data back to extended OriginIR string.

The output is always flat: a single QINIT/CREG header with physical q[i]/c[i] operands (named registers and DEF blocks are resolved/inlined at parse time).

Returns:

Extended OriginIR string representation.

Return type:

str

to_qasm()[source]

The function coverts OriginIR string into OpenQASM string.

Returns:

OpenQASM string.