PatchLayout¶
Bases: MutableMapping[str, QECCodePatch], Displayable
A collection of QECCodePatch objects, plus relational data.
This is a dict-like object where the keys are patch labels (literally,
as any patch_label usage in an Instruction apply function
refers to these keys) and the values are QECCodePatch objects
-- a strict superset of the old PatchDict's API. It also tracks
PatchRelation objects, keyed by the sorted tuple of their
participants' patch labels (order-independent lookup; frozenset
keys were considered but are not supported by LoQS's serialization
framework, so a canonical sorted tuple is used instead).
Unlike many other LoQS objects, this is a mutable object to make it easy
to manipulate patches. Users should be careful to first use copy
to avoid messing up previous Frame objects (or use
expire() properly).
Examples:
>>> from loqs.core.recordables.patchlayout import PatchLayout
>>> layout = PatchLayout()
>>> len(layout)
0
PatchLayout ¶
PatchLayout(patches: PatchLayoutLike = None) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patches
|
PatchLayoutLike
|
See |
None
|
Attributes¶
| Name | Type | Value | Doc |
|---|---|---|---|
all_qubit_labels |
list[str | int] |
read-only property | All qubits managed by patches in this PatchLayout. |
patches |
dict[str, QECCodePatch] |
unset | Underlying dict of patch labels and QECCodePatch objects. |
relations |
dict[tuple[str, ...], PatchRelation] |
unset | PatchRelation objects, keyed by the sorted tuple of their participants' patch labels. Prefer get_relation()/ set_relation() over touching this directly. |
clear¶
Inherited method from MutableMapping.
copy ¶
copy() -> PatchLayout
Return a copy of this PatchLayout.
Returns:
| Type | Description |
|---|---|
PatchLayout
|
The copied |
decode¶
Inherited static method from Serializable.decode().
display¶
Inherited method from Displayable.display().
dump¶
Inherited method from Serializable.dump().
encode¶
Inherited static method from Serializable.encode().
get¶
Inherited method from Mapping.
get_relation ¶
get_relation(*labels: str) -> PatchRelation | None
Look up a PatchRelation by its participants' labels.
Order of labels does not matter. Warns (does not raise) if any
label isn't a current key of this PatchLayout -- with
patch removal auto-dropping stale relations, reaching this should
only happen from a typo or a reference to an already-removed
patch, not a relation that simply doesn't exist yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*labels
|
str
|
The participant patch labels naming the relation. |
()
|
Returns:
| Type | Description |
|---|---|
PatchRelation | None
|
The matching relation, or |
Examples:
>>> from loqs.core import QECCode
>>> from loqs.core.recordables.patchlayout import PatchLayout, PatchRelation
>>> code = QECCode(instructions={}, template_qubits=["q0"], template_data_qubits=["q0"])
>>> layout = PatchLayout({"L0": code.create_patch(["Q0"]), "L1": code.create_patch(["Q1"])})
>>> layout.get_relation("L0", "L1") is None
True
>>> layout.set_relation(PatchRelation({"a": "L0", "b": "L1"}, data={"m": 1}))
>>> layout.get_relation("L1", "L0").data["m"]
1
items¶
Inherited method from Mapping.
keys¶
Inherited method from Mapping.
load¶
Inherited class method from Serializable.load().
pop¶
Inherited method from MutableMapping.
popitem¶
Inherited method from MutableMapping.
read¶
Inherited class method from Serializable.read().
serialize_function¶
Inherited static method from Serializable.serialize_function().
set_relation ¶
set_relation(relation: PatchRelation) -> None
Register a PatchRelation, keyed by its own participants.
Overwrites any existing relation for the same participant set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relation
|
PatchRelation
|
The |
required |
setdefault¶
Inherited method from MutableMapping.
update¶
Inherited method from MutableMapping.
values¶
Inherited method from Mapping.
write¶
Inherited method from Serializable.write().