bag.layout.routing.grid

This module defines the RoutingGrid class.

Module Contents

Classes

TrackSpec

RoutingGrid

A class that represents the routing grid.

Attributes

SizeType

FillConfigType

OptHalfIntType

bag.layout.routing.grid.SizeType[source]
bag.layout.routing.grid.FillConfigType[source]
bag.layout.routing.grid.OptHalfIntType[source]
class bag.layout.routing.grid.TrackSpec[source]
layer: int[source]
direction: pybag.enum.Orient2D[source]
width: int[source]
space: int[source]
offset: int[source]
class bag.layout.routing.grid.RoutingGrid(tech_info: bag.layout.tech.TechInfo, config_fname: str, copy: Optional[pybag.core.PyRoutingGrid] = None)[source]

Bases: pybag.core.PyRoutingGrid

A class that represents the routing grid.

This class provides various methods to convert between Cartesian coordinates and routing tracks. This class assumes the lower-left coordinate is (0, 0)

the track numbers are at half-track pitch. That is, even track numbers corresponds to physical tracks, and odd track numbers corresponds to middle between two tracks. This convention is chosen so it is easy to locate a via for 2-track wide wires, for example.

Assumptions:

  1. the pitch of all layers evenly divides the largest pitch.

Parameters:
  • tech_info (TechInfo) – the TechInfo instance used to create metals and vias.

  • config_fname (str) – the routing grid configuration file.

  • copy (Optional[PyRoutingGrid]) – copy create a new routing grid that’s the same as the given copy

property tech_info: bag.layout.tech.TechInfo[source]

The TechInfo technology object.

Type:

TechInfo

classmethod get_middle_track(tr1: bag.typing.TrackType, tr2: bag.typing.TrackType, round_up: bool = False) bag.util.math.HalfInt[source]

Get the track between the two given tracks.

is_horizontal(layer_id: int) bool[source]

Returns true if the given layer is horizontal.

get_num_tracks(size: SizeType, layer_id: int) bag.util.math.HalfInt[source]

Returns the number of tracks on the given layer for a block with the given size.

Parameters:
  • size (SizeType) – the block size tuple.

  • layer_id (int) – the layer ID.

Returns:

num_tracks – number of tracks on that given layer.

Return type:

HalfInt

dim_to_num_tracks(layer_id: int, dim: int, round_mode: pybag.enum.RoundMode = RoundMode.NONE) bag.util.math.HalfInt[source]

Returns how many track pitches are in the given dimension.

get_sep_tracks(layer: int, ntr1: int = 1, ntr2: int = 1, same_color: bool = False, half_space: bool = True) bag.util.math.HalfInt[source]

Returns the track separations needed between two adjacent wires.

Parameters:
  • layer (int) – wire layer ID.

  • ntr1 (int) – width (in number of tracks) of the first wire.

  • ntr2 (int) – width (in number of tracks) of the second wire.

  • same_color (bool) – True to assume they have the same color.

  • half_space (bool) – True to allow half-track spacing.

Returns:

sep_index – minimum track index difference of the adjacent wires

Return type:

HalfInt

get_line_end_sep_tracks(layer_dir: pybag.enum.Direction, le_layer: int, le_ntr: int = 1, adj_ntr: int = 1, half_space: bool = True) bag.util.math.HalfInt[source]

Returns the track separations needed to satisfy via extension + line-end constraints.

When you have two separate wires on the same track and need to connect them to adjacent layers, if the adjacent wires are too close, the via extensions could violate line-end spacing constraints. This method computes the minimum track index difference those two wires must have to avoid this error.

Parameters:
  • layer_dir (Direction) – the direction of the specified layer. LOWER if the layer is the bottom layer, UPPER if the layer is the top layer.

  • le_layer (int) – line-end wire layer ID.

  • le_ntr (int) – width (in number of tracks) of the line-end wire.

  • adj_ntr (int) – width (in number of tracks) of the wire on the adjacent layer.

  • half_space (bool) – True to allow half-track spacing.

Returns:

sep_index – minimum track index difference of the adjacent wires

Return type:

HalfInt

get_max_track_width(layer_id: int, num_tracks: int, tot_space: int, half_end_space: bool = False) int[source]

Compute maximum track width and space that satisfies DRC rule.

Given available number of tracks and numbers of tracks needed, returns the maximum possible track width.

Parameters:
  • layer_id (int) – the track layer ID.

  • num_tracks (int) – number of tracks to draw.

  • tot_space (int) – available number of tracks.

  • half_end_space (bool) – True if end spaces can be half of minimum spacing. This is true if you’re these tracks will be repeated, or there are no adjacent tracks.

Returns:

tr_w – track width.

Return type:

int

static get_evenly_spaced_tracks(num_tracks: int, tot_space: int, track_width: int, half_end_space: bool = False) List[bag.util.math.HalfInt][source]

Evenly space given number of tracks in the available space.

Currently this method may return half-integer tracks.

Parameters:
  • num_tracks (int) – number of tracks to draw.

  • tot_space (int) – avilable number of tracks.

  • track_width (int) – track width in number of tracks.

  • half_end_space (bool) – True if end spaces can be half of minimum spacing. This is true if you’re these tracks will be repeated, or there are no adjacent tracks.

Returns:

idx_list – list of track indices. 0 is the left-most track.

Return type:

List[HalfInt]

get_fill_size(top_layer: int, fill_config: FillConfigType, *, include_private: bool = False, half_blk_x: bool = True, half_blk_y: bool = True) Tuple[int, int][source]

Returns unit block size given the top routing layer and power fill configuration.

Parameters:
  • top_layer (int) – the top layer ID.

  • fill_config (Dict[int, Tuple[int, int, int, int]]) – the fill configuration dictionary.

  • include_private (bool) – True to include private layers in block size calculation.

  • half_blk_x (bool) – True to allow half-block widths.

  • half_blk_y (bool) – True to allow half-block heights.

Returns:

  • block_width (int) – the block width in resolution units.

  • block_height (int) – the block height in resolution units.

get_size_tuple(layer_id: int, width: int, height: int, *, round_up: bool = False, half_blk_x: bool = False, half_blk_y: bool = False) SizeType[source]

Compute the size tuple corresponding to the given width and height from block pitch.

Parameters:
  • layer_id (int) – the layer ID.

  • width (int) – width of the block, in resolution units.

  • height (int) – height of the block, in resolution units.

  • round_up (bool) – True to round up instead of raising an error if the given width and height are not on pitch.

  • half_blk_x (bool) – True to allow half-block widths.

  • half_blk_y (bool) – True to allow half-block heights.

Returns:

size – the size tuple. the first element is the top layer ID, second element is the width in number of vertical tracks, and third element is the height in number of horizontal tracks.

Return type:

SizeType

get_size_dimension(size: SizeType) Tuple[int, int][source]

Compute width and height from given size.

Parameters:

size (SizeType) – size of a block.

Returns:

  • width (int) – the width in resolution units.

  • height (int) – the height in resolution units.

convert_size(size: SizeType, new_top_layer: int) SizeType[source]

Convert the given size to a new top layer.

Parameters:
  • size (SizeType) – size of a block.

  • new_top_layer (int) – the new top level layer ID.

Returns:

new_size – the new size tuple.

Return type:

SizeType

get_wire_bounds(layer_id: int, tr_idx: bag.typing.TrackType, width: int = 1) Tuple[int, int][source]

Calculate the wire bounds coordinate.

Parameters:
  • layer_id (int) – the layer ID.

  • tr_idx (TrackType) – the center track index.

  • width (int) – width of wire in number of tracks.

Returns:

  • lower (int) – the lower bound coordinate perpendicular to wire direction.

  • upper (int) – the upper bound coordinate perpendicular to wire direction.

coord_to_track(layer_id: int, coord: int, mode: pybag.enum.RoundMode = RoundMode.NONE, even: bool = False) bag.util.math.HalfInt[source]

Convert given coordinate to track number.

Parameters:
  • layer_id (int) – the layer number.

  • coord (int) – the coordinate perpendicular to the track direction.

  • mode (RoundMode) –

    the rounding mode.

    If mode == NEAREST, return the nearest track (default).

    If mode == LESS_EQ, return the nearest track with coordinate less than or equal to coord.

    If mode == LESS, return the nearest track with coordinate less than coord.

    If mode == GREATER, return the nearest track with coordinate greater than or equal to coord.

    If mode == GREATER_EQ, return the nearest track with coordinate greater than coord.

    If mode == NONE, raise error if coordinate is not on track.

  • even (bool) – True to round coordinate to integer tracks.

Returns:

track – the track number

Return type:

HalfInt

coord_to_fill_track(layer_id: int, coord: int, fill_config: Dict[int, Any], mode: pybag.enum.RoundMode = RoundMode.NEAREST) bag.util.math.HalfInt[source]

Returns the fill track number closest to the given coordinate.

Parameters:
  • layer_id (int) – the layer number.

  • coord (int) – the coordinate perpendicular to the track direction.

  • fill_config (Dict[int, Any]) – the fill configuration dictionary.

  • mode (RoundMode) –

    the rounding mode.

    If mode == NEAREST, return the nearest track (default).

    If mode == LESS_EQ, return the nearest track with coordinate less than or equal to coord.

    If mode == LESS, return the nearest track with coordinate less than coord.

    If mode == GREATER, return the nearest track with coordinate greater than or equal to coord.

    If mode == GREATER_EQ, return the nearest track with coordinate greater than coord.

    If mode == NONE, raise error if coordinate is not on track.

Returns:

track – the track number

Return type:

HalfInt

coord_to_nearest_track(layer_id: int, coord: int, *, half_track: bool = True, mode: Union[pybag.enum.RoundMode, int] = RoundMode.NEAREST) bag.util.math.HalfInt[source]

Returns the track number closest to the given coordinate.

Parameters:
  • layer_id (int) – the layer number.

  • coord (int) – the coordinate perpendicular to the track direction.

  • half_track (bool) – if True, allow half integer track numbers.

  • mode (Union[RoundMode, int]) –

    the rounding mode.

    If mode == NEAREST, return the nearest track (default).

    If mode == LESS_EQ, return the nearest track with coordinate less than or equal to coord.

    If mode == LESS, return the nearest track with coordinate less than coord.

    If mode == GREATER, return the nearest track with coordinate greater than or equal to coord.

    If mode == GREATER_EQ, return the nearest track with coordinate greater than coord.

Returns:

track – the track number

Return type:

HalfInt

find_next_track(layer_id: int, coord: int, *, tr_width: int = 1, half_track: bool = True, mode: Union[pybag.enum.RoundMode, int] = RoundMode.GREATER_EQ) bag.util.math.HalfInt[source]

Find the track such that its edges are on the same side w.r.t. the given coordinate.

Parameters:
  • layer_id (int) – the layer number.

  • coord (int) – the coordinate perpendicular to the track direction.

  • tr_width (int) – the track width, in number of tracks.

  • half_track (bool) – True to allow half integer track center numbers.

  • mode (Union[RoundMode, int]) –

    the rounding mode. NEAREST and NONE are not supported.

    If mode == LESS_EQ, return the track with both edges less than or equal to coord.

    If mode == LESS, return the nearest track with both edges less than coord.

    If mode == GREATER, return the nearest track with both edges greater than coord.

    If mode == GREATER_EQ, return the nearest track with both edges greater than or equal to coord.

Returns:

tr_idx – the center track index.

Return type:

HalfInt

transform_track(layer_id: int, track_idx: bag.typing.TrackType, xform: pybag.core.Transform) bag.util.math.HalfInt[source]

Transform the given track index.

Parameters:
  • layer_id (int) – the layer ID.

  • track_idx (TrackType) – the track index.

  • xform (Transform) – the transformation object.

Returns:

tidx – the transformed track index.

Return type:

HalfInt

get_track_index_range(layer_id: int, lower: int, upper: int, *, num_space: bag.typing.TrackType = 0, edge_margin: int = 0, half_track: bool = True) Tuple[OptHalfIntType, OptHalfIntType][source]

Returns the first and last track index strictly in the given range.

Parameters:
  • layer_id (int) – the layer ID.

  • lower (int) – the lower coordinate.

  • upper (int) – the upper coordinate.

  • num_space (TrackType) – number of space tracks to the tracks right outside of the given range.

  • edge_margin (int) – minimum space from outer tracks to given range.

  • half_track (bool) – True to allow half-integer tracks.

Returns:

  • start_track (OptHalfIntType) – the first track index. None if no solution.

  • end_track (OptHalfIntType) – the last track index. None if no solution.

get_overlap_tracks(layer_id: int, lower: int, upper: int, half_track: bool = True) Tuple[OptHalfIntType, OptHalfIntType][source]

Returns the first and last track index that overlaps with the given range.

Parameters:
  • layer_id (int) – the layer ID.

  • lower (int) – the lower coordinate.

  • upper (int) – the upper coordinate.

  • half_track (bool) – True to allow half-integer tracks.

Returns:

  • start_track (OptHalfIntType) – the first track index. None if no solution.

  • end_track (OptHalfIntType) – the last track index. None if no solution.

track_to_coord(layer_id: int, track_idx: bag.typing.TrackType) int[source]

Convert given track number to coordinate.

Parameters:
  • layer_id (int) – the layer number.

  • track_idx (TrackType) – the track number.

Returns:

coord – the coordinate perpendicular to track direction.

Return type:

int

interval_to_track(layer_id: int, intv: Tuple[int, int]) Tuple[bag.util.math.HalfInt, int][source]

Convert given coordinates to track number and width.

Parameters:
  • layer_id (int) – the layer number.

  • intv (Tuple[int, int]) – lower and upper coordinates perpendicular to the track direction.

Returns:

  • track (HalfInt) – the track number

  • width (int) – the track width, in number of tracks.

get_copy_with(top_ignore_lay: Optional[int] = None, top_private_lay: Optional[int] = None, tr_specs: Optional[List[TrackSpec]] = None) RoutingGrid[source]