Skip to content
Snippets Groups Projects

Resolve "Operation Replacement in a SFG"

Closed Kevin Scott requested to merge 17-operation-replacement-in-a-sfg into develop
5 unresolved threads

Added method with tests for replacing multiple operations in a sfg with another operation with the same amount of input / output ports. Closes #17

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
  • Angus Lothian
  • Angus Lothian
  • 405 405 # The old SFG will be deleted by Python GC
    406 406 return self()
    407 407
    408 def replace_operations(self, operation_ids: Sequence[GraphID], operation: Operation):
    • What this method does is replace a set of operations with an entered operation, which is good and probably what Oscar wants to do most of the time. However in the Requirements Specification the requirement is that a set of operations should be able to be replace with another set of operations.

      Not sure if this is completely necessary though, but otherwise we have to change the requirements specification. What do you think @ivaha717 ?

    • Please register or sign in to reply
  • 412 Arguments:
    413 operation_ids: The id's of the operations we are replacing
    414 operation: The operation used for replacement.
    415 """
    416
    417 inputs = []
    418 outputs = []
    419
    420 for _operation in self.operations:
    421 if _operation.graph_id not in operation_ids:
    422 continue
    423
    424 # Retrive input operations
    425 for _signal in _operation.input_signals:
    426 if _signal.source.operation.graph_id not in operation_ids:
    427 inputs.append(_signal.source.operation)
  • 257
    258 class TestReplaceOperations:
    259 def test_replace_mul_add_with_mad(self):
    260 in1 = Input()
    261 in2 = Input()
    262 in3 = Input()
    263 mul1 = in1 * in2
    264 add1 = mul1 + in3
    265 out1 = Output(add1)
    266 sfg = SFG(inputs=[in1, in2, in3], outputs=[out1])
    267
    268 mad1 = MAD()
    269 _sfg = sfg.replace_operations(['add1', 'mul1'], mad1)
    270
    271 assert 'mad1' in _sfg._components_by_id.keys()
    272 assert {add1, mul1} not in _sfg.operations
  • 271 assert 'mad1' in _sfg._components_by_id.keys()
    272 assert {add1, mul1} not in _sfg.operations
    273
    274 def test_replace_neg_add_with_sub(self):
    275 in1 = Input()
    276 in2 = Input()
    277 neg1 = ConstantMultiplication(-1, in1, 'neg1')
    278 add1 = neg1 + in2
    279 out1 = Output(add1)
    280 sfg = SFG(inputs=[in1, in2], outputs=[out1])
    281
    282 sub1 = Subtraction()
    283 _sfg = sfg.replace_operations(['add1', 'neg1'], sub1)
    284
    285 assert 'sub1' in _sfg._components_by_id.keys()
    286 assert {add1, neg1} not in _sfg.operations
  • Kevin Scott added 1 commit

    added 1 commit

    • 81631595 - changed replace_operations method

    Compare with previous version

  • Kevin Scott added 1 commit

    added 1 commit

    • 311f41f5 - Fixed sfg being immutable when replacing operations

    Compare with previous version

  • Kevin Scott added 1 commit

    added 1 commit

    • 5843bf7f - Changed replace operations method

    Compare with previous version

  • Kevin Scott added 1 commit

    added 1 commit

    Compare with previous version

  • Closed because the project has ended.

  • closed

  • Please register or sign in to reply
    Loading