code: def from_graph(cls, graph, linear_energy_ranges, quadratic_energy_ranges):
          
          get_env().enable_infix_notation = True  # not sure why we need this here
  
          theta = cls.empty(dimod.SPIN)
  
          theta.add_offset(Symbol('offset', REAL))
  
          def Linear(v):
              """Create a Symbol for the linear bias including the energy range
              constraints."""
              bias = Symbol('h_{}'.format(v), REAL)
  
              min_, max_ = linear_energy_ranges[v]
  
              theta.assertions.add(LE(bias, limitReal(max_)))
              theta.assertions.add(GE(bias, limitReal(min_)))
  
              return bias
  
          def Quadratic(u, v):
              """Create a Symbol for the quadratic bias including the energy range
              constraints."""
              bias = Symbol('J_{},{}'.format(u, v), REAL)
  
              if (v, u) in quadratic_energy_ranges:
                  min_, max_ = quadratic_energy_ranges[(v, u)]
              else:
                  min_, max_ = quadratic_energy_ranges[(u, v)]
  
              theta.assertions.add(LE(bias, limitReal(max_)))
              theta.assertions.add(GE(bias, limitReal(min_)))
  
              return bias
  
          for v in graph.nodes:
              theta.add_variable(v, Linear(v))
  
          for u, v in graph.edges:
              theta.add_interaction(u, v, Quadratic(u, v))
  
          return theta
docs: Create Theta from a graph and energy ranges.
  
          Args:
              graph (:obj:`networkx.Graph`):
                  Provides the structure for Theta.
  
              linear_energy_ranges (dict):
                  A dict of the form {v: (min, max), ...} where min and max are the
                  range of values allowed to v.
              quadratic_energy_ranges (dict):
                  A dict of the form {(u, v): (min, max), ...} where min and max
                  are the range of values allowed to (u, v).
  
          Returns:
              :obj:`.Theta`