LayoutTemplate#
- class tqec.templates.LayoutTemplate(element_layout, default_increments=None)[source]#
Bases:
Template
A template representing a layout of other templates.
Each element template in the layout is placed at a specific position in the 2D grid.
Note
The provided template positions have only one restriction: two templates should not be at the same position. In particular, this class does not require that the provided template are spatially connected or entirely cover a rectangular portion of the 2 spatial dimensions.
- Parameters:
element_layout (dict[BlockPosition2D, RectangularTemplate]) – a dictionary with the position of the element templates in the layout as keys and the templates as values.
default_increments (Shift2D | None) – default increments between two plaquettes. Defaults to
Displacement(2, 2)
whenNone
.
Methods
__init__
(element_layout[, default_increments])A template representing a layout of other templates.
Return the uniform shape of the element templates.
Get the default increments of the template.
Get one index map for each of the templates in the layout.
get_spatially_distinct_subtemplates
(k[, ...])Returns a representation of all the distinct sub-templates of the provided manhattan radius.
instantiate
(k[, plaquette_indices])Generate the numpy array representing the template.
Coordinates of the top-left entry origin.
shape
(k)Returns the current template shape.
Attributes
expected_plaquettes_number
Returns the number of plaquettes expected from the instantiate method.
scalable_shape
Returns a scalable version of the template shape.
Detailed methods
- __init__(element_layout, default_increments=None)[source]#
A template representing a layout of other templates.
Each element template in the layout is placed at a specific position in the 2D grid.
Note
The provided template positions have only one restriction: two templates should not be at the same position. In particular, this class does not require that the provided template are spatially connected or entirely cover a rectangular portion of the 2 spatial dimensions.
- Parameters:
element_layout (dict[BlockPosition2D, RectangularTemplate]) – a dictionary with the position of the element templates in the layout as keys and the templates as values.
default_increments (Shift2D | None) – default increments between two plaquettes. Defaults to
Displacement(2, 2)
whenNone
.
- Return type:
None
- element_shape(k)[source]#
Return the uniform shape of the element templates.
- Parameters:
k (int)
- Return type:
- get_increments()#
Get the default increments of the template.
- Returns:
a displacement of the default increments in the x and y directions.
- Return type:
- get_indices_map_for_instantiation(instantiate_indices=None)[source]#
Get one index map for each of the templates in the layout.
This method is used internally by
LayoutTemplate.instantiate()
and can be used externally to get a map from the instantiation indices used by each of the individualTemplate
instances stored inself
to the global instantiation index used.- Parameters:
instantiate_indices (Sequence[int] | None) – global indices used to instantiate
self
. Have the same meaning and defaults as theplaquette_indices
parameter inLayoutTemplate.instantiate()
. Defaults to None.- Returns:
a map from positions to instantiation index maps. Each instantiation index map is a bijection from the template instantiation indices (going from
1
totemplate.expected_plaquettes_number
) to the global indices that are used inLayoutTemplate.instantiate()
(going fromN
toN + template.expected_plaquettes_number - 1
whereN
depends on the otherTemplate
instances managed byself
).- Return type:
dict[BlockPosition2D, dict[int, int]]
- get_spatially_distinct_subtemplates(k, manhattan_radius=1, avoid_zero_plaquettes=True)#
Returns a representation of all the distinct sub-templates of the provided manhattan radius.
Note
This method will likely be inefficient for large templates (i.e., large values of k) or for large Manhattan radiuses, both in terms of memory used and computation time. Subclasses are invited to reimplement that method using a specialized algorithm (or hard-coded values) to speed things up.
- Parameters:
k (int) – scaling parameter used to instantiate the template.
manhattan_radius (int) – radius of the considered ball using the Manhattan distance. Only squares with sides of
2*manhattan_radius+1
plaquettes will be considered.avoid_zero_plaquettes (bool) –
True
if sub-templates with an empty plaquette (i.e., 0 value in the instantiation of theTemplate
instance) at its center should be ignored. Default toTrue
.
- Returns:
a representation of all the sub-templates found.
- Return type:
UniqueSubTemplates
- instantiate(k, plaquette_indices=None)[source]#
Generate the numpy array representing the template.
- Parameters:
k (int) – scaling parameter used to instantiate the template.
plaquette_indices (Sequence[int] | None) – the plaquette indices that will be forwarded to the underlying Template instance’s instantiate method. Defaults to range(1, self.expected_plaquettes_number + 1) if None.
- Returns:
a numpy array with the given plaquette indices arranged according to the underlying shape of the template.
- Return type:
ndarray[Any, dtype[int64]]
- instantiation_origin(k)[source]#
Coordinates of the top-left entry origin.
This property returns the coordinates of the origin of the plaquette (
origin
) that corresponds to the top-left entry of the array returned byinstantiate()
.Note
the returned coordinates are in plaquette coordinates. That means that, if you want to get the coordinates of the top-left plaquette origin (which is a qubit), you should multiply the coordinates returned by this method by the tiling increments.
- Parameters:
k (int) – scaling parameter used to instantiate the template.
- Returns:
the coordinates of the origin of the plaquette (
origin
) that corresponds to the top-left entry of the array returned byinstantiate()
.- Return type: