This is already noted as a todo, but based on the QASM specifications, it should be possible to read until the first non-comment line to determine the QASM versions (if one is specified).
|
# TODO: optimize this to just check the start of the program for version |
|
parsed_program = parse(qasm) |
For large qasm files, parsing the entire file is a substantial overhead. This came up in benchmarking ucc for this circuit. ucc uses qbraid to translate circuits between formats.
For this example, profiling shows of 2m3s script runtime, 2m2s are effectively spent extracting the version, and actually takes two passes, first when checking the input format and again when determining the best path to conversion. It ultimately dispatches to qiskit's native parser for qasm, which runs in under 1 second (rust based?).
from qbraid.transpiler import transpile
# download https://raw.githubusercontent.com/unitaryfund/ucc/refs/heads/main/benchmarks/qasm_circuits/qasm2/benchpress/qv_N100_12345_basis_rz_rx_ry_cx.qasm
qasm = open(
"qv_N100_12345_basis_rz_rx_ry_cx.qasm",
"r",
).read()
transpile(qasm, "qiskit")
This is already noted as a todo, but based on the QASM specifications, it should be possible to read until the first non-comment line to determine the QASM versions (if one is specified).
pyqasm/src/pyqasm/analyzer.py
Lines 227 to 228 in 0e1cd9f
For large qasm files, parsing the entire file is a substantial overhead. This came up in benchmarking
uccfor this circuit.uccusesqbraidto translate circuits between formats.For this example, profiling shows of 2m3s script runtime, 2m2s are effectively spent extracting the version, and actually takes two passes, first when checking the input format and again when determining the best path to conversion. It ultimately dispatches to qiskit's native parser for qasm, which runs in under 1 second (rust based?).