Week 11 - GSoC 2020

Week 11 was spent mostly on applying suggestions from code review in the Transfer function matrix PR (19761). Prior to week 11, I was mostly involved in implementing a bunch of functionality but couldn’t add a good set of unit tests for that. So, I added tests for construction of Parallel and Series objects with transfer function matrix in the arguments. The str printing of TransferFunctionMatrix, Series, and Parallel objects is really long and often times unreadable, so I would advise the users to use pretty-printing (pprint) to analyse better. I also added pretty-printing tests for Series and Parallel.

Then I modified doit() method in Series class to support MIMO transfer function and added tests related to that. Similar to the rewriter for the SISO transfer function, I got an idea to also introduce a rewriter for transfer function matrix. It works this way:

>>> tf1 = TransferFunction(s, s + 1, s)
>>> tf2 = TransferFunction(p + s, s**2 + s + 1, s)
>>> tfm1 = TransferFunctionMatrix([tf1, -tf2], (2, 1), s)
>>> tfm2 = TransferFunctionMatrix([tf2, -tf1], (2, 1), s)
>>> pprint(tfm1)        # it's better to use pprint than use normal printing.
    s     
  ─────   
  s + 1   
          
  -p - s  
⎢──────────⎥
 2        
s  + s + 1
>>> pprint(tfm2)
  p + s   
⎢──────────⎥
 2        
s  + s + 1
          
   -s     
  ─────   
  s + 1   
>>> pprint(Parallel(tfm1, tfm2))
    s          p + s   
  ─────      ⎢──────────⎥
  s + 1       2        
             s  + s + 1
  -p - s   +           
⎢──────────⎥      -s     
 2             ─────   
s  + s + 1     s + 1   
>>> # Note: The following result will be the same that we get from calling `.doit()`. To expand the internal objects, call `doit()` once again.
>>> pprint(Parallel(tfm1, tfm2).rewrite(TransferFunctionMatrix))    # similarly works for `Series` objects with transfer function matrix in the arguments.
  s       p + s   
⎢───── + ──────────⎥
s + 1    2        
        s  + s + 1
                  
  -p - s      -s  
⎢────────── + ─────⎥
 2           s + 1
s  + s + 1        

In the last few days, I also worked on the negation of Series and Parallel objects and added tests related to that. Overall, I do feel it was a productive week. Looking forward to the next week which would be challenging for sure, because I have to wrap up this PR soon.