Skip to content
Snippets Groups Projects
Commit ddfe0a4a authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Some more doc fixes

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