code: def chain_to_quadratic(chain, target_adjacency, chain_strength):
      
      quadratic = {}  # we will be adding the edges that make the chain here
  
      # do a breadth first search
      seen = set()
      try:
          next_level = {next(iter(chain))}
      except StopIteration:
          raise ValueError("chain must have at least one variable")
      while next_level:
          this_level = next_level
          next_level = set()
          for v in this_level:
              if v not in seen:
                  seen.add(v)
  
                  for u in target_adjacency[v]:
                      if u not in chain:
                          continue
                      next_level.add(u)
                      if u != v and (u, v) not in quadratic:
                          quadratic[(v, u)] = -chain_strength
  
      if len(chain) != len(seen):
          raise ValueError('{} is not a connected chain'.format(chain))
  
      return quadratic
docs: Determine the quadratic biases that induce the given chain.
  
      Args:
          chain (iterable):
              The variables that make up a chain.
  
          target_adjacency (dict/:class:`networkx.Graph`):
              Should be a dict of the form {s: Ns, ...} where s is a variable
              in the target graph and Ns is the set of neighbours of s.
  
          chain_strength (float):
              The magnitude of the quadratic bias that should be used to create chains.
  
      Returns:
          dict[edge, float]: The quadratic biases that induce the given chain.
  
      Raises:
          ValueError: If the variables in chain do not form a connected subgraph of target.
  
      Examples:
          >>> chain = {1, 2}
          >>> target_adjacency = {0: {1, 2}, 1: {0, 2}, 2: {0, 1}}
          >>> dimod.embedding.chain_to_quadratic(chain, target_adjacency, 1)
          {(1, 2): -1}