Plaquettes#
- class tqec.plaquette.Plaquettes(collection)[source]#
Bases:
objectRepresent a collection of plaquettes that might be applied to a
Templateinstance.The goal of this class is to abstract away how a “collection of plaquettes” is represented and to provide a unique interface in order to retrieve plaquettes when building a quantum circuit from a template and plaquettes.
It also checks that the represented collection is valid, which means that it does not include any plaquette associated with index 0 (that is internally and conventionally reserved for the empty plaquette).
Methods
__init__(collection)from_dict(data[, plaquettes])Return a collection of plaquettes from its dictionary representation.
items()Return an iterable over each
Plaquetteand its associated index inself.map_indices(callable)Return a new
Plaquettesinstance with updated plaquette indices.to_dict([plaquettes_to_indices])Return a dictionary representation of the plaquettes.
Return a dictionary with each plaquette name as value.
with_updated_plaquettes(plaquettes_to_update)Return a new
Plaquettesinstance with the updated plaquettes.without_plaquettes(indices)Remove the plaquettes at the provided
indicesfrom a copy ofself.Attributes
collectionDetailed methods
- Parameters:
collection (FrozenDefaultDict[int, Plaquette])
- __init__(collection)#
- Parameters:
collection (FrozenDefaultDict[int, Plaquette])
- Return type:
None
- static from_dict(data, plaquettes=None)[source]#
Return a collection of plaquettes from its dictionary representation.
- Parameters:
data (dict[str, Any]) – dictionary with the keys
plaquettesanddefault.plaquettes (Sequence[Plaquette] | None) – list of
Plaquetteinstances to use to build thePlaquettesinstances. Each plaquette is represented by its index in the list of unique plaquettes to save space.
- Returns:
a new instance of
Plaquetteswith the providedplaquettesanddefault.- Return type:
- items()[source]#
Return an iterable over each
Plaquetteand its associated index inself.- Return type:
Iterable[tuple[int, Plaquette]]
- map_indices(callable)[source]#
Return a new
Plaquettesinstance with updated plaquette indices.- Parameters:
callable (Callable[[int], int])
- Return type:
- to_dict(plaquettes_to_indices=None)[source]#
Return a dictionary representation of the plaquettes.
- Parameters:
plaquettes_to_indices (dict[Plaquette, int] | None) – a dictionary mapping plaquettes to their indices. If provided, a plaquette will be represented by its index
- Return type:
dict[str, Any]
- to_name_dict()[source]#
Return a dictionary with each plaquette name as value.
- Return type:
dict[int | Literal[‘default’], str]
- with_updated_plaquettes(plaquettes_to_update)[source]#
Return a new
Plaquettesinstance with the updated plaquettes.- Parameters:
plaquettes_to_update (Mapping[int, Plaquette]) – a mapping from plaquette indices to
Plaquetteinstances. Each entry will replace an existing (or create a new) entry in a copy ofself.- Returns:
a new
Plaquettesinstance with plaquettes fromselfandplaquettes_to_update. If an index is present in bothselfandplaquettes_to_update,plaquettes_to_updatetake precedence.- Return type: