Skip to content

PatchGeometry

Role -> (patch label, qubits) assignment, plus named seam(s).

Reuses the Mapping[str, str]-style role-naming convention already established by patch_labels and patch_labels. The two-patch case (most builders) uses roles "a"/"b" and a single unnamed seam; builders needing more than two patches or more than one seam (e.g. a 3-patch lattice-surgery CNOT) use whatever role names make sense and name each seam.

Examples:

>>> from loqs.core import PatchGeometry
>>> geometry = PatchGeometry(
...     patches={"a": ("L0", ["D0", "D1"]), "b": ("L1", ["D2", "D3"])},
...     seam=["S0"],
...     layout="surf10",
... )
>>> geometry.label("a")
'L0'
>>> geometry.seam
['S0']

PatchGeometry

PatchGeometry(patches: Mapping[str, tuple[str, Sequence[str]]], layout: str, seam: Sequence[str] | None = None, seams: Mapping[str, Sequence[str]] | None = None)

Parameters:

Name Type Description Default
patches Mapping[str, tuple[str, Sequence[str]]]

Role name -> (patch_label, qubits). qubits is each patch's full qubit list (template order, data + ancillas).

required
layout str

One of "surf17", "surf13", "surf10" (all patches must share one layout).

required
seam Sequence[str] | None

The seam qubits, for the common case of exactly one seam. Omit both seam and seams for an operation with no seam at all (e.g. a transversal CNOT or an ancilla-mediated joint parity measurement). Mutually exclusive with seams.

None
seams Mapping[str, Sequence[str]] | None

Name -> seam qubits, for geometries with more than one seam (e.g. {"zz": [...], "xx": [...]} for a 3-patch surgery CNOT). Mutually exclusive with seam. Internally, seam=... is equivalent to seams={"main": ...} -- a PatchGeometry always stores its seams the same way regardless of which constructor argument was used, so seam and subset() work uniformly either way.

None

Attributes

Name Type Value Doc
patch_labels dict[str, str] read-only property Role -> patch label, dropping the qubit lists.
seam list[str] read-only property The seam qubits, when this geometry has exactly one seam.

init_patch_entries

init_patch_entries(patch_type_tag: str) -> list[dict]

"Init Patch <patch_type_tag>" stack entries for every role.

Parameters:

Name Type Description Default
patch_type_tag str

The key a QuantumProgram's patch_types mapping registers the desired QECCode under (e.g. "SURF"), used to resolve the "Init Patch <tag>" stack shorthand.

required

Returns:

Type Description
list[dict]

One {"instruction": ..., "new_patch_label": ..., "qubits": ...} entry per role, in role-insertion order.


label

label(role: str) -> str

The patch label assigned to role.


qubits

qubits(role: str) -> list[str]

The qubit list assigned to role.


subset

subset(roles: Sequence[str], seam: str) -> PatchGeometry

A new, two-role PatchGeometry for a subset of this one's roles.

roles (exactly 2) are remapped to canonical roles "a"/"b" in the order given, and seam names which of this geometry's seams the result carries. This is what a 3-patch, multi-seam geometry (e.g. a surgery CNOT's ctrl/tgt/anc roles and zz/xx seams) uses to derive the two-role geometry each underlying pairwise merge/split builder actually needs.

Parameters:

Name Type Description Default
roles Sequence[str]

Exactly 2 of this geometry's role names, in (a, b) order.

required
seam str

Name of one of this geometry's seams.

required

Returns:

Type Description
PatchGeometry

Roles "a"/"b", one seam, same layout.