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

Add documentation

parent 32bd8d93
No related branches found
No related tags found
No related merge requests found
Pipeline #89943 failed
This commit is part of merge request !208. Comments created here will be created in the context of that merge request.
...@@ -35,6 +35,15 @@ class Simulation: ...@@ -35,6 +35,15 @@ class Simulation:
Use FastSimulation (from the C++ extension module) for a more effective Use FastSimulation (from the C++ extension module) for a more effective
simulation when running many iterations. simulation when running many iterations.
Parameters
----------
sfg : SFG
The signal flow graph to simulate.
input_providers : list, optional
Input values, one list item per input. Each list item can be an array of values,
a callable taking a time index and returning the value, or a
number (constant input). If a value is not provided for an input, it will be 0.
""" """
_sfg: SFG _sfg: SFG
...@@ -50,23 +59,28 @@ class Simulation: ...@@ -50,23 +59,28 @@ class Simulation:
input_providers: Optional[Sequence[Optional[InputProvider]]] = None, input_providers: Optional[Sequence[Optional[InputProvider]]] = None,
): ):
"""Construct a Simulation of an SFG.""" """Construct a Simulation of an SFG."""
self._sfg = ( # Copy the SFG to make sure it's not modified from the outside.
sfg() self._sfg = sfg()
) # Copy the SFG to make sure it's not modified from the outside.
self._results = defaultdict(list) self._results = defaultdict(list)
self._delays = {} self._delays = {}
self._iteration = 0 self._iteration = 0
self._input_functions = [ self._input_functions = [lambda _: 0 for _ in range(self._sfg.input_count)]
lambda _: 0 for _ in range(self._sfg.input_count)
]
self._input_length = None self._input_length = None
if input_providers is not None: if input_providers is not None:
self.set_inputs(input_providers) self.set_inputs(input_providers)
def set_input(self, index: int, input_provider: InputProvider) -> None: def set_input(self, index: int, input_provider: InputProvider) -> None:
""" """
Set the input function 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 to the internal SFG. given index to 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).
""" """
if index < 0 or index >= len(self._input_functions): if index < 0 or index >= len(self._input_functions):
raise IndexError( raise IndexError(
...@@ -87,9 +101,7 @@ class Simulation: ...@@ -87,9 +101,7 @@ class Simulation:
) )
self._input_functions[index] = lambda n: input_provider[n] self._input_functions[index] = lambda n: input_provider[n]
def set_inputs( def set_inputs(self, input_providers: Sequence[Optional[InputProvider]]) -> None:
self, input_providers: Sequence[Optional[InputProvider]]
) -> None:
""" """
Set the input functions used to get values for the inputs to the internal SFG. Set the input functions used to get values for the inputs to the internal SFG.
""" """
...@@ -172,9 +184,7 @@ class Simulation: ...@@ -172,9 +184,7 @@ class Simulation:
""" """
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")
return self.run_until( return self.run_until(self._input_length, save_results, bits_override, truncate)
self._input_length, save_results, bits_override, truncate
)
@property @property
def iteration(self) -> int: def iteration(self) -> int:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment