quairkit.core.operator.transpile¶
Source file for transpilation between OperatorInfo and [OpenQASM 2.0](https://github.com/openqasm/openqasm/tree/OpenQASM2.x)
- class quairkit.core.operator.transpile.OpenQASM2Transpiler¶
A class to handle the translation between OperatorInfo and OpenQASM 2.0 format.
This class provides methods to convert operator information into OpenQASM 2.0 format and to handle equivalent translations for specific operators.
- static format_qasm(name, system_idx, param)¶
Translate OperatorInfo to OpenQASM-like format.
- static transpile(name, system_idx, param)¶
Translate OperatorInfo to OpenQASM 2.0 format.
- static from_qasm2(source)¶
Parse a complete OpenQASM 2.0 program into a list of (name, system_idx, param).
- Aggregation rule:
Consecutive gates are combined into a single tuple only if - they have the same gate name, and - they are placeable in parallel, i.e., they act on disjoint sets of qubits.
- Special handling:
measure q -> c: returned as (‘measure’, [[list_of_all_q_qubits]], None) (not split).
reset q: returned as (‘reset’, [[list_of_all_q_qubits]], None) (not split).
Both measure and reset still follow the parallel-combine rule across consecutive statements.
- Parameters:¶
- source : str¶
Full OpenQASM 2.0 text (statements separated by ‘n’ and terminated by ‘;’).
- Returns:¶
name: internal operator name (note: u1->p, cu1->cp as per __general_case)
system_idx: each inner list are the qubit indices for one gate instance
param: tensor of shape [len(system_idx), 1, num_params] or None for non-parametric gates
- Return type:¶
A list of tuples (name, system_idx, param), where
- Raises:¶
ValueError – if the program header is missing or does not include “qelib1.inc”, or malformed ops.
NotImplementedError – if the program contains gate/opaque definitions or classically conditioned “if”.