code: def _gh(self, x):
          Pgen = x[self._Pg.i1:self._Pg.iN + 1]
          Qgen = x[self._Qg.i1:self._Qg.iN + 1]
          for i, gen in enumerate(self._gn):
              gen.p = Pgen[i] * self._base_mva
              gen.q = Qgen[i] * self._base_mva
          Sbus = self.om.case.getSbus(self._bs)
          Vang = x[self._Va.i1:self._Va.iN + 1]
          Vmag = x[self._Vm.i1:self._Vm.iN + 1]
          V = Vmag * exp(1j * Vang)
          mis = V * conj(self._Ybus * V) - Sbus
          g = r_[mis.real,
                 mis.imag]
          flow_max = array([(l.rate_a / self._base_mva)**2 for l in self._ln])
          for i, v in enumerate(flow_max):
              if v == 0.0:
                  flow_max[i] = Inf
          if self.flow_lim == IFLOW:
              If = self._Yf * V
              It = self._Yt * V
              h = r_[(If * conj(If)) - flow_max,
                     (It * conj(It)) - flow_max]
          else:
              i_fbus = [e.from_bus._i for e in self._ln]
              i_tbus = [e.to_bus._i for e in self._ln]
              Sf = V[i_fbus] * conj(self._Yf * V)
              St = V[i_tbus] * conj(self._Yt * V)
              if self.flow_lim == PFLOW:
                  h = r_[Sf.real()**2 - flow_max,
                         St.real()**2 - flow_max]
              elif self.flow_lim == SFLOW:
                  h = r_[(Sf * conj(Sf)) - flow_max,
                         (St * conj(St)) - flow_max].real
              else:
                  raise ValueError
          return h, g