Layouts

Layout Utils

Header: fiction/layouts/layout_utils.hpp

template<typename Lyt>
uint8_t fiction::layouts::num_adjacent_coordinates(const Lyt &lyt, const fiction::layouts::layout_base::coordinate &c) noexcept

Returns the number of adjacent coordinates of a given one. This is not a constant value because c could be located at a layout border.

Template Parameters:

Lyt – Layout type.

Parameters:
  • lyt – Layout.

  • c – Coordinate whose number of adjacencies are required.

Returns:

Number of c’s adjacent coordinates.

template<uint16_t GateSizeX, uint16_t GateSizeY, typename GateLyt, typename Coordinate>
Coordinate fiction::layouts::relative_to_absolute_cell_position(const GateLyt &gate_lyt, const fiction::layouts::layout_base::coordinate &t, const Coordinate &relative_c)

Converts a relative cell position within a tile to an absolute cell position within a layout. To compute the absolute position, the layout topology is taken into account.

Template Parameters:
  • GateSizeX – Horizontal tile size.

  • GateSizeY – Vertical tile size.

  • GateLyt – Gate-level layout type.

  • Coordinate – Cell coordinate type, e.g., layout_base::coordinate. Hexagonal tiles can yield negative positions.

Parameters:
  • gate_lyt – The gate-level layout whose tiles are to be considered.

  • t – Tile within gate_lyt.

  • relative_c – Relative cell position within t.

Throws:
  • std::invalid_argument – If the relative cell lies outside the tile.

  • std::overflow_error – If the absolute cell is outside the signed 32-bit coordinate range.

Returns:

Absolute cell position in a layout.

template<typename Lyt>
std::optional<fiction::layouts::layout_base::coordinate> fiction::layouts::port_direction_to_coordinate(const Lyt &lyt, const fiction::layouts::layout_base::coordinate &c, const fcn::port_direction &port) noexcept

Port directions address coordinates relative to each other by specifying cardinal directions. This function converts such a relative direction to an absolute coordinate when given a layout and a coordinate therein to consider. That is, when presented with, e.g., a NORTH_EAST direction, it will return the coordinate that is to the NORTH_EAST of the given coordinate c in the layout lyt.

Template Parameters:

Lyt – Coordinate layout type.

Parameters:
  • lyt – Coordinate layout.

  • c – Coordinate to consider.

  • port – Port direction.

Returns:

Adjacent coordinate, or no coordinate when the neighbor lies outside the layout.

template<typename Lyt>
Lyt fiction::layouts::normalize_layout_coordinates(const Lyt &lyt)

Returns a copy of the given cell grid layout whose cells are shifted towards the origin, so that the smallest occupied x- and y-coordinates become 0. Cell types, names, and, where the layout has them, cell modes move with their cells. Layer coordinates, the layout name, and the clocking stay unchanged. The extent preserves trailing padding and encloses translated x/y coordinates and occupied nonnegative layers.

Template Parameters:

Lyt – Cell grid layout type, e.g., qca::layout, mol_qca::layout, or inml::layout.

Parameters:

lyt – The layout to normalize.

Throws:

std::invalid_argument – If the normalized extent exceeds the signed coordinate domain.

Returns:

Normalized copy of lyt.

template<typename CoordinateType>
CoordinateType fiction::layouts::random_coordinate(const CoordinateType corner1, const CoordinateType corner2) noexcept

Generates a random coordinate with each axis inside the inclusive region spanned by two coordinates.

Template Parameters:

CoordinateType – Coordinate type to generate.

Parameters:
  • corner1 – One corner of the region.

  • corner2 – Opposite corner of the region; axes may appear in either order.

Returns:

Random coordinate between the corresponding corner axes.

num_adjacent_coordinates(lyt: cartesian_gate_layout, c: coordinate | tuple[int, int] | tuple[int, int, int]) → int
num_adjacent_coordinates(lyt: mnt.pyfiction.layouts.shifted_cartesian_gate_layout, c: coordinate | tuple[int, int] | tuple[int, int, int]) → int
num_adjacent_coordinates(lyt: hexagonal_gate_layout, c: coordinate | tuple[int, int] | tuple[int, int, int]) → int

Returns the number of adjacent coordinates of a given one. This is not a constant value because c could be located at a layout border.

Parameters:
  • lyt – Layout.

  • c – Coordinate whose number of adjacencies are required.

Template Args:

Lyt – Layout type.

Returns:

Number of c’s adjacent coordinates.

normalize_layout_coordinates(lyt: qca_layout) → qca_layout
normalize_layout_coordinates(lyt: mol_qca_layout) → mol_qca_layout
normalize_layout_coordinates(lyt: inml_layout) → inml_layout

Returns a copy of the given cell grid layout whose cells are shifted towards the origin, so that the smallest occupied x- and y-coordinates become 0. Cell types, names, and, where the layout has them, cell modes move with their cells. Layer coordinates, the layout name, and the clocking stay unchanged. The extent preserves trailing padding and encloses translated x/y coordinates and occupied nonnegative layers.

Parameters:

lyt – The layout to normalize.

Template Args:

Lyt – Cell grid layout type, e.g., qca::layout, mol_qca::layout, or inml::layout.

Returns:

Normalized copy of lyt.

Raises:

std::invalid_argument – If the normalized extent exceeds the signed coordinate domain.

random_coordinate(corner1: coordinate | tuple[int, int] | tuple[int, int, int], corner2: coordinate | tuple[int, int] | tuple[int, int, int]) → coordinate

Generates a random coordinate with each axis inside the inclusive region spanned by two coordinates.

Parameters:
  • corner1 – One corner of the region.

  • corner2 – Opposite corner of the region; axes may appear in either order.

Template Args:

CoordinateType – Coordinate type to generate.

Returns:

Random coordinate between the corresponding corner axes.