class_docstr: Wrapper class for the basic BlueFog API.
class_docstr_tok: ["Wrapper","class","for","the","basic","BlueFog","API","."]
docstr: A function that sets the virtual machine topology.
  
  Args:
    Topo: A networkx.DiGraph object to decide the machine topology. It shall not be None.
    is_weighted: If set to true, hierarchical_neighbor_allreduce will execute the
      weighted average instead, where the weights are the value used in machine topology
      matrix (including self weight).
  
  Returns:
      A boolean value that whether machine topology is set correctly or not.
  
  Example:
      >>> import bluefog.torch as bf
      >>> from bluefog.common import topology_util
      >>> bf.init()
      >>> bf.set_machine_topology(topology_util.RingGraph(bf.machine_size()))
docstr_tok: ["A","function","that","sets","the","virtual","machine","topology",".","Args",":","Topo",":","A","networkx.DiGraph","object","to","decide","the","machine","topology",".","It","shall","not","be","None",".","is_weighted",":","If","set","to","true",",","hierarchical_neighbor_allreduce","will","execute","the","weighted","average","instead",",","where","the","weights","are","the","value","used","in","machine","topology","matrix","(","including","self","weight",")",".","Returns",":","A","boolean","value","that","whether","machine","topology","is","set","correctly","or","not",".","Example",":",">",">",">","import","bluefog.torch","as","bf",">",">",">","from","bluefog.common","import","topology_util",">",">",">","bf.init","(",")",">",">",">","bf.set_machine_topology","(","topology_util.RingGraph","(","bf.machine_size","(",")",")",")"]
code: def set_machine_topology(
      self,
      topology: Optional[networkx.DiGraph],
      is_weighted: bool = False,
  ) -> bool:
      """A function that sets the virtual machine topology.
  
      Args:
        Topo: A networkx.DiGraph object to decide the machine topology. It shall not be None.
        is_weighted: If set to true, hierarchical_neighbor_allreduce will execute the
          weighted average instead, where the weights are the value used in machine topology
          matrix (including self weight).
  
      Returns:
          A boolean value that whether machine topology is set correctly or not.
  
      Example:
          >>> import bluefog.torch as bf
          >>> from bluefog.common import topology_util
          >>> bf.init()
          >>> bf.set_machine_topology(topology_util.RingGraph(bf.machine_size()))
      """
      if topology is None:
          raise ValueError("Machine topology shall not be None.")
  
      if not isinstance(topology, networkx.DiGraph):
          raise TypeError(
              "Machine topology must be a networkx.DiGraph obejct."
          )
      if topology.number_of_nodes() != self.machine_size():
          raise TypeError(
              "topology must be a networkx.DiGraph obejct with same number of nodes "
              "as bf.machine_size()."
          )
  
      assert (
          self.is_homogeneous()
      ), "Only supports homogeneous environment now"
  
      if topology_util.IsTopologyEquivalent(
          topology, self._machine_topology
      ):
          if self.local_rank() == 0:
              logger.debug(
                  "Machine topology to set is the same as old one. Skip the setting."
              )
          return True
  
      self._machine_topology = topology
      self._is_machine_topo_weighted = is_weighted
      return True
  
imports: from typing import List, Callable, Optional
  import atexit
  import contextlib
  import ctypes
  import logging
  import networkx
  import bluefog.common.util
  import bluefog.common.topology_util
label_desc: Use image node_id 20 for calling the BlueFogBasics obj's underlying member method code with example usage: obj.set_machine_topology(topology, is_weighted) and returns: True, True