diff --git a/b_asic/port.py b/b_asic/port.py index f2a2532874b0fed1511c10633c36376805396240..0ea0b28faa24a78918bd7cfc019756e33f94c669 100644 --- a/b_asic/port.py +++ b/b_asic/port.py @@ -174,16 +174,14 @@ class InputPort(AbstractPort): def add_signal(self, signal: Signal) -> None: if self._source_signal is not None: raise ValueError("Cannot add to already connected input port.") - assert ( - signal is not self._source_signal - ), "Attempted to add already connected signal." + if signal is self._source_signal: + raise ValueError("Cannot add same signal twice") self._source_signal = signal signal.set_destination(self) def remove_signal(self, signal: Signal) -> None: - assert ( - signal is self._source_signal - ), "Attempted to remove signal that is not connected." + if signal is not self._source_signal: + raise ValueError("Cannot remove signal that is not connected") self._source_signal = None signal.remove_destination() @@ -242,16 +240,14 @@ class OutputPort(AbstractPort, SignalSourceProvider): return self._destination_signals def add_signal(self, signal: Signal) -> None: - assert ( - signal not in self._destination_signals - ), "Attempted to add already connected signal." + if signal in self._destination_signals: + raise ValueError("Cannot add same signal twice") self._destination_signals.append(signal) signal.set_source(self) def remove_signal(self, signal: Signal) -> None: - assert ( - signal in self._destination_signals - ), "Attempted to remove signal that is not connected." + if signal not in self._destination_signals: + raise ValueError("Cannot remove signal that is not connected") self._destination_signals.remove(signal) signal.remove_source() diff --git a/b_asic/schedule.py b/b_asic/schedule.py index 61c8cde4e6fbc5b05e5cb7d846215f10755492f7..acddc88d7530b9edf7cc547234800f6d89480b58 100644 --- a/b_asic/schedule.py +++ b/b_asic/schedule.py @@ -74,11 +74,11 @@ class Schedule: self._schedule_time = schedule_time def start_time_of_operation(self, op_id: GraphID) -> int: - """Get the start time of the operation with the specified by the op_id. """ - assert ( - op_id in self._start_times - ), "No operation with the specified op_id in this schedule." + Get the start time of the operation with the specified by the op_id. + """ + if op_id not in self._start_times: + raise ValueError(f"No operation with op_id {op_id} in schedule") return self._start_times[op_id] def get_max_end_time(self) -> int: @@ -93,9 +93,8 @@ class Schedule: return max_end_time def forward_slack(self, op_id: GraphID) -> int: - assert ( - op_id in self._start_times - ), "No operation with the specified op_id in this schedule." + if op_id not in self._start_times: + raise ValueError(f"No operation with op_id {op_id} in schedule") slack = sys.maxsize output_slacks = self._forward_slacks(op_id) # Make more pythonic @@ -125,9 +124,8 @@ class Schedule: return ret def backward_slack(self, op_id: GraphID) -> int: - assert ( - op_id in self._start_times - ), "No operation with the specified op_id in this schedule." + if op_id not in self._start_times: + raise ValueError(f"No operation with op_id {op_id} in schedule") slack = sys.maxsize input_slacks = self._backward_slacks(op_id) # Make more pythonic @@ -157,16 +155,16 @@ class Schedule: return ret def slacks(self, op_id: GraphID) -> Tuple[int, int]: - assert ( - op_id in self._start_times - ), "No operation with the specified op_id in this schedule." + if op_id not in self._start_times: + raise ValueError(f"No operation with op_id {op_id} in schedule") return self.backward_slack(op_id), self.forward_slack(op_id) def print_slacks(self) -> None: raise NotImplementedError def set_schedule_time(self, time: int) -> "Schedule": - assert self.get_max_end_time() <= time, "New schedule time to short." + if time < self.get_max_end_time(): + raise ValueError( "New schedule time ({time})to short, minimum: ({self.get_max_end_time()}).") self._schedule_time = time return self @@ -260,9 +258,8 @@ class Schedule: return self def move_operation(self, op_id: GraphID, time: int) -> "Schedule": - assert ( - op_id in self._start_times - ), "No operation with the specified op_id in this schedule." + if op_id not in self._start_times: + raise ValueError(f"No operation with op_id {op_id} in schedule") (backward_slack, forward_slack) = self.slacks(op_id) if not -backward_slack <= time <= forward_slack: diff --git a/b_asic/scheduler_gui/graphics_axes_item.py b/b_asic/scheduler_gui/graphics_axes_item.py index e141993e9a9abd49ab8f11da7c64bb358f134f4f..25297e7e4b3a16b3e52c4d3a14909353f9f3e192 100644 --- a/b_asic/scheduler_gui/graphics_axes_item.py +++ b/b_asic/scheduler_gui/graphics_axes_item.py @@ -62,12 +62,10 @@ class GraphicsAxesItem(QGraphicsItemGroup): *parent* is passed to QGraphicsItemGroup's constructor. """ super().__init__(parent=parent) - assert ( - width >= 0 - ), f"'width' greater or equal to 0 expected, got: {width}." - assert ( - height >= 0 - ), f"'height' greater or equal to 0 expected, got: {height}." + if width < 0: + raise ValueError(f"'width' greater or equal to 0 expected, got: {width}.") + if height < 0: + raise ValueError(f"'height' greater or equal to 0 expected, got: {height}.") self._width = width self._height = height @@ -153,13 +151,15 @@ class GraphicsAxesItem(QGraphicsItemGroup): def set_height(self, height: int) -> "GraphicsAxesItem": # TODO: implement, docstring + if height < 0: + raise ValueError(f"'height' greater or equal to 0 expected, got: {height}.") raise NotImplementedError def set_width(self, width: int) -> "GraphicsAxesItem": # TODO: docstring - assert ( - width >= 0 - ), f"'width' greater or equal to 0 expected, got: {width}." + if width < 0: + raise ValueError(f"'width' greater or equal to 0 expected, got: {width}.") + delta_width = width - self._width if delta_width > 0: diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py index ab8d096a55d3744fedc445d2c21b6649bc6ebc62..41d42b13751d2e0c65f917dd24fc0b9c15ee4fdf 100644 --- a/b_asic/signal_flow_graph.py +++ b/b_asic/signal_flow_graph.py @@ -150,9 +150,8 @@ class SFG(AbstractOperation): # Setup input signals. if input_signals is not None: for input_index, signal in enumerate(input_signals): - assert ( - signal not in self._original_components_to_new - ), "Duplicate input signals supplied to SFG constructor." + if signal in self._original_components_to_new: + raise ValueError(f"Duplicate input signal {signal!r} in SFG") new_input_op = self._add_component_unconnected_copy(Input()) new_signal = self._add_component_unconnected_copy(signal) new_signal.set_source(new_input_op.output(0)) @@ -162,9 +161,8 @@ class SFG(AbstractOperation): # Setup input operations, starting from indices after input signals. if inputs is not None: for input_index, input_op in enumerate(inputs, input_signal_count): - assert ( - input_op not in self._original_components_to_new - ), "Duplicate input operations supplied to SFG constructor." + if input_op in self._original_components_to_new: + raise ValueError(f"Duplicate input operation {input_op!r} in SFG") new_input_op = self._add_component_unconnected_copy(input_op) for signal in input_op.output(0).signals: assert signal not in self._original_components_to_new, ( @@ -200,9 +198,9 @@ class SFG(AbstractOperation): for output_index, output_op in enumerate( outputs, output_signal_count ): - assert ( - output_op not in self._original_components_to_new - ), "Duplicate output operations supplied to SFG constructor." + if output_op in self._original_components_to_new: + raise ValueError(f"Duplicate output operation {output_op!r} in SFG") + new_output_op = self._add_component_unconnected_copy(output_op) for signal in output_op.input(0).signals: if signal in self._original_components_to_new: