QASMTemplate

class QASMTemplate(fragments: tuple[str, ...], slot_indices: tuple[int, ...])[source]

Bases: NamedTuple

Pre-split QASM body for fast parameter substitution.

Instead of scanning a full QASM string with a regex on every parameter binding call, the string is split once at symbol boundaries into fragments and slot_indices. Rendering then reduces to interleaving fragments with looked-up values — no regex needed.

fragments[i] is the literal QASM text between the (i-1)-th and i-th symbol occurrence. slot_indices[i] is the index into the parameter values array for the i-th slot.

Invariant: len(fragments) == len(slot_indices) + 1

Example:

Given QASM body ``"rx(w_0) q[0];\nrz(w_1) q[1];\n"``
and symbols ``("w_0", "w_1")``:

    fragments   = ("rx(", ") q[0];\nrz(", ") q[1];\n")
    slot_indices = (0, 1)

Rendering with values ``("1.5", "2.7")`` produces::

    "rx(" + "1.5" + ") q[0];\nrz(" + "2.7" + ") q[1];\n"
    = "rx(1.5) q[0];\nrz(2.7) q[1];\n"

Create new instance of QASMTemplate(fragments, slot_indices)

Attributes Summary

fragments

Alias for field number 0

slot_indices

Alias for field number 1

Attributes Documentation

fragments: tuple[str, ...]

Alias for field number 0

slot_indices: tuple[int, ...]

Alias for field number 1