diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 53a34ad9d7118bf83be479141829fd4c4ac33789..e3a6997ed8c977add7fd8c9332f103ed2e78e00c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,12 +14,12 @@ repos: - id: check-toml - repo: https://github.com/crate-ci/typos - rev: v1.20.7 + rev: v1.20.9 hooks: - id: typos - repo: https://github.com/psf/black - rev: 24.3.0 + rev: 24.4.0 hooks: - id: black @@ -36,7 +36,7 @@ repos: - repo: https://github.com/charliermarsh/ruff-pre-commit # Ruff version. - rev: "v0.3.5" + rev: "v0.4.0" hooks: - id: ruff diff --git a/b_asic/architecture.py b/b_asic/architecture.py index 7e6ad3225cfd99314a959b53077c51cec97359e4..f919482aa3bb856de9a87c9dd5cebc26c7fae2c2 100644 --- a/b_asic/architecture.py +++ b/b_asic/architecture.py @@ -11,6 +11,7 @@ from typing import ( Iterable, Iterator, List, + Literal, Optional, Set, Tuple, @@ -240,7 +241,7 @@ class Resource(HardwareBlock): ax : Axes Matplotlib Axes to plot in. **kwargs - Passed to :meth:`b_asic.resources.ProcessCollection.plot`. + Passed to :meth:`~b_asic.resources.ProcessCollection.plot`. """ if not self.is_assigned: self._collection.plot(ax, **kwargs) @@ -259,7 +260,7 @@ class Resource(HardwareBlock): title : str, optional Figure title. **kwargs - Passed to :meth:`b_asic.resources.ProcessCollection.plot`. + Passed to :meth:`~b_asic.resources.ProcessCollection.plot`. """ fig, ax = plt.subplots() self.plot_content(ax, **kwargs) @@ -412,13 +413,15 @@ class ProcessingElement(Resource): def processes(self) -> List[OperatorProcess]: return [cast(OperatorProcess, p) for p in self._collection] - def assign(self, heuristic: str = "left_edge") -> None: + def assign( + self, heuristic: Literal["left_edge", "graph_color"] = "left_edge" + ) -> None: """ Perform assignment of the processes. Parameters ---------- - heuristic : str, default: 'left_edge' + heuristic : {'left_edge', 'graph_color'}, default: 'left_edge' The assignment algorithm. * 'left_edge': Left-edge algorithm. @@ -463,7 +466,7 @@ class Memory(Resource): def __init__( self, process_collection: ProcessCollection, - memory_type: str = "RAM", + memory_type: Literal["RAM", "register"] = "RAM", entity_name: Optional[str] = None, read_ports: Optional[int] = None, write_ports: Optional[int] = None, @@ -793,7 +796,7 @@ of :class:`~b_asic.architecture.ProcessingElement` Parameters ---------- - resource : :class:`b_asic.architecture.Resource` or str + resource : :class:`~b_asic.architecture.Resource` or str The resource or the resource name to remove. """ if isinstance(resource, str): @@ -830,8 +833,8 @@ of :class:`~b_asic.architecture.ProcessingElement` def move_process( self, proc: Union[str, Process], - re_from: Union[str, Resource], - re_to: Union[str, Resource], + source: Union[str, Resource], + destination: Union[str, Resource], assign: bool = False, ) -> None: """ @@ -842,11 +845,11 @@ of :class:`~b_asic.architecture.ProcessingElement` Parameters ---------- - proc : :class:`b_asic.process.Process` or str + proc : :class:`~b_asic.process.Process` or str The process (or its name) to move. - re_from : :class:`b_asic.architecture.Resource` or str + source : :class:`~b_asic.architecture.Resource` or str The resource (or its entity name) to move the process from. - re_to : :class:`b_asic.architecture.Resource` or str + destination : :class:`~b_asic.architecture.Resource` or str The resource (or its entity name) to move the process to. assign : bool, default=False Whether to perform assignment of the resources after moving. @@ -854,24 +857,24 @@ of :class:`~b_asic.architecture.ProcessingElement` Raises ------ :class:`KeyError` - If *proc* is not present in resource *re_from*. + If *proc* is not present in resource *source*. """ # Extract resources from name - if isinstance(re_from, str): - re_from = self.resource_from_name(re_from) - if isinstance(re_to, str): - re_to = self.resource_from_name(re_to) + if isinstance(source, str): + source = self.resource_from_name(source) + if isinstance(destination, str): + destination = self.resource_from_name(destination) # Extract process from name if isinstance(proc, str): - proc = re_from.collection.from_name(proc) + proc = source.collection.from_name(proc) # Move the process - if proc in re_from: - re_to.add_process(proc, assign=assign) - re_from.remove_process(proc, assign=assign) + if proc in source: + destination.add_process(proc, assign=assign) + source.remove_process(proc, assign=assign) else: - raise KeyError(f"{proc} not in {re_from.entity_name}") + raise KeyError(f"{proc} not in {source.entity_name}") self._build_dicts() def _digraph( diff --git a/b_asic/graph_component.py b/b_asic/graph_component.py index 1b3ac9a709a4875d8d832272abd153a107c39555..238c6ecdf3350bb90aa775c63eaac471eb5f2fb1 100644 --- a/b_asic/graph_component.py +++ b/b_asic/graph_component.py @@ -28,7 +28,7 @@ class GraphComponent(ABC): @classmethod @abstractmethod def type_name(cls) -> TypeName: - """Get the type name of this graph component""" + """Get the type name of this graph component.""" raise NotImplementedError @property diff --git a/b_asic/operation.py b/b_asic/operation.py index 3598eb2d1c544c373dbd414d2fb3d13bc664aa95..5cda2ed7128b1b0278320a4788e020294787ff8a 100644 --- a/b_asic/operation.py +++ b/b_asic/operation.py @@ -840,7 +840,9 @@ class AbstractOperation(Operation, AbstractGraphComponent): bits_override: Optional[int] = None, ) -> Sequence[Num]: """ - Quantize the values to be used as inputs to the bit lengths specified + Quantize the values to be used as inputs. + + The bit lengths are specified by the respective signals connected to each input. """ args = [] diff --git a/b_asic/port.py b/b_asic/port.py index 911634cee32efe41e81fde325edf1d22b84b1de6..25400df20f8626d5042206b25f3ef84e4521763f 100644 --- a/b_asic/port.py +++ b/b_asic/port.py @@ -109,7 +109,7 @@ class Port(ABC): @abstractmethod def clear(self) -> None: - """Removes all connected signals from the Port.""" + """Remove all connected signals from the Port.""" raise NotImplementedError @property @@ -334,19 +334,21 @@ class InputPort(AbstractPort): def __ilshift__(self, src: SignalSourceProvider) -> "InputPort": """ - Overloads the inline left shift operator to make it connect the provided - signal source to this input port. Returns the new signal. + Connect the provided signal source to this input port. + + Returns the new signal. """ self.connect(src) return self def delay(self, number: int) -> "InputPort": """ - Inserts `number` amount of delay elements before the input port. + Insert *number* amount of delay elements before the input port. Returns the input port of the first delay element in the chain. """ from b_asic.special_operations import Delay + if not isinstance(number, int) or number < 0: raise TypeError("Number of delays must be a positive integer") tmp_signal = None diff --git a/b_asic/resources.py b/b_asic/resources.py index bda636125b0e25e1cb4f9ed8c679d1266fed5a29..41dcac6bf30cbbf2fa7e5a6cf7b5773459f79553 100644 --- a/b_asic/resources.py +++ b/b_asic/resources.py @@ -532,11 +532,11 @@ class ProcessCollection: Plot all :class:`~b_asic.process.Process` objects of this :class:`~b_asic.resources.ProcessCollection` in a lifetime diagram. - If the ``ax`` parameter is not specified, a new Matplotlib figure is created. + If the *ax* parameter is not specified, a new Matplotlib figure is created. Raises :class:`KeyError` if any :class:`~b_asic.process.Process` lifetime exceeds this :class:`~b_asic.resources.ProcessCollection` schedule time, - unless ``allow_excessive_lifetimes`` is specified. In that case, + unless *allow_excessive_lifetimes* is True. In that case, :class:`~b_asic.process.Process` objects whose lifetime exceed the schedule time are drawn using the B-ASIC warning color. diff --git a/b_asic/schedule.py b/b_asic/schedule.py index 2e846960e9da4cf7938421f76020ecbc1bc0bb00..9cb4132df54ed032e0288ea094bbac0cc86970b4 100644 --- a/b_asic/schedule.py +++ b/b_asic/schedule.py @@ -1121,7 +1121,7 @@ class Schedule: """Reset all the y-locations in the schedule to None""" self._y_locations = defaultdict(_y_locations_default) - def plot(self, ax: Axes, operation_gap: OPERATION_GAP) -> None: + def plot(self, ax: Axes, operation_gap: float = OPERATION_GAP) -> None: """ Plot the schedule in a :class:`matplotlib.axes.Axes` or subclass. diff --git a/b_asic/scheduler_gui/timeline_item.py b/b_asic/scheduler_gui/timeline_item.py index 048a92a025645a9f34319d71ff0673245df0f092..b9296cf3d16a0c5e8a9a1b847ca3e73a574ce12f 100644 --- a/b_asic/scheduler_gui/timeline_item.py +++ b/b_asic/scheduler_gui/timeline_item.py @@ -22,14 +22,16 @@ class TimelineItem(QGraphicsLineItem): @overload def __init__(self, line: QLineF, parent: Optional[QGraphicsItem] = None) -> None: """ - Constructs a TimelineItem out of 'line'. 'parent' is passed to - QGraphicsLineItem's constructor. + Constructs a TimelineItem out of *line*. + + *parent* is passed to QGraphicsLineItem's constructor. """ @overload def __init__(self, parent: Optional[QGraphicsItem] = None) -> None: - """Constructs a TimelineItem. 'parent' is passed to - QGraphicsLineItem's constructor.""" + """Constructs a TimelineItem. + + *parent* is passed to QGraphicsLineItem's constructor.""" @overload def __init__( @@ -41,8 +43,9 @@ class TimelineItem(QGraphicsLineItem): parent: Optional[QGraphicsItem] = None, ) -> None: """ - Constructs a TimelineItem from (x1, y1) to (x2, y2). 'parent' - is passed to QGraphicsLineItem's constructor. + Constructs a TimelineItem from (x1, y1) to (x2, y2). + + *parent* is passed to QGraphicsLineItem's constructor. """ def __init__(self, *args, **kwargs):