diff --git a/b_asic/process.py b/b_asic/process.py index df855bf0a10927f699aaff5dde2ddbac6d6b153a..04b1e48196114d3092972c9cef84d3a849241dcc 100644 --- a/b_asic/process.py +++ b/b_asic/process.py @@ -1,6 +1,4 @@ -""" -B-ASIC classes representing resource usage. -""" +"""B-ASIC classes representing resource usage.""" from typing import Dict, Optional, Tuple @@ -10,9 +8,10 @@ from b_asic.port import InputPort, OutputPort class Process: """ - Object for use in resource allocation. Has a start time and an execution - time. Subclasses will in many cases contain additional information for - resource assignment. + Object for use in resource allocation. + + Has a start time and an execution time. Subclasses will in many cases + contain additional information for resource assignment. Parameters ========== @@ -59,9 +58,7 @@ class Process: return self._name def __repr__(self) -> str: - return ( - f"Process({self.start_time}, {self.execution_time}, {self.name})" - ) + return f"Process({self.start_time}, {self.execution_time}, {self.name})" # Static counter for default names _name_cnt = 0 @@ -90,8 +87,7 @@ class OperatorProcess(Process): execution_time = operation.execution_time if execution_time is None: raise ValueError( - "Operation {operation!r} does not have an execution time" - " specified!" + "Operation {operation!r} does not have an execution time specified!" ) super().__init__( start_time, @@ -157,8 +153,9 @@ class MemoryVariable(Process): class PlainMemoryVariable(Process): """ - Object that corresponds to a memory variable which only use numbers for - ports. This can be useful when only a plain memory variable is wanted with + Object that corresponds to a memory variable which only use numbers for ports. + + This can be useful when only a plain memory variable is wanted with no connection to a schedule. Parameters diff --git a/b_asic/sfg_generators.py b/b_asic/sfg_generators.py index 9b3239ecfe37b8bab71a76f756118ac4773d86f1..e9a864705d58164090eda94966f9343f07ab07bc 100644 --- a/b_asic/sfg_generators.py +++ b/b_asic/sfg_generators.py @@ -29,8 +29,8 @@ def wdf_allpass( execution_time: Optional[int] = None, ) -> SFG: """ - Generate a signal flow graph of a WDF allpass section based on symmetric two-port - adaptors. + Generate a signal flow graph of a WDF allpass section based on symmetric two-port\ + adaptors. Parameters ---------- @@ -126,8 +126,9 @@ def direct_form_fir( add_properties: Optional[Union[Dict[str, int], Dict[str, Dict[str, int]]]] = None, ): r""" - Generate a signal flow graph of a direct form FIR filter. The *coefficients* parameter is a - sequence of impulse response values:: + Generate a signal flow graph of a direct form FIR filter. + + The *coefficients* parameter is a sequence of impulse response values:: coefficients = [h0, h1, h2, ..., hN] @@ -206,8 +207,9 @@ def transposed_direct_form_fir( add_properties: Optional[Union[Dict[str, int], Dict[str, Dict[str, int]]]] = None, ): r""" - Generate a signal flow graph of a transposed direct form FIR filter. The *coefficients* parameter is a - sequence of impulse response values:: + Generate a signal flow graph of a transposed direct form FIR filter. + + The *coefficients* parameter is a sequence of impulse response values:: coefficients = [h0, h1, h2, ..., hN] diff --git a/b_asic/signal.py b/b_asic/signal.py index 8b094a94f9051dff9737ed82392acddd2ed2379c..b7128f4500ee7c0b039e8adb67d1a66f87b1c668 100644 --- a/b_asic/signal.py +++ b/b_asic/signal.py @@ -64,23 +64,26 @@ class Signal(AbstractGraphComponent): @property def neighbors(self) -> Iterable[GraphComponent]: + """Return a list of the (up to) two operations connected to this signal.""" return [p.operation for p in [self.source, self.destination] if p is not None] @property def source(self) -> Optional["OutputPort"]: - """The source OutputPort of the signal.""" + """Return the source OutputPort of the signal.""" return self._source @property def destination(self) -> Optional["InputPort"]: - """The destination InputPort of the signal.""" + """Return the destination InputPort of the signal.""" return self._destination def set_source(self, source: Union["OutputPort", "Signal", "Operation"]) -> None: """ - Disconnect the previous source OutputPort of the signal and - connect to the entered source OutputPort. Also connect the entered - source port to the signal if it has not already been connected. + Connect to the entered source OutputPort. + + Also, disconnect the previous source OutputPort of the signal and + connect the entered source port to the signal if it has not + already been connected. Parameters ========== @@ -111,9 +114,11 @@ class Signal(AbstractGraphComponent): self, destination: Union["InputPort", "Signal", "Operation"] ) -> None: """ - Disconnect the previous destination InputPort of the signal and - connect to the entered destination InputPort. Also connect the entered - destination port to the signal if it has not already been connected. + Connect to the entered *destination* InputPort. + + Also, disconnect the previous destination InputPort of the signal and + connect the entered destination port to the signal if it has not already + been connected. Parameters ========== @@ -143,8 +148,10 @@ class Signal(AbstractGraphComponent): def remove_source(self) -> None: """ - Disconnect the source OutputPort of the signal. If the source port - still is connected to this signal then also disconnect the source port. + Disconnect the source OutputPort of the signal. + + If the source port still is connected to this signal then also disconnect + the source port. """ source = self._source if source is not None: @@ -162,8 +169,7 @@ class Signal(AbstractGraphComponent): def dangling(self) -> bool: """ - Returns True if the signal is missing either a source or a destination, - else False. + Return True if the signal is missing either a source or a destination. """ return self._source is None or self._destination is None diff --git a/b_asic/simulation.py b/b_asic/simulation.py index ea4efb2b0ac9c7052a0567c5167178e62c5eebbd..20716a42045e234a80e6d4b2e7d63acd43c0482e 100644 --- a/b_asic/simulation.py +++ b/b_asic/simulation.py @@ -71,16 +71,16 @@ class Simulation: def set_input(self, index: int, input_provider: InputProvider) -> None: """ - Set the input used to get values for the specific input at the - given index to the internal SFG. + Set the input used to get values for the specific input at the given index of\ + the internal SFG. Parameters ---------- index : int The input index. input_provider : list, callable, or number - Can be an array of values, a callable taking a time index and returning the value, or a - number (constant input). + Can be an array of values, a callable taking a time index and returning + the value, or a number (constant input). """ if index < 0 or index >= len(self._input_functions): raise IndexError( @@ -120,8 +120,7 @@ class Simulation: bits_override: Optional[int] = None, truncate: bool = True, ) -> Sequence[Num]: - """ - Run one iteration of the simulation and return the resulting output values. + """Run one iteration of the simulation and return the resulting output values. """ return self.run_for(1, save_results, bits_override, truncate) @@ -133,8 +132,8 @@ class Simulation: truncate: bool = True, ) -> Sequence[Num]: """ - Run the simulation until its iteration is greater than or equal to the given - iteration and return the output values of the last iteration. + Run the simulation until its iteration is greater than or equal to the given\ + iteration and return the output values of the last iteration. """ result: Sequence[Num] = [] while self._iteration < iteration: @@ -165,8 +164,8 @@ class Simulation: truncate: bool = True, ) -> Sequence[Num]: """ - Run a given number of iterations of the simulation and return the output - values of the last iteration. + Run a given number of iterations of the simulation and return the output\ + values of the last iteration. """ return self.run_until( self._iteration + iterations, save_results, bits_override, truncate @@ -179,8 +178,8 @@ class Simulation: truncate: bool = True, ) -> Sequence[Num]: """ - Run the simulation until the end of its input arrays and return the output - values of the last iteration. + Run the simulation until the end of its input arrays and return the output\ + values of the last iteration. """ if self._input_length is None: raise IndexError("Tried to run unlimited simulation") @@ -194,11 +193,12 @@ class Simulation: @property def results(self) -> ResultArrayMap: """ - Get a mapping from result keys to numpy arrays containing all results, including - intermediate values, calculated for each iteration up until now that was run - with save_results enabled. - The mapping is indexed using the key() method of Operation with the appropriate - output index. + Get a mapping from result keys to numpy arrays containing all results. + + This includes intermediate values, calculated for each iteration up until now + that was run with *save_results* enabled. + The mapping is indexed using the ``key()`` method of Operation with the + appropriate output index. Example result after 3 iterations:: {"c1": [3, 6, 7], "c2": [4, 5, 5], "bfly1.0": [7, 0, 0], "bfly1.1": [-1, 0, 2], "0": [7, -2, -1]}