bag.layout.routing.base

This module provides basic routing classes.

Module Contents

Classes

TrackID

A class that represents locations of track(s) on the routing grid.

WireArray

An array of wires on the routing grid.

Port

A layout port.

TrackManager

A class that makes it easy to compute track locations.

Attributes

WDictType

SpDictType

bag.layout.routing.base.WDictType[source]
bag.layout.routing.base.SpDictType[source]
class bag.layout.routing.base.TrackID(layer_id: int, track_idx: bag.typing.TrackType, width: int = 1, num: int = 1, pitch: bag.typing.TrackType = 0, grid: Optional[bag.layout.routing.grid.RoutingGrid] = None)[source]

Bases: pybag.core.PyTrackID

A class that represents locations of track(s) on the routing grid.

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

  • track_idx (TrackType) – the smallest middle track index in the array. Multiples of 0.5

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

  • num (int) – number of tracks in this array.

  • pitch (TrackType) – pitch between adjacent tracks, in number of track pitches.

  • grid (Optional[RoutingGrid]) – the routing grid associated with this TrackID object.

property base_index: bag.util.math.HalfInt[source]

the base index.

Type:

HalfInt

property pitch: bag.util.math.HalfInt[source]

the track pitch.

Type:

HalfInt

property grid: Optional[bag.layout.routing.grid.RoutingGrid][source]

the routing grid of this TrackID object.

Type:

Optional[RoutingGrid]

__iter__() Iterator[bag.util.math.HalfInt][source]

Iterate over all middle track indices in this TrackID.

__getitem__(idx: Union[int, slice]) TrackID[source]
transform(xform: pybag.core.Transform) TrackID[source]

Transform this TrackID.

get_transform(xform: pybag.core.Transform) TrackID[source]

returns a transformed TrackID.

copy_with(grid: bag.layout.routing.grid.RoutingGrid) TrackID[source]
class bag.layout.routing.base.WireArray(track_id: TrackID, lower: int, upper: int)[source]

An array of wires on the routing grid.

Parameters:
  • track_id (TrackID) – TrackArray representing the track locations of this wire array.

  • lower (int) – the lower coordinate along the track direction.

  • upper (int) – the upper coordinate along the track direction.

property track_id: TrackID[source]

The TrackID of this WireArray.

Type:

TrackID

property layer_id: int[source]
property lower: int[source]
property upper: int[source]
property middle: int[source]
property bound_box: pybag.core.BBox[source]

the bounding box of this WireArray.

Type:

BBox

classmethod list_to_warr(warr_list: Sequence[WireArray]) WireArray[source]

Convert a list of WireArrays to a single WireArray.

this method assumes all WireArrays have the same layer, width, and lower/upper coordinates. Overlapping WireArrays will be compacted.

classmethod single_warr_iter(warr: Union[WireArray, Sequence[WireArray]]) Iterable[WireArray][source]

Iterate through single wires in the given WireArray or WireArray list.

classmethod wire_grp_iter(warr: Union[WireArray, Sequence[WireArray]]) Iterable[WireArray][source]

Iterate through WireArrays in the given WireArray or WireArray list.

__getitem__(idx: int) WireArray[source]
__repr__() str[source]

Return repr(self).

to_warr_list() List[WireArray][source]

Convert this WireArray into a list of single wires.

warr_iter() Iterable[WireArray][source]

Iterates through single wires in this WireArray.

wire_iter(tr_colors: pybag.core.TrackColoring) Iterable[Tuple[str, str, pybag.core.BBox]][source]
transform(xform: pybag.core.Transform) WireArray[source]

Transform this WireArray.

Parameters:

xform (Transform) – the transformation object.

Returns:

warr – a reference to this object.

Return type:

WireArray

get_transform(xform: pybag.core.Transform) WireArray[source]

Return a new transformed WireArray.

Parameters:

xform (Transform) – the transformation object.

Returns:

warr – the new WireArray object.

Return type:

WireArray

class bag.layout.routing.base.Port(term_name: str, pin_dict: Dict[Union[int, str], Union[List[WireArray], List[pybag.core.BBox]]], label: str, hidden: bool)[source]

A layout port.

a port is a group of pins that represent the same net. The pins can be on different layers.

Parameters:
  • term_name (str) – the terminal name of the port.

  • pin_dict (Dict[Union[int, str], Union[List[WireArray], List[BBox]]]) – a dictionary from layer ID to pin geometries on that layer.

  • label (str) – the label of this port.

property net_name: str[source]

The net name of this port.

Type:

str

property label: str[source]

The label of this port.

Type:

str

property hidden: bool[source]

True if this is a hidden port.

Type:

bool

default_layer[source]
get_single_layer() Union[int, str][source]

Returns the layer of this port if it only has a single layer.

_get_layer(layer: Union[int, str]) Union[int, str][source]

Get the layer ID or name.

items() Iterable[Union[int, str], Union[List[WireArray], List[pybag.core.BBox]]][source]
get_pins(layer: Union[int, str] = -1000) Union[List[WireArray], List[pybag.core.BBox]][source]

Returns the pin geometries on the given layer.

Parameters:

layer (Union[int, str]) – the layer ID. If equal to Port.default_layer, check if this port is on a single layer, then return the result.

Returns:

track_bus_list – pins on the given layer representing as WireArrays.

Return type:

Union[List[WireArray], List[BBox]]

get_bounding_box(layer: Union[int, str] = -1000) pybag.core.BBox[source]

Calculate the overall bounding box of this port on the given layer.

Parameters:

layer (Union[int, str]) – the layer ID. If Negative, check if this port is on a single layer, then return the result.

Returns:

bbox – the bounding box.

Return type:

BBox

get_transform(xform: pybag.core.Transform) Port[source]

Return a new transformed Port.

Parameters:

xform (Transform) – the transform object.

to_primitive(tr_colors: pybag.core.TrackColoring, check_fun: Callable[[int], bool]) Port[source]
class bag.layout.routing.base.TrackManager(grid: bag.layout.routing.grid.RoutingGrid, tr_widths: WDictType, tr_spaces: SpDictType, **kwargs: Any)[source]

A class that makes it easy to compute track locations.

This class provides many helper methods for computing track locations and spacing when each track could have variable width. All methods in this class accepts a “track_type”, which is either a string in the track dictionary or an integer representing the track width.

Parameters:
  • grid (RoutingGrid) – the RoutingGrid object.

  • tr_widths (WDictType) – dictionary from wire types to its width on each layer.

  • tr_spaces (SpDictType) – dictionary from wire types to its spaces on each layer.

  • **kwargs (Any) – additional options.

property grid: bag.layout.routing.grid.RoutingGrid[source]
property half_space: bool[source]
property tr_widths: bag.util.immutable.ImmutableSortedDict[str, bag.util.immutable.ImmutableSortedDict[int, int]][source]
property tr_spaces: bag.util.immutable.ImmutableSortedDict[Tuple[str, str], bag.util.immutable.ImmutableSortedDict[int, bag.typing.TrackType]][source]
__hash__() int[source]

Return hash(self).

__eq__(other: Any) bool[source]

Return self==value.

classmethod _get_space_from_tuple(layer_id: int, ntup: Tuple[str, str], sp_dict: Optional[SpDictType]) Optional[bag.typing.TrackType][source]
get_width(layer_id: int, track_type: Union[str, int]) int[source]

Returns the track width.

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

  • track_type (Union[str, int]) – the track type.

get_sep(layer_id: int, type_tuple: Tuple[Union[str, int], Union[str, int]], **kwargs: Any) bag.util.math.HalfInt[source]

Returns the track separation.

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

  • type_tuple (Tuple[Union[str, int], Union[str, int]],) – Tuple of the two types of wire. If a type is an integer instead of a string, we use that as the track width.

  • **kwargs (Any) – optional parameters.

Returns:

tr_sp – the track spacing

Return type:

TrackType

get_next_track(layer_id: int, cur_idx: bag.typing.TrackType, cur_type: Union[str, int], next_type: Union[str, int], up: Union[bool, int] = True, **kwargs: Any) bag.util.math.HalfInt[source]

Compute the track location of a wire next to a given one.

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

  • cur_idx (TrackType) – the current wire track index.

  • cur_type (Union[str, int]) – the current wire type.

  • next_type (Union[str, int]) – the next wire type.

  • up (Union[bool, int]) – True to return the next track index that is larger than cur_idx. Can also be integer to count number of tracks.

  • **kwargs (Any) – optional parameters.

Returns:

next_int – the next track index.

Return type:

HalfInt

get_num_wires_between(layer_id: int, bot_wire: str, bot_idx: bag.util.math.HalfInt, top_wire: str, top_idx: bag.util.math.HalfInt, fill_wire: str) int[source]
place_wires(layer_id: int, type_list: Sequence[Union[str, int]], align_track: Optional[bag.util.math.HalfInt] = None, align_idx: int = 0, center_coord: Optional[int] = None, **kwargs: Any) Tuple[bag.util.math.HalfInt, List[bag.util.math.HalfInt]][source]

Place the given wires next to each other.

Parameters:
  • layer_id (int) – the layer of the tracks.

  • type_list (Sequence[Union[str, int]]) – list of wire types.

  • align_track (Optional[HalfInt]) – If not None, will make sure the the track at location align_idx has this value.

  • align_idx (Optional[int]) – the align wire index.

  • center_coord (Optional[int]) – If not None, will try to center the wires around this coordinate. align_track takes precedence over center_coord.

  • **kwargs (Any) – optional parameters for get_num_space_tracks() method of RoutingGrid.

Returns:

  • num_tracks (HalfInt) – number of tracks used.

  • locations (List[HalfInt]) – the center track index of each wire.

classmethod _get_align_delta(tot_ntr: bag.typing.TrackType, num_used: bag.typing.TrackType, alignment: int) bag.util.math.HalfInt[source]
align_wires(layer_id: int, type_list: Sequence[Union[str, int]], tot_ntr: bag.typing.TrackType, alignment: int = 0, start_idx: bag.typing.TrackType = 0, **kwargs: Any) List[bag.util.math.HalfInt][source]

Place the given wires in the given space with the specified alignment.

Parameters:
  • layer_id (int) – the layer of the tracks.

  • type_list (Sequence[Union[str, int]]) – list of wire types.

  • tot_ntr (TrackType) – total available space in number of tracks.

  • alignment (int) – If alignment == -1, will “left adjust” the wires (left is the lower index direction). If alignment == 0, will center the wires in the middle. If alignment == 1, will “right adjust” the wires.

  • start_idx (TrackType) – the starting track index.

  • **kwargs (Any) – optional parameters for place_wires().

Returns:

locations – the center track index of each wire.

Return type:

List[HalfInt]

get_next_track_obj(warr_tid_obj: Union[TrackID, WireArray], cur_type: Union[str, int], next_type: Union[str, int], count_rel_tracks: int = 1, **kwargs) TrackID[source]

Computes next TrackID relative the WireArray or TrackID object, given wire types

Parameters:
  • warr_tid_obj (Union[TrackID, WireArray]) – the wire array or track id object used as the reference

  • cur_type (Union[str, int]) – the wire type of current reference warr/tid

  • next_type (Union[str, int]) – the wire type of the returned tid

  • count_rel_tracks (int) – the number of spacings to skip +1 means the immediate next track id -1 means immediate previous track id, +2 means the one after the next track id, etc. if |count_rel_tracks| > 1, the skipped distance is space(cur_type, next_type) + (|count_rel_tracks| - 1) * space(next_type, next_type)

Returns:

track_id – the TrackID object of the next track id

Return type:

TrackID

get_shield_tracks(layer_id: int, tidx_lo: bag.util.math.HalfInt, tidx_hi: bag.util.math.HalfInt, wtype_lo: Union[str, int], wtype_hi: Union[str, int]) List[TrackID][source]

Fill the given space with shielding tracks

Try to fill with the widest metal allowed in the PDK Respect DRC spacing rules relative to lower and higher wires Currently this method just returns a bunch of width 1 wires.

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

  • tidx_lo (HalfInt) – lower bound track index

  • tidx_hi (HalfInt) – upper bound track index

  • wtype_lo (Union[str, int]) – type of lower bound wire

  • wtype_hi (Union[str, int]) – type of upper bound wire

Returns:

idx_list – list of TrackIDs

Return type:

List[TrackID]

spread_wires(layer_id: int, type_list: Sequence[Union[str, int]], lower: bag.util.math.HalfInt, upper: bag.util.math.HalfInt, sp_type: Tuple[str, str], alignment: int = 0, max_iter: int = 1000) List[bag.util.math.HalfInt][source]

Spread out the given wires in the given space.

This method tries to spread out wires by increasing the space around the given wire/combination of wires.

Parameters:
  • layer_id (int) – the layer of the tracks.

  • type_list (Sequence[Union[str, int]]) – list of wire types.

  • lower (HalfInt) – the lower bound track index, inclusive.

  • upper (HalfInt) – the upper bound track index, inclusive.

  • sp_type (Tuple[str, str]) – The space to increase.

  • alignment (int) – If alignment == -1, will “left adjust” the wires (left is the lower index direction). If alignment == 0, will center the wires in the middle. If alignment == 1, will “right adjust” the wires.

  • max_iter (int) – maximum number of iterations.

Returns:

locations – the center track index of each wire.

Return type:

List[HalfInt]