original_docstring: 
      Computes the engery of an Ising model
  
      Inputs:
          - x : binary n x m matrix of spin states (value +1 or -1)
          - Jnm : magnetic coupling between neighbouring spins (typically +1 or -1)
          - H : magnetic field or potential on the spins
  
      Outputs:
          - energy of the system
      
docstring: Computes the engery of an Ising model
  Inputs:
  x : binary n x m matrix of spin states (value +1 or -1)
  Jnm : magnetic coupling between neighbouring spins (typically +1 or -1)
  H : magnetic field or potential on the spins
  
  energy of the system
docstring_tokens: Computes the engery of an Ising model Inputs : x : binary n x m matrix of spin states ( value + 1 or - 1 ) Jnm : magnetic coupling between neighbouring spins ( typically + 1 or - 1 ) H : magnetic field or potential on the spins energy of the system
code: def ising_energy(x, Jij, H=None):
      """
      Computes the engery of an Ising model
  
      Inputs:
          - x : binary n x m matrix of spin states (value +1 or -1)
          - Jnm : magnetic coupling between neighbouring spins (typically +1 or -1)
          - H : magnetic field or potential on the spins
  
      Outputs:
          - energy of the system
      """
      n, m = x.shape
      energy = 0.0
      for i in range(n):
          # use cyclic boundaries
          i_minus_1 = i - 1 if i > 0 else n - 1
          i_plus_1 = i + 1 if i < n - 1 else 0
          for j in range(m):
              # use cyclic boundaries
              j_minus_1 = j - 1 if j > 0 else m - 1
              j_plus_1 = j + 1 if j < m - 1 else 0
              energy += Jij * x[i, j] * (x[i_minus_1, j] + x[i_plus_1, j] +\
                          x[i, j_minus_1] + x[i, j_plus_1] )
      energy /= 2
      if H is not None:
          energy += np.sum(x * H)
      return - energy
code_tokens: def ising_energy ( x , Jij , H = None ) : n , m = x . shape energy = 0.0 for i in range ( n ) : i_minus_1 = i - 1 if i > 0 else n - 1 i_plus_1 = i + 1 if i < n - 1 else 0 for j in range ( m ) : j_minus_1 = j - 1 if j > 0 else m - 1 j_plus_1 = j + 1 if j < m - 1 else 0 energy += Jij * x [ i , j ] * ( x [ i_minus_1 , j ] + x [ i_plus_1 , j ] + x [ i , j_minus_1 ] + x [ i , j_plus_1 ] ) energy /= 2 if H is not None : energy += np . sum ( x * H ) return - energy
short_docstring: Computes the engery of an Ising model
  Inputs:
   x : binary n x m matrix of spin states (value +1 or -1)
   Jnm : magnetic coupling between neighbouring spins (typically +1 or -1)
   H : magnetic field or potential on the spins
short_docstring_tokens: Computes the engery of an Ising model Inputs : x : binary n x m matrix of spin states ( value + 1 or - 1 ) Jnm : magnetic coupling between neighbouring spins ( typically + 1 or - 1 ) H : magnetic field or potential on the spins
comment: """
      Computes the engery of an Ising model
  
      Inputs:
          - x : binary n x m matrix of spin states (value +1 or -1)
          - Jnm : magnetic coupling between neighbouring spins (typically +1 or -1)
          - H : magnetic field or potential on the spins
  
      Outputs:
          - energy of the system
      """$SEP$# use cyclic boundaries$SEP$# use cyclic boundaries