Block#

class tqec.compile.blocks.Block(layer_sequence, trimmed_spatial_borders=frozenset({}))[source]#

Bases: SequencedLayers

Encodes the implementation of a block.

This data structure is voluntarily very generic. It represents blocks as a sequence of layers that can be instances of either BaseLayer or BaseComposedLayer.

Depending on the stored layers, this class can be used to represent regular cubes (i.e. scaling in the 3 dimensions with k) as well as pipes (i.e. scaling in only 2 dimension with k).

Composed layer implementing a fixed sequence of layers.

This composed layer sequentially applies layers from a fixed sequence.

Parameters:
  • layer_sequence (Sequence[BaseLayer | BaseComposedLayer]) – non-empty sequence of layers to apply one after the other. All the layers in this sequence should have exactly the same spatial footprint.

  • trimmed_spatial_borders (frozenset[SpatialBlockBorder]) – all the spatial borders that have been removed from the layer.

Raises:

TQECException – if the provided layer_sequence is empty.

Methods

__init__(layer_sequence[, ...])

Composed layer implementing a fixed sequence of layers.

all_layers(k)

Returns all the base layers represented by the instance.

get_temporal_border(border)

get_temporal_layer_on_border(border)

shape(k)

Returns the 2-dimensional shape of the object for the given k.

timesteps(k)

Returns the number of timesteps needed to implement the object for the provided scaling parameter k.

to_sequenced_layer_with_schedule(schedule)

Splits self into a SequencedLayers instance with the provided schedule.

with_spatial_borders_trimmed(borders)

Returns self with the provided spatial borders removed.

with_temporal_borders_replaced(...)

Returns self with the provided temporal borders replaced.

Attributes

dimensions

Returns the dimensions of self.

is_cube

is_pipe

is_temporal_pipe

layer_sequence

scalable_shape

Returns the 2-dimensional shape of the object as an exact expression that can then be used to compute the shape for any value of k.

scalable_timesteps

Returns the number of timesteps needed to implement the object as an exact expression that can then be used to compute the number of timesteps for any value of k.

schedule

Returns the duration of each of the sequenced layers.

trimmed_spatial_borders

Detailed methods

__init__(layer_sequence, trimmed_spatial_borders=frozenset({}))#

Composed layer implementing a fixed sequence of layers.

This composed layer sequentially applies layers from a fixed sequence.

Parameters:
  • layer_sequence (Sequence[BaseLayer | BaseComposedLayer]) – non-empty sequence of layers to apply one after the other. All the layers in this sequence should have exactly the same spatial footprint.

  • trimmed_spatial_borders (frozenset[SpatialBlockBorder]) – all the spatial borders that have been removed from the layer.

Raises:

TQECException – if the provided layer_sequence is empty.

all_layers(k)#

Returns all the base layers represented by the instance.

Returns:

All the base layers represented by the instance. The returned iterable should have as many entries as self.timesteps(k).

Parameters:

k (int)

Return type:

Iterable[BaseLayer]

get_temporal_border(border)[source]#
Parameters:

border (TemporalBlockBorder)

Return type:

BaseLayer

get_temporal_layer_on_border(border)#
Parameters:

border (TemporalBlockBorder)

Return type:

BaseLayer

shape(k)#

Returns the 2-dimensional shape of the object for the given k.

Parameters:

k (int) – scaling parameter.

Returns:

the 2-dimensional shape of the object for the given k.

Return type:

PhysicalQubitShape2D

timesteps(k)#

Returns the number of timesteps needed to implement the object for the provided scaling parameter k.

Parameters:

k (int) – scaling parameter.

Returns:

the number of timesteps needed to implement the object for the provided scaling parameter k.

Return type:

int

to_sequenced_layer_with_schedule(schedule)#

Splits self into a SequencedLayers instance with the provided schedule.

Parameters:

schedule (tuple[LinearFunction, ...]) – duration of each of the layers in the returned SequencedLayers instance.

Returns:

an instance of SequencedLayers that is equivalent to self (same duration, same layers applied, …) and that has the provided schedule.

Return type:

SequencedLayers

with_spatial_borders_trimmed(borders)[source]#

Returns self with the provided spatial borders removed.

Parameters:

borders (Iterable[SpatialBlockBorder]) – spatial borders to remove.

Returns:

a copy of self with the provided borders removed.

Return type:

Block

with_temporal_borders_replaced(border_replacements)[source]#

Returns self with the provided temporal borders replaced.

Parameters:
  • borders – a mapping from temporal borders to replace to their replacement. A value of None as a replacement means that the border is removed.

  • border_replacements (Mapping[TemporalBlockBorder, BaseLayer | None])

Returns:

a copy of self with the provided borders replaced, or None if replacing the provided borders from self result in an empty temporal footprint.

Return type:

Block | None