Skip to content

Optimize extracting the qasm version #134

@bachase

Description

@bachase

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")

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions