code: def serialize(self):
          
          # fill sequences
          for keys, groups in groupby(self.ports, lambda x: x.io_type):
              for seq, port in enumerate(groups):
                  port.sequence = seq
          return super(AlgorithmDef, self).serialize()
docs: Serialize the algorithm definition