code: def find_bus_controls(sub_network):
      
  
      network = sub_network.network
  
      find_slack_bus(sub_network)
  
      gens = sub_network.generators()
      buses_i = sub_network.buses_i()
  
      #default bus control is PQ
      network.buses.loc[buses_i, "control"] = "PQ"
  
      #find all buses with one or more gens with PV
      pvs = gens[gens.control == 'PV'].index.to_series()
      if len(pvs) > 0:
          pvs = pvs.groupby(gens.bus).first()
          network.buses.loc[pvs.index, "control"] = "PV"
          network.buses.loc[pvs.index, "generator"] = pvs
  
      network.buses.loc[sub_network.slack_bus, "control"] = "Slack"
      network.buses.loc[sub_network.slack_bus, "generator"] = sub_network.slack_generator
  
      buses_control = network.buses.loc[buses_i, "control"]
      sub_network.pvs = buses_control.index[buses_control == "PV"]
      sub_network.pqs = buses_control.index[buses_control == "PQ"]
  
      sub_network.pvpqs = sub_network.pvs.append(sub_network.pqs)
  
      # order buses
      sub_network.buses_o = sub_network.pvpqs.insert(0, sub_network.slack_bus)
docs: Find slack and all PV and PQ buses for a sub_network.
      This function also fixes sub_network.buses_o, a DataFrame
      ordered by control type.