docstr: perform secure aggregate once
  Args:
      ctx: Context to use
      ranks: ranks to aggregate, if None, use all ranks
docstr_tok: ["perform","secure","aggregate","once","Args",":","ctx",":","Context","to","use","ranks",":","ranks","to","aggregate",",","if","None",",","use","all","ranks"]
code: def secure_aggregate(
      self, ctx: Context, ranks: typing.Optional[int] = None
  ):
      """
      perform secure aggregate once
      Args:
          ctx: Context to use
          ranks: ranks to aggregate, if None, use all ranks
      """
      if ranks is None:
          ranks = self.ranks
      aggregated_weight = 0.0
      has_weight = False
  
      if self._is_mock:
          aggregated = []
          for rank in ranks:
              arrays, weight = ctx.parties[rank].get(
                  self._get_name(self._send_name)
              )
              for i in range(len(arrays)):
                  if len(aggregated) <= i:
                      aggregated.append(arrays[i])
                  else:
                      aggregated[i] += arrays[i]
              if weight is not None:
                  has_weight = True
                  aggregated_weight += weight
          if has_weight:
              aggregated = [x / aggregated_weight for x in aggregated]
      else:
          mix_aggregator = MixAggregate()
          for rank in ranks:
              mix_arrays, weight = ctx.parties[rank].get(
                  self._get_name(self._send_name)
              )
              mix_aggregator.aggregate(mix_arrays)
              if weight is not None:
                  has_weight = True
                  aggregated_weight += weight
          if not has_weight:
              aggregated_weight = None
          aggregated = mix_aggregator.finalize(aggregated_weight)
  
      for rank in ranks:
          ctx.parties[rank].put(
              self._get_name(self._recv_name), aggregated
          )
  
      return aggregated
  
file_path: FATE/python/fate/arch/protocol/secure_aggregation/_secure_aggregation.py
imports: import typing
  import numpy
  from fate.arch import Context
  from fate.arch.protocol.diffie_hellman import DiffieHellman
  from fate_utils.secure_aggregation_helper import MixAggregate, RandomMix
label_desc: Use image node_id 2 for calling the SecureAggregatorServer obj's underlying member method code with example usage: obj.secure_aggregate(ctx, ranks) and returns: aggregated