Skip to content

Qubit allocation

qalloc_at

qalloc_at(
    positions: IList[PositionIndex, N],
) -> ilist.IList[Qubit, N]

Allocate logical qubits at optional linear logical positions.

An integer position pins the qubit to zone 0 at word 2 * position; None allocates an unpinned qubit for the layout heuristic to place. The input must be statically known, and the calling kernel must set aggressive_unroll=True, so the map can lower into individual allocations.

Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/logical/stdlib/qubit_allocation.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@kernel(aggressive_unroll=True, verify=False)
def qalloc_at(
    positions: ilist.IList[PositionIndex, N],
) -> ilist.IList[Qubit, N]:
    """Allocate logical qubits at optional linear logical positions.

    An integer ``position`` pins the qubit to zone 0 at word ``2 * position``;
    ``None`` allocates an unpinned qubit for the layout heuristic to place.
    The input must be statically known, and the calling kernel must set
    ``aggressive_unroll=True``, so the map can lower into individual
    allocations.
    """

    def position_to_new_at(
        position: PositionIndex,
    ) -> Qubit:
        if position is None:
            q = qubit.new()
        else:
            q = new_at(0, position * 2, 0)
        return q

    return ilist.map(position_to_new_at, positions)