Skip to content
Snippets Groups Projects

Resolve "Add AbstractPort" and "Change Port ID to Port Index"

Merged Angus Lothian requested to merge 48-add-abstractport into develop
5 unresolved threads
  • Changes the port module by introducing a fully abstract "Port" interface and then an "AbstractPort" abstract class that implements the Port interface, which is in line with the class diagram.
  • Renames many functions such as "connect_port" to "connect" and "connect_signal" to "add_signal" for better useability and to fit with the class diagram.
  • Moves "AbstractGraphComponent" to the graph_component module.
  • Also renames functions such as "connect_source" to "set_source" in signal.
  • Refactors Port ID to Port Index as in #49 (closed)
  • Move AbstractOperation implementation to the operation module.
  • Mode BFS implementation from the utilites module to the operation module to solve cyclic imports.

Closes #48 (closed) Closes #49 (closed)

Edited by Angus Lothian

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
    • Resolved by Jacob Wahlman

      I am just wondering why we have a separate module for AbstractOperation and not AbstractPort, does it have to do with cyclic imports or is there any other reason to not separate AbstractPort like AbstractOperation? Generally I think it looks good, just make sure to run pylint and fix some issues.

  • Angus Lothian added 1 commit

    added 1 commit

    • 10976d00 - Solve pull request comments and change so evaluate function in SFG uses the...

    Compare with previous version

  • Author Contributor

    Requesting re-review after made changes @jacwa448 , @ivaha717

  • Angus Lothian added 1 commit

    added 1 commit

    • 62b19475 - Move abstract operation to operation module and move utilties implementation...

    Compare with previous version

  • Jacob Wahlman resolved all threads

    resolved all threads

  • Jacob Wahlman approved this merge request

    approved this merge request

  • Angus Lothian changed the description

    changed the description

  • 88 91 If no neighbours are found this returns an empty list
    89 92 """
    90 93 raise NotImplementedError
    94
    95
    96 class AbstractOperation(Operation, AbstractGraphComponent):
    97 """Generic abstract operation class which most implementations will derive from.
    98 TODO: More info.
  • 102 _output_ports: List["OutputPort"]
    103 _parameters: Dict[str, Optional[Any]]
    104
    105 def __init__(self, name: Name = ""):
    106 super().__init__(name)
    107 self._input_ports = []
    108 self._output_ports = []
    109 self._parameters = {}
    110
    111 @abstractmethod
    112 def evaluate(self, *inputs) -> Any: # pylint: disable=arguments-differ
    113 """Evaluate the operation and generate a list of output values given a
    114 list of input values."""
    115 raise NotImplementedError
    116
    117 def inputs(self) -> List["InputPort"]:
  • 134
    135 def params(self) -> Dict[str, Optional[Any]]:
    136 return self._parameters.copy()
    137
    138 def param(self, name: str) -> Optional[Any]:
    139 return self._parameters.get(name)
    140
    141 def set_param(self, name: str, value: Any) -> None:
    142 assert name in self._parameters # TODO: Error message.
    143 self._parameters[name] = value
    144
    145 def evaluate_outputs(self, state: SimulationState) -> List[Number]:
    146 # TODO: Check implementation.
    147 input_count: int = self.input_count()
    148 output_count: int = self.output_count()
    149 assert input_count == len(self._input_ports) # TODO: Error message.
  • 135 def params(self) -> Dict[str, Optional[Any]]:
    136 return self._parameters.copy()
    137
    138 def param(self, name: str) -> Optional[Any]:
    139 return self._parameters.get(name)
    140
    141 def set_param(self, name: str, value: Any) -> None:
    142 assert name in self._parameters # TODO: Error message.
    143 self._parameters[name] = value
    144
    145 def evaluate_outputs(self, state: SimulationState) -> List[Number]:
    146 # TODO: Check implementation.
    147 input_count: int = self.input_count()
    148 output_count: int = self.output_count()
    149 assert input_count == len(self._input_ports) # TODO: Error message.
    150 assert output_count == len(self._output_ports) # TODO: Error message.
  • 82 83 assert s_w_source.source.signals == [s_w_source]
    83 84 assert s_w_source.destination is None
    84 85
    86 def test_connect_then_disconnect(inp_port, out_port):
    87 """Can port be connected and then disconnected properly?"""
    88 inp_port.connect(out_port)
    89
  • Ivar Härnqvist approved this merge request

    approved this merge request

  • Ivar Härnqvist mentioned in commit 7c6cbe75

    mentioned in commit 7c6cbe75

  • mentioned in issue #49 (closed)

  • Please register or sign in to reply
    Loading