Skip to content

Length functions

length_functions

Length function for calculating length of manhattan routes.

LengthFunction

Bases: Protocol

Protocol for a function which calculates the length of a route.

Source code in kfactory/routing/length_functions.py
21
22
23
24
25
@runtime_checkable
class LengthFunction(Protocol):
    """Protocol for a function which calculates the length of a route."""

    def __call__(self, route: ManhattanRoute) -> int | float: ...

get_length_from_area

get_length_from_area(
    layer: LayerInfo | None = None,
) -> LengthFunction

Get length from are in dbu.

Parameters:

Name Type Description Default
layer LayerInfo | None

The layer for which to calculate the area.

None

Returns:

Type Description
LengthFunction

Length in dbu.

Source code in kfactory/routing/length_functions.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def get_length_from_area(layer: kdb.LayerInfo | None = None) -> LengthFunction:
    """Get length from are in dbu.

    Args:
        layer: The layer for which to calculate the area.

    Returns:
        Length in dbu.
    """

    def get_length_(route: ManhattanRoute) -> float:
        if not route.instances:
            return 0
        layer_ = layer or route.start_port.layer_info

        length: float = 0
        width = route.start_port.width

        for inst in route.instances:
            length += _get_area_from_layer(
                inst.cell.kcl.name, inst.cell.cell_index(), layer_, width
            )

        return length

    return get_length_